- Timestamp:
- 11/19/15 11:42:02 (9 years ago)
- Location:
- stable
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12921,12936-12938,12940,12947,13055-13058,13163,13267,13269
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs
r12938 r13280 38 38 39 39 #region parameter names 40 41 40 private const string NumberOfBitsParameterName = "NumberOfBits"; 42 43 41 #endregion 44 42 … … 47 45 get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; } 48 46 } 49 50 47 #endregion 51 48 52 49 #region Properties 53 54 50 public int NumberOfBits { 55 51 get { return NumberOfBitsParameter.Value.Value; } 56 52 set { NumberOfBitsParameter.Value.Value = value; } 57 53 } 58 59 60 54 #endregion 61 55 … … 63 57 get { return true; } 64 58 } 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 65 78 66 79 public EvenParityProblem() … … 84 97 85 98 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) 86 101 } 87 102 … … 108 123 } 109 124 110 111 125 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 = 113 127 (left, right, f) => InterpretRec(left, bs).Zip(InterpretRec(right, bs), f); 114 128 115 129 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)); 120 134 default: { 121 135 byte bitPos; … … 131 145 } 132 146 133 #region item cloning and persistence134 // persistence135 [StorableConstructor]136 private EvenParityProblem(bool deserializing) : base(deserializing) { }137 138 [StorableHook(HookType.AfterDeserialization)]139 private void AfterDeserialization() {140 RegisterEventHandlers();141 }142 143 // cloning144 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 #endregion152 153 147 #region events 154 155 148 private void RegisterEventHandlers() { 156 149 NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar(); -
stable/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs
r12938 r13280 40 40 41 41 #region parameter names 42 43 42 private const string NumberOfBitsParameterName = "NumberOfBits"; 44 45 43 #endregion 46 44 47 45 #region Parameter Properties 48 49 46 public IFixedValueParameter<IntValue> NumberOfBitsParameter { 50 47 get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; } 51 48 } 52 53 49 #endregion 54 50 55 51 #region Properties 56 57 52 public int NumberOfBits { 58 53 get { return NumberOfBitsParameter.Value.Value; } 59 54 set { NumberOfBitsParameter.Value.Value = value; } 60 55 } 61 62 63 56 #endregion 64 57 … … 66 59 get { return true; } 67 60 } 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 68 81 69 82 public MultiplexerProblem() … … 98 111 99 112 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) 100 115 } 101 116 … … 103 118 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) { 104 119 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."); 106 121 var bs = Enumerable.Range(0, (int)Math.Pow(2, NumberOfBits)); 107 122 var addrBits = (int)Math.Log(NumberOfBits, 2); // largest power of two that fits into the number of bits … … 132 147 133 148 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 = 135 150 (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 = 137 152 (left, right, f) => InterpretRec(left, bs, addrBits).Zip(InterpretRec(right, bs, addrBits), f); 138 153 139 154 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); 143 158 case "IF": return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits); 144 159 default: { … … 176 191 } 177 192 178 #region item cloning and persistence179 // persistence180 [StorableConstructor]181 private MultiplexerProblem(bool deserializing) : base(deserializing) { }182 183 [StorableHook(HookType.AfterDeserialization)]184 private void AfterDeserialization() {185 RegisterEventHandlers();186 }187 188 // cloning189 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 #endregion197 198 193 #region events 199 200 194 private void RegisterEventHandlers() { 201 195 NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar();
Note: See TracChangeset
for help on using the changeset viewer.