Changeset 5517
- Timestamp:
- 02/18/11 14:50:19 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/AntInterpreter.cs
r5473 r5517 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;28 27 using HeuristicLab.Problems.ArtificialAnt.Symbols; 29 28 … … 65 64 private int currentAntLocationColumn; 66 65 private int nFoodItems; 67 private Stack< SymbolicExpressionTreeNode> nodeStack = new Stack<SymbolicExpressionTreeNode>();66 private Stack<ISymbolicExpressionTreeNode> nodeStack = new Stack<ISymbolicExpressionTreeNode>(); 68 67 69 68 private void CountFoodItems() { … … 94 93 // expression evaluated completly => start at root again 95 94 if (nodeStack.Count == 0) { 96 nodeStack.Push(Expression.Root. SubTrees[0].SubTrees[0]);95 nodeStack.Push(Expression.Root.GetSubTree(0).GetSubTree(0)); 97 96 } 98 97 … … 115 114 NextField(out nextAntLocationRow, out nextAntLocationColumn); 116 115 if (World[nextAntLocationRow, nextAntLocationColumn]) { 117 nodeStack.Push(currentNode. SubTrees[0]);116 nodeStack.Push(currentNode.GetSubTree(0)); 118 117 } else { 119 nodeStack.Push(currentNode. SubTrees[1]);118 nodeStack.Push(currentNode.GetSubTree(1)); 120 119 } 121 120 } else if (currentNode.Symbol is Prog2) { 122 nodeStack.Push(currentNode. SubTrees[1]);123 nodeStack.Push(currentNode. SubTrees[0]);121 nodeStack.Push(currentNode.GetSubTree(1)); 122 nodeStack.Push(currentNode.GetSubTree(0)); 124 123 return; 125 124 } else if (currentNode.Symbol is Prog3) { 126 nodeStack.Push(currentNode. SubTrees[2]);127 nodeStack.Push(currentNode. SubTrees[1]);128 nodeStack.Push(currentNode. SubTrees[0]);125 nodeStack.Push(currentNode.GetSubTree(2)); 126 nodeStack.Push(currentNode.GetSubTree(1)); 127 nodeStack.Push(currentNode.GetSubTree(0)); 129 128 return; 130 129 } else if (currentNode.Symbol is InvokeFunction) { … … 132 131 var functionDefinition = (SymbolicExpressionTreeNode)FindMatchingFunction(invokeNode.Symbol.FunctionName).Clone(); 133 132 var argumentCutPoints = (from node in functionDefinition.IterateNodesPrefix() 134 where node.SubTrees.Count > 0133 where node.SubTrees.Count() > 0 135 134 from subtree in node.SubTrees 136 135 where subtree is ArgumentTreeNode 137 select new { Parent = node, Argument = subtree.Symbol as Argument, ChildIndex = node. SubTrees.IndexOf(subtree) }).ToList();136 select new { Parent = node, Argument = subtree.Symbol as Argument, ChildIndex = node.IndexOfSubTree(subtree) }).ToList(); 138 137 foreach (var cutPoint in argumentCutPoints) { 139 138 cutPoint.Parent.RemoveSubTree(cutPoint.ChildIndex); 140 cutPoint.Parent.InsertSubTree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode. SubTrees[cutPoint.Argument.ArgumentIndex].Clone());139 cutPoint.Parent.InsertSubTree(cutPoint.ChildIndex, (SymbolicExpressionTreeNode)invokeNode.GetSubTree(cutPoint.Argument.ArgumentIndex).Clone()); 141 140 } 142 nodeStack.Push(functionDefinition. SubTrees[0]);141 nodeStack.Push(functionDefinition.GetSubTree(0)); 143 142 } else { 144 143 throw new InvalidOperationException(currentNode.Symbol.ToString()); -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntExpressionGrammar.cs
r5473 r5517 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 using HeuristicLab.Problems.ArtificialAnt.Symbols; -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs
r5499 r5517 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;32 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;33 30 using HeuristicLab.Optimization; 34 31 using HeuristicLab.Parameters; … … 104 101 get { return EvaluatorParameter; } 105 102 } 106 public ValueParameter<ISymbolicExpression Grammar> ArtificialAntExpressionGrammarParameter {107 get { return (ValueParameter<ISymbolicExpression Grammar>)Parameters["ArtificialAntExpressionGrammar"]; }103 public ValueParameter<ISymbolicExpressionTreeGrammar> ArtificialAntExpressionGrammarParameter { 104 get { return (ValueParameter<ISymbolicExpressionTreeGrammar>)Parameters["ArtificialAntExpressionGrammar"]; } 108 105 } 109 106 public ValueParameter<IntValue> MaxExpressionLengthParameter { … … 218 215 Evaluator evaluator = new Evaluator(); 219 216 BoolMatrix world = new BoolMatrix(santaFeAntTrail); 220 ISymbolicExpression Grammar grammar = new GlobalSymbolicExpressionGrammar(new ArtificialAntExpressionGrammar());217 ISymbolicExpressionTreeGrammar grammar = new GlobalSymbolicExpressionGrammar(new ArtificialAntExpressionGrammar()); 221 218 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true))); 222 219 Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator)); … … 227 224 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3))); 228 225 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions in the expression to control the artificial ant.", new IntValue(3))); 229 Parameters.Add(new ValueParameter<ISymbolicExpression Grammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", grammar));226 Parameters.Add(new ValueParameter<ISymbolicExpressionTreeGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", grammar)); 230 227 Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world)); 231 228 Parameters.Add(new ValueParameter<IntValue>("MaxTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600))); … … 233 230 creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution"; 234 231 evaluator.QualityParameter.ActualName = "FoodEaten"; 235 ParameterizeSolutionCreator();236 ParameterizeEvaluator();237 232 InitializeOperators(); 238 233 AttachEventHandlers(); … … 263 258 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 264 259 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged); 265 ParameterizeSolutionCreator();266 ParameterizeEvaluator();267 260 ParameterizeAnalyzers(); 268 261 ParameterizeOperators(); … … 270 263 } 271 264 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 272 ParameterizeEvaluator();273 265 ParameterizeAnalyzers(); 274 266 ParameterizeOperators(); … … 276 268 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 277 269 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 278 Parameterize Evaluator();279 Parameterize Analyzers();270 ParameterizeAnalyzers(); 271 ParameterizeOperators(); 280 272 OnEvaluatorChanged(); 281 273 } … … 283 275 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 284 276 ParameterizeAnalyzers(); 285 }286 277 ParameterizeOperators(); 278 } 287 279 #endregion 288 280 … … 299 291 } 300 292 301 void MaxFunctionDefinitionsParameter_ValueChanged(object sender, EventArgs e) {293 private void MaxFunctionDefinitionsParameter_ValueChanged(object sender, EventArgs e) { 302 294 ArtificialAntExpressionGrammar.MaxFunctionDefinitions = MaxFunctionDefinitions.Value; 303 295 } 304 305 void MaxFunctionArgumentsParameter_ValueChanged(object sender, EventArgs e) { 296 private void MaxFunctionArgumentsParameter_ValueChanged(object sender, EventArgs e) { 306 297 ArtificialAntExpressionGrammar.MaxFunctionArguments = MaxFunctionArguments.Value; 307 298 } … … 317 308 } 318 309 319 private void ParameterizeSolutionCreator() {320 SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;321 SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;322 SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;323 }324 private void ParameterizeEvaluator() {325 Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;326 Evaluator.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;327 Evaluator.WorldParameter.ActualName = WorldParameter.Name;328 }329 310 private void ParameterizeAnalyzers() { 330 311 foreach (IAntTrailAnalyzer analyzer in AntTrailAnalyzers) { … … 340 321 341 322 private void ParameterizeOperators() { 342 foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) { 343 op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name; 344 op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name; 345 op.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name; 323 foreach (ISymbolicExpressionTreeGrammarBasedOperator op in Operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) { 324 op.SymbolicExpressionTreeGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name; 325 } 326 foreach (ISymbolicExpressionTreeSizeConstraintOperator op in Operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) { 327 op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaxExpressionDepthParameter.Name; 328 op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaxExpressionLengthParameter.Name; 329 346 330 } 347 331 foreach (Evaluator op in Operators.OfType<Evaluator>()) { … … 357 341 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 358 342 } 359 foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) { 360 op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name; 361 op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 362 } 363 foreach (SymbolicExpressionTreeCreator op in Operators.OfType<SymbolicExpressionTreeCreator>()) { 364 op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 365 op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name; 366 } 367 } 368 369 343 foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in Operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) { 344 op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name; 345 op.MaximumFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name; 346 } 347 foreach (ISymbolicExpressionTreeCreator op in Operators.OfType<ISymbolicExpressionTreeCreator>()) { 348 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 349 } 350 } 370 351 #endregion 371 352 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/Symbols/IfFoodAhead.cs
r5445 r5517 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/Symbols/Left.cs
r5445 r5517 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/Symbols/Move.cs
r5445 r5517 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/Symbols/Prog2.cs
r5445 r5517 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols;25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/Symbols/Prog3.cs
r5445 r5517 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 namespace HeuristicLab.Problems.ArtificialAnt.Symbols { -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/Symbols/Right.cs
r5445 r5517 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Symbols;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 namespace HeuristicLab.Problems.ArtificialAnt.Symbols {
Note: See TracChangeset
for help on using the changeset viewer.