- Timestamp:
- 11/18/15 22:29:17 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs
r13163 r13267 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 … … 110 104 } 111 105 112 113 106 private static IEnumerable<bool> InterpretRec(ISymbolicExpressionTreeNode node, IEnumerable<int> bs) { 114 Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> eval2=107 Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> binaryEval = 115 108 (left, right, f) => InterpretRec(left, bs).Zip(InterpretRec(right, bs), f); 116 109 117 110 switch (node.Symbol.Name) { 118 case "AND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);119 case "OR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);120 case "NAND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y));121 case "NOR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y));111 case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y); 112 case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y); 113 case "NAND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x & y)); 114 case "NOR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => !(x | y)); 122 115 default: { 123 116 byte bitPos; … … 154 147 155 148 #region events 156 157 149 private void RegisterEventHandlers() { 158 150 NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar(); -
trunk/sources/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs
r13238 r13267 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 … … 105 98 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) { 106 99 if (NumberOfBits <= 0) throw new NotSupportedException("Number of bits must be larger than zero."); 107 if (NumberOfBits > 37) throw new NotSupportedException("Mu pltiplexer does not support problems with number of bits > 37.");100 if (NumberOfBits > 37) throw new NotSupportedException("Multiplexer does not support problems with number of bits > 37."); 108 101 var bs = Enumerable.Range(0, (int)Math.Pow(2, NumberOfBits)); 109 102 var addrBits = (int)Math.Log(NumberOfBits, 2); // largest power of two that fits into the number of bits … … 134 127 135 128 private static IEnumerable<bool> InterpretRec(ISymbolicExpressionTreeNode node, IEnumerable<int> bs, byte addrBits) { 136 Func<ISymbolicExpressionTreeNode, Func<bool, bool>, IEnumerable<bool>> eval1=129 Func<ISymbolicExpressionTreeNode, Func<bool, bool>, IEnumerable<bool>> unaryEval = 137 130 (child, f) => InterpretRec(child, bs, addrBits).Select(f); 138 Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> eval2=131 Func<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode, Func<bool, bool, bool>, IEnumerable<bool>> binaryEval = 139 132 (left, right, f) => InterpretRec(left, bs, addrBits).Zip(InterpretRec(right, bs, addrBits), f); 140 133 141 134 switch (node.Symbol.Name) { 142 case "AND": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y);143 case "OR": return eval2(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y);144 case "NOT": return eval1(node.GetSubtree(0), (x) => !x);145 case "IF": return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits);135 case "AND": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x & y); 136 case "OR": return binaryEval(node.GetSubtree(0), node.GetSubtree(1), (x, y) => x | y); 137 case "NOT": return unaryEval(node.GetSubtree(0), (x) => !x); 138 case "IF": return EvalIf(node.GetSubtree(0), node.GetSubtree(1), node.GetSubtree(2), bs, addrBits); 146 139 default: { 147 140 if (node.Symbol.Name[0] == 'a') { … … 199 192 200 193 #region events 201 202 194 private void RegisterEventHandlers() { 203 195 NumberOfBitsParameter.Value.ValueChanged += (sender, args) => UpdateGrammar();
Note: See TracChangeset
for help on using the changeset viewer.