namespace HeuristicLab.Problems.ProgramSynthesis.Push.Erc { using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.ProgramSynthesis.Push.Erc.Interfaces; [StorableClass] public class BooleanErcOptions : ErcOption, IReadOnlyBooleanErcOptions { private const string AllowTrueParameterName = "Allow true"; private const string AllowFalseParameterName = "Allow false"; public BooleanErcOptions() : this(true, true) { } public BooleanErcOptions(bool allowTrue, bool allowFalse) { Parameters.Add(new FixedValueParameter(AllowTrueParameterName, new BoolValue(allowTrue))); Parameters.Add(new FixedValueParameter(AllowFalseParameterName, new BoolValue(allowFalse))); } [StorableConstructor] public BooleanErcOptions(bool deserializing) : base(deserializing) { } public BooleanErcOptions(BooleanErcOptions origin, Cloner cloner) : base(origin, cloner) { this.AllowFalse = origin.AllowFalse; this.AllowTrue = origin.AllowTrue; } public IValueParameter AllowFalseParameter { get { return (IValueParameter)Parameters[AllowFalseParameterName]; } } public bool AllowFalse { get { return AllowFalseParameter.Value.Value; } set { AllowFalseParameter.Value.Value = value; } } public IValueParameter AllowTrueParameter { get { return (IValueParameter)Parameters[AllowTrueParameterName]; } } public bool AllowTrue { get { return AllowTrueParameter.Value.Value; } set { AllowTrueParameter.Value.Value = value; } } public override IDeepCloneable Clone(Cloner cloner) { return new BooleanErcOptions(this, cloner); } public bool GetRandom(IRandom random) { if (!this.AllowTrue && !this.AllowFalse) throw new InvalidOperationException(); if (!this.AllowFalse) return true; if (!this.AllowTrue) return false; return random.NextDouble() >= 0.5; } } }