Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/BooleanErcOptions.cs @ 14875

Last change on this file since 14875 was 14875, checked in by pkimmesw, 7 years ago

#2665 BenchmarkSuite, all examples, partially tested, VectorExpressions added

File size: 2.4 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc {
2  using System;
3
4  using HeuristicLab.Common;
5  using HeuristicLab.Core;
6  using HeuristicLab.Data;
7  using HeuristicLab.Parameters;
8  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9  using HeuristicLab.Problems.ProgramSynthesis.Base.Erc.Interfaces;
10
11  [StorableClass]
12  public class BooleanErcOptions : ErcOption, IReadOnlyBooleanErcOptions {
13    private const string AllowTrueParameterName = "Allow true";
14    private const string AllowFalseParameterName = "Allow false";
15
16    public BooleanErcOptions()
17      : this(true, true) {
18      IsEnabled = false;
19    }
20
21    public BooleanErcOptions(bool allowTrue, bool allowFalse) {
22      if (!allowTrue && allowFalse) {
23        throw new InvalidOperationException("true and false values are disabled");
24      }
25
26      IsEnabled = true;
27      Parameters.Add(new FixedValueParameter<BoolValue>(AllowTrueParameterName, new BoolValue(allowTrue)));
28      Parameters.Add(new FixedValueParameter<BoolValue>(AllowFalseParameterName, new BoolValue(allowFalse)));
29    }
30
31    [StorableConstructor]
32    public BooleanErcOptions(bool deserializing) : base(deserializing) { }
33
34    public BooleanErcOptions(BooleanErcOptions origin, Cloner cloner) : base(origin, cloner) {
35      this.AllowFalse = origin.AllowFalse;
36      this.AllowTrue = origin.AllowTrue;
37    }
38
39    public IValueParameter<BoolValue> AllowFalseParameter
40    {
41      get { return (IValueParameter<BoolValue>)Parameters[AllowFalseParameterName]; }
42    }
43
44    public bool AllowFalse
45    {
46      get { return AllowFalseParameter.Value.Value; }
47      set { AllowFalseParameter.Value.Value = value; }
48    }
49
50    public IValueParameter<BoolValue> AllowTrueParameter
51    {
52      get { return (IValueParameter<BoolValue>)Parameters[AllowTrueParameterName]; }
53    }
54
55    public bool AllowTrue
56    {
57      get { return AllowTrueParameter.Value.Value; }
58      set { AllowTrueParameter.Value.Value = value; }
59    }
60
61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new BooleanErcOptions(this, cloner);
63    }
64
65    public bool GetRandom(IRandom random) {
66      if (!this.AllowTrue && !this.AllowFalse) throw new InvalidOperationException();
67      if (!this.AllowFalse) return true;
68      if (!this.AllowTrue) return false;
69
70      return random.NextDouble() >= 0.5;
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.