- Timestamp:
- 07/26/12 09:51:13 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower/3.3/Grammar.cs
r8086 r8331 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 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower/3.3/HeuristicLab.Problems.LawnMower.csproj
r8086 r8331 96 96 <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules> 97 97 </PropertyGroup> 98 <PropertyGroup> 99 <SignAssembly>true</SignAssembly> 100 </PropertyGroup> 101 <PropertyGroup> 102 <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile> 103 </PropertyGroup> 98 104 <ItemGroup> 99 105 <Reference Include="HeuristicLab.Common-3.3"> … … 106 112 <ItemGroup> 107 113 <Compile Include="BestSolutionAnalyzer.cs" /> 114 <None Include="HeuristicLab.snk" /> 108 115 <None Include="Plugin.cs.frame" /> 109 116 <Compile Include="Interpreter.cs" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower/3.3/Interpreter.cs
r8086 r8331 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 26 … … 51 53 mowerState.Energy = length * width * 2; 52 54 lawn[mowerState.Position.Item1, mowerState.Position.Item2] = true; 53 EvaluateLawnMowerProgram(tree.Root, ref mowerState, lawn);55 EvaluateLawnMowerProgram(tree.Root, mowerState, lawn, tree.Root.Subtrees.Skip(1).ToArray()); 54 56 55 57 return lawn; … … 57 59 58 60 59 private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, ref MowerState mowerState, bool[,] lawn) {61 private static Tuple<int, int> EvaluateLawnMowerProgram(ISymbolicExpressionTreeNode node, MowerState mowerState, bool[,] lawn, IEnumerable<ISymbolicExpressionTreeNode> adfs) { 60 62 if (mowerState.Energy <= 0) return new Tuple<int, int>(0, 0); 61 63 62 64 if (node.Symbol is ProgramRootSymbol) { 63 return EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn);65 return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 64 66 } else if (node.Symbol is StartSymbol) { 65 return EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn);67 return EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 66 68 } else if (node.Symbol is Left) { 67 69 switch (mowerState.Heading) { … … 104 106 return constNode.Value; 105 107 } else if (node.Symbol is Sum) { 106 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn);107 var q = EvaluateLawnMowerProgram(node.GetSubtree(1), ref mowerState, lawn);108 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 109 var q = EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs); 108 110 return new Tuple<int, int>(p.Item1 + q.Item1, 109 111 p.Item2 + q.Item2); 110 112 } else if (node.Symbol is Prog) { 111 EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn);112 return EvaluateLawnMowerProgram(node.GetSubtree(1), ref mowerState, lawn);113 EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 114 return EvaluateLawnMowerProgram(node.GetSubtree(1), mowerState, lawn, adfs); 113 115 } else if (node.Symbol is Frog) { 114 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), ref mowerState, lawn);116 var p = EvaluateLawnMowerProgram(node.GetSubtree(0), mowerState, lawn, adfs); 115 117 116 118 uint newRow = (uint)((mowerState.Position.Item1 + lawn.GetLength(0) + p.Item1 % lawn.GetLength(0)) % lawn.GetLength(0)); … … 120 122 lawn[newRow, newCol] = true; 121 123 return new Tuple<int, int>(0, 0); 124 } else if (node.Symbol is InvokeFunction) { 125 var invokeNode = node as InvokeFunctionTreeNode; 126 127 // find the function definition for the invoke call 128 var functionDefinition = (from adf in adfs.Cast<DefunTreeNode>() 129 where adf.FunctionName == invokeNode.Symbol.FunctionName 130 select adf).Single(); 131 // clone the function definition because we are replacing the argument nodes 132 functionDefinition = (DefunTreeNode) functionDefinition.Clone(); 133 // find the argument tree nodes and their parents in the original function definition 134 // toList is necessary to prevent that newly inserted branches are iterated 135 var argumentCutPoints = (from parent in functionDefinition.IterateNodesPrefix() 136 from subtree in parent.Subtrees 137 where subtree is ArgumentTreeNode 138 select new { Parent = parent, Argument = subtree.Symbol as Argument, ChildIndex = parent.IndexOfSubtree(subtree) }) 139 .ToList(); 140 // replace all argument tree ndoes with the matching argument of the invoke node 141 foreach (var cutPoint in argumentCutPoints) { 142 cutPoint.Parent.RemoveSubtree(cutPoint.ChildIndex); 143 cutPoint.Parent.InsertSubtree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubtree(cutPoint.Argument.ArgumentIndex).Clone()); 144 } 145 return EvaluateLawnMowerProgram(functionDefinition.GetSubtree(0), mowerState, lawn, adfs); 122 146 } else { 123 147 throw new ArgumentException("Invalid symbol in the lawn mower program."); 124 148 } 125 149 } 126 127 150 } 128 151 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower/3.3/Plugin.cs.frame
r8086 r8331 23 23 24 24 namespace HeuristicLab.Problems.LawnMower { 25 [Plugin("HeuristicLab.Problems.LawnMower", "Lawn mower demo problem for genetic programming", "3.3. 0.$WCREV$")]25 [Plugin("HeuristicLab.Problems.LawnMower", "Lawn mower demo problem for genetic programming", "3.3.7.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.LawnMower-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower/3.3/Problem.cs
r8086 r8331 42 42 private const string MaxLawnMowerProgramDepthParameterName = "MaxProgramDepth"; 43 43 private const string LawnMowerGrammarParameterName = "Grammar"; 44 private const string MaxFunctionDefinitionsParameterName = "MaxFunctionDefinitions"; 45 private const string MaxArgumentDefinitionsParameterName = "MaxArgumentDefinitions"; 44 46 45 47 public IFixedValueParameter<IntValue> LawnWidthParameter { … … 58 60 get { return (IValueParameter<Grammar>)Parameters[LawnMowerGrammarParameterName]; } 59 61 } 62 public IFixedValueParameter<IntValue> MaxFunctionDefinitionsParameter { 63 get { return (IFixedValueParameter<IntValue>)Parameters[MaxFunctionDefinitionsParameterName]; } 64 } 65 public IFixedValueParameter<IntValue> MaxArgumentDefinitionsParameter { 66 get { return (IFixedValueParameter<IntValue>)Parameters[MaxArgumentDefinitionsParameterName]; } 67 } 60 68 61 69 [StorableConstructor] … … 73 81 Parameters.Add(new FixedValueParameter<IntValue>(MaxLawnMowerProgramDepthParameterName, "Maximal depth of the lawn mower program.", new IntValue(13))); 74 82 Parameters.Add(new FixedValueParameter<IntValue>(MaxLawnMowerProgramLengthParameterName, "Maximal length of the lawn mower program.", new IntValue(1000))); 83 Parameters.Add(new FixedValueParameter<IntValue>(MaxFunctionDefinitionsParameterName, "Maximal number of automatically defined functions (ADF).", new IntValue(3))); 84 Parameters.Add(new FixedValueParameter<IntValue>(MaxArgumentDefinitionsParameterName, "Maximal number of automatically defined arguments.", new IntValue(3))); 75 85 Parameters.Add(new ValueParameter<Grammar>(LawnMowerGrammarParameterName, "Grammar for the lawn mower program.", 76 86 new Grammar())); … … 105 115 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += 106 116 SymbolicExpressionTreeParameterOnActualNameChanged; 117 MaxArgumentDefinitionsParameter.ValueChanged += ParameterizeGrammar; 118 MaxFunctionDefinitionsParameter.ValueChanged += ParameterizeGrammar; 107 119 } 108 120 109 110 111 121 protected override void OnEvaluatorChanged() { 112 base.OnEvaluatorChanged();113 122 Evaluator.LawnMowerProgramParameter.ActualName = LawnMowerProgramParameterName; 114 123 Evaluator.LawnLengthParameter.ActualName = LawnLengthParameterName; … … 117 126 ParameterizeAnalyzers(); 118 127 ParameterizeOperators(); 128 base.OnEvaluatorChanged(); 119 129 } 120 130 121 131 protected override void OnSolutionCreatorChanged() { 122 base.OnSolutionCreatorChanged();123 132 SolutionCreator.SymbolicExpressionTreeParameter.ActualName = LawnMowerProgramParameterName; 124 133 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += SymbolicExpressionTreeParameterOnActualNameChanged; 125 134 ParameterizeAnalyzers(); 126 135 ParameterizeOperators(); 136 base.OnSolutionCreatorChanged(); 127 137 } 128 138 … … 135 145 ParameterizeAnalyzers(); 136 146 ParameterizeOperators(); 147 } 148 149 private void ParameterizeGrammar(object sender, EventArgs eventArgs) { 150 GrammarParameter.Value.MaximumFunctionArguments = MaxArgumentDefinitionsParameter.Value.Value; 151 GrammarParameter.Value.MaximumFunctionDefinitions = MaxFunctionDefinitionsParameter.Value.Value; 137 152 } 138 153 … … 175 190 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 176 191 } 192 foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) { 193 op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name; 194 op.MaximumFunctionArgumentsParameter.ActualName = MaxArgumentDefinitionsParameter.Name; 195 } 177 196 } 178 197 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.LawnMower/3.3/Properties/AssemblyInfo.cs.frame
r8086 r8331 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3. 0.$WCREV$")]56 [assembly: AssemblyFileVersion("3.3.7.$WCREV$")]
Note: See TracChangeset
for help on using the changeset viewer.