Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/15 11:42:02 (9 years ago)
Author:
gkronber
Message:

#2472: merged r12921,r12936:12938,r12940,r12947,r13055:13058,r13163,r13267,r13269 from trunk to stable

Location:
stable
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r12938 r13280  
    3838
    3939    #region parameter names
    40 
    4140    private const string NumberOfBitsParameterName = "NumberOfBits";
    42 
    4341    #endregion
    4442
     
    4745      get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; }
    4846    }
    49 
    5047    #endregion
    5148
    5249    #region Properties
    53 
    5450    public int NumberOfBits {
    5551      get { return NumberOfBitsParameter.Value.Value; }
    5652      set { NumberOfBitsParameter.Value.Value = value; }
    5753    }
    58 
    59 
    6054    #endregion
    6155
     
    6357      get { return true; }
    6458    }
     59
     60    #region item cloning and persistence
     61    // persistence
     62    [StorableConstructor]
     63    private EvenParityProblem(bool deserializing) : base(deserializing) { }
     64    [StorableHook(HookType.AfterDeserialization)]
     65    private void AfterDeserialization() {
     66      RegisterEventHandlers();
     67    }
     68
     69    // cloning
     70    private EvenParityProblem(EvenParityProblem original, Cloner cloner)
     71      : base(original, cloner) {
     72      RegisterEventHandlers();
     73    }
     74    public override IDeepCloneable Clone(Cloner cloner) {
     75      return new EvenParityProblem(this, cloner);
     76    }
     77    #endregion
    6578
    6679    public EvenParityProblem()
     
    8497
    8598      Encoding.Grammar = g;
     99
     100      BestKnownQuality = Math.Pow(2, NumberOfBits); // this is a benchmark problem (the best achievable quality is known for a given number of bits)
    86101    }
    87102
     
    108123    }
    109124
    110 
    111125    private static IEnumerable<bool> InterpretRec(ISymbolicExpressionTreeNode node, IEnumerable<int> bs) {
    112       Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> eval2 =
     126      Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> binaryEval =
    113127        (left, right, f) => InterpretRec(left, bs).Zip(InterpretRec(right, bs), f);
    114128
    115129      switch (node.Symbol.Name) {
    116         case "AND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
    117         case "OR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
    118         case "NAND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y));
    119         case "NOR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));
     130        case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
     131        case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
     132        case "NAND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y));
     133        case "NOR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));
    120134        default: {
    121135            byte bitPos;
     
    131145    }
    132146
    133     #region item cloning and persistence
    134     // persistence
    135     [StorableConstructor]
    136     private EvenParityProblem(bool deserializing) : base(deserializing) { }
    137 
    138     [StorableHook(HookType.AfterDeserialization)]
    139     private void AfterDeserialization() {
    140       RegisterEventHandlers();
    141     }
    142 
    143     // cloning
    144     private EvenParityProblem(EvenParityProblem original, Cloner cloner)
    145       : base(original, cloner) {
    146       RegisterEventHandlers();
    147     }
    148     public override IDeepCloneable Clone(Cloner cloner) {
    149       return new EvenParityProblem(this, cloner);
    150     }
    151     #endregion
    152 
    153147    #region events
    154 
    155148    private void RegisterEventHandlers() {
    156149      NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar();
  • stable/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r12938 r13280  
    4040
    4141    #region parameter names
    42 
    4342    private const string NumberOfBitsParameterName = "NumberOfBits";
    44 
    4543    #endregion
    4644
    4745    #region Parameter Properties
    48 
    4946    public IFixedValueParameter<IntValue> NumberOfBitsParameter {
    5047      get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; }
    5148    }
    52 
    5349    #endregion
    5450
    5551    #region Properties
    56 
    5752    public int NumberOfBits {
    5853      get { return NumberOfBitsParameter.Value.Value; }
    5954      set { NumberOfBitsParameter.Value.Value = value; }
    6055    }
    61 
    62 
    6356    #endregion
    6457
     
    6659      get { return true; }
    6760    }
     61
     62    #region item cloning and persistence
     63    // persistence
     64    [StorableConstructor]
     65    private MultiplexerProblem(bool deserializing) : base(deserializing) { }
     66    [StorableHook(HookType.AfterDeserialization)]
     67    private void AfterDeserialization() {
     68      RegisterEventHandlers();
     69    }
     70
     71    // cloning
     72    private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
     73      : base(original, cloner) {
     74      RegisterEventHandlers();
     75    }
     76    public override IDeepCloneable Clone(Cloner cloner) {
     77      return new MultiplexerProblem(this, cloner);
     78    }
     79    #endregion
     80
    6881
    6982    public MultiplexerProblem()
     
    98111
    99112      Encoding.Grammar = g;
     113
     114      BestKnownQuality = Math.Pow(2, NumberOfBits); // this is a benchmark problem (the best achievable quality is known for a given number of bits)
    100115    }
    101116
     
    103118    public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
    104119      if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero.");
    105       if (NumberOfBits > 40) throw new NotSupportedException("Mupltiplexer does not support problems with number of bits > 37.");
     120      if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37.");
    106121      var bs = Enumerable.Range(0, (int)Math.Pow(2, NumberOfBits));
    107122      var addrBits = (int)Math.Log(NumberOfBits, 2); // largest power of two that fits into the number of bits
     
    132147
    133148    private static IEnumerable<bool> InterpretRec(ISymbolicExpressionTreeNode node, IEnumerable<int> bs, byte addrBits) {
    134       Func<ISymbolicExpressionTreeNode, Func<bool, bool>, IEnumerable<bool>> eval1 =
     149      Func<ISymbolicExpressionTreeNode, Func<bool, bool>, IEnumerable<bool>> unaryEval =
    135150        (child, f) => InterpretRec(child, bs, addrBits).Select(f);
    136       Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> eval2 =
     151      Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> binaryEval =
    137152        (left, right, f) => InterpretRec(left, bs, addrBits).Zip(InterpretRec(right, bs, addrBits), f);
    138153
    139154      switch (node.Symbol.Name) {
    140         case "AND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
    141         case "OR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
    142         case "NOT": return eval1(node.GetSubtree(0), (x) => !x);
     155        case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);
     156        case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);
     157        case "NOT": return unaryEval(node.GetSubtree(0), (x) => !x);
    143158        case "IF": return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits);
    144159        default: {
     
    176191    }
    177192
    178     #region item cloning and persistence
    179     // persistence
    180     [StorableConstructor]
    181     private MultiplexerProblem(bool deserializing) : base(deserializing) { }
    182 
    183     [StorableHook(HookType.AfterDeserialization)]
    184     private void AfterDeserialization() {
    185       RegisterEventHandlers();
    186     }
    187 
    188     // cloning
    189     private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
    190       : base(original, cloner) {
    191       RegisterEventHandlers();
    192     }
    193     public override IDeepCloneable Clone(Cloner cloner) {
    194       return new MultiplexerProblem(this, cloner);
    195     }
    196     #endregion
    197 
    198193    #region events
    199 
    200194    private void RegisterEventHandlers() {
    201195      NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar();
Note: See TracChangeset for help on using the changeset viewer.