Changeset 8163
- Timestamp:
- 06/29/12 15:44:29 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.LawnMower/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Grammar.cs
r8059 r8163 64 64 // define grammar rules 65 65 foreach (var s in allSymbols) { 66 AddAllowedChildSymbol(sum, s , 0);67 AddAllowedChildSymbol(sum, s , 1);68 AddAllowedChildSymbol(prog, s , 0);69 AddAllowedChildSymbol(prog, s , 1);70 AddAllowedChildSymbol(frog, s , 0);71 AddAllowedChildSymbol(StartSymbol, s , 0);66 AddAllowedChildSymbol(sum, s); 67 AddAllowedChildSymbol(sum, s); 68 AddAllowedChildSymbol(prog, s); 69 AddAllowedChildSymbol(prog, s); 70 AddAllowedChildSymbol(frog, s); 71 AddAllowedChildSymbol(StartSymbol, s); 72 72 } 73 73 } -
trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Interpreter.cs
r8131 r8163 53 53 mowerState.Energy = length * width * 2; 54 54 lawn[mowerState.Position.Item1, mowerState.Position.Item2] = true; 55 EvaluateLawnMowerProgram(tree.Root, refmowerState, lawn, tree.Root.Subtrees.Skip(1).ToArray());55 EvaluateLawnMowerProgram(tree.Root, mowerState, lawn, tree.Root.Subtrees.Skip(1).ToArray()); 56 56 57 57 return lawn; … … 59 59 60 60 61 private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, refMowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) {61 private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, MowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) { 62 62 if (mowerState.Energy <= 0) return new Tuple<int, int>(0, 0); 63 63 64 64 if (node.Symbol is ProgramRootSymbol) { 65 return EvaluateLawnMowerProgram(node.GetSubtree(0), refmowerState, lawn, adfs);65 return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 66 66 } else if (node.Symbol is StartSymbol) { 67 return EvaluateLawnMowerProgram(node.GetSubtree(0), refmowerState, lawn, adfs);67 return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 68 68 } else if (node.Symbol is Left) { 69 69 switch (mowerState.Heading) { … … 106 106 return constNode.Value; 107 107 } else if (node.Symbol is Sum) { 108 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), refmowerState, lawn, adfs);109 var q = EvaluateLawnMowerProgram(node.GetSubtree(1), refmowerState, lawn, adfs);108 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 109 var q = EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs); 110 110 return new Tuple<int, int>(p.Item1 + q.Item1, 111 111 p.Item2 + q.Item2); 112 112 } else if (node.Symbol is Prog) { 113 EvaluateLawnMowerProgram(node.GetSubtree(0), refmowerState, lawn, adfs);114 return EvaluateLawnMowerProgram(node.GetSubtree(1), refmowerState, lawn, adfs);113 EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 114 return EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs); 115 115 } else if (node.Symbol is Frog) { 116 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), refmowerState, lawn, adfs);116 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 117 117 118 118 uint newRow = (uint)((mowerState.Position.Item1 + lawn.GetLength(0) + p.Item1 % lawn.GetLength(0)) % lawn.GetLength(0)); … … 143 143 cutPoint.Parent.InsertSubtree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubtree(cutPoint.Argument.ArgumentIndex).Clone()); 144 144 } 145 return EvaluateLawnMowerProgram(functionDefinition.GetSubtree(0), refmowerState, lawn, adfs);145 return EvaluateLawnMowerProgram(functionDefinition.GetSubtree(0), mowerState, lawn, adfs); 146 146 } else { 147 147 throw new ArgumentException("Invalid symbol in the lawn mower program."); -
trunk/sources/HeuristicLab.Problems.LawnMower/3.3/Problem.cs
r8131 r8163 120 120 121 121 protected override void OnEvaluatorChanged() { 122 base.OnEvaluatorChanged();123 122 Evaluator.LawnMowerProgramParameter.ActualName = LawnMowerProgramParameterName; 124 123 Evaluator.LawnLengthParameter.ActualName = LawnLengthParameterName; … … 127 126 ParameterizeAnalyzers(); 128 127 ParameterizeOperators(); 128 base.OnEvaluatorChanged(); 129 129 } 130 130 131 131 protected override void OnSolutionCreatorChanged() { 132 base.OnSolutionCreatorChanged();133 132 SolutionCreator.SymbolicExpressionTreeParameter.ActualName = LawnMowerProgramParameterName; 134 133 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += SymbolicExpressionTreeParameterOnActualNameChanged; 135 134 ParameterizeAnalyzers(); 136 135 ParameterizeOperators(); 136 base.OnSolutionCreatorChanged(); 137 137 } 138 138
Note: See TracChangeset
for help on using the changeset viewer.