Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Erc/BooleanErcOptions.cs @ 14834

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

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File size: 2.2 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Push.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.Push.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() : this(true, true) { }
17
18    public BooleanErcOptions(bool allowTrue, bool allowFalse) {
19      Parameters.Add(new FixedValueParameter<BoolValue>(AllowTrueParameterName, new BoolValue(allowTrue)));
20      Parameters.Add(new FixedValueParameter<BoolValue>(AllowFalseParameterName, new BoolValue(allowFalse)));
21    }
22
23    [StorableConstructor]
24    public BooleanErcOptions(bool deserializing) : base(deserializing) { }
25
26    public BooleanErcOptions(BooleanErcOptions origin, Cloner cloner) : base(origin, cloner) {
27      this.AllowFalse = origin.AllowFalse;
28      this.AllowTrue = origin.AllowTrue;
29    }
30
31    public IValueParameter<BoolValue> AllowFalseParameter
32    {
33      get { return (IValueParameter<BoolValue>)Parameters[AllowFalseParameterName]; }
34    }
35
36    public bool AllowFalse
37    {
38      get { return AllowFalseParameter.Value.Value; }
39      set { AllowFalseParameter.Value.Value = value; }
40    }
41
42    public IValueParameter<BoolValue> AllowTrueParameter
43    {
44      get { return (IValueParameter<BoolValue>)Parameters[AllowTrueParameterName]; }
45    }
46
47    public bool AllowTrue
48    {
49      get { return AllowTrueParameter.Value.Value; }
50      set { AllowTrueParameter.Value.Value = value; }
51    }
52
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new BooleanErcOptions(this, cloner);
55    }
56
57    public bool GetRandom(IRandom random) {
58      if (!this.AllowTrue && !this.AllowFalse) throw new InvalidOperationException();
59      if (!this.AllowFalse) return true;
60      if (!this.AllowTrue) return false;
61
62      return random.NextDouble() >= 0.5;
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.