- Timestamp:
- 03/15/11 13:34:38 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntExpressionGrammar.cs
r5517 r5686 28 28 namespace HeuristicLab.Problems.ArtificialAnt { 29 29 [StorableClass] 30 public class ArtificialAntExpressionGrammar : DefaultSymbolicExpressionGrammar {30 public class ArtificialAntExpressionGrammar : SymbolicExpressionGrammar { 31 31 32 32 public ArtificialAntExpressionGrammar() … … 53 53 54 54 allSymbols.ForEach(s => AddSymbol(s)); 55 SetMinSubtreeCount(ifFoodAhead, 2); 56 SetMaxSubtreeCount(ifFoodAhead, 2); 57 SetMinSubtreeCount(prog2, 2); 58 SetMaxSubtreeCount(prog2, 2); 59 SetMinSubtreeCount(prog3, 3); 60 SetMaxSubtreeCount(prog3, 3); 61 SetMinSubtreeCount(move, 0); 62 SetMaxSubtreeCount(move, 0); 63 SetMinSubtreeCount(left, 0); 64 SetMaxSubtreeCount(left, 0); 65 SetMinSubtreeCount(right, 0); 66 SetMaxSubtreeCount(right, 0); 55 SetSubtreeCount(ifFoodAhead, 2, 3); 56 SetSubtreeCount(prog2, 2, 2); 57 SetSubtreeCount(prog3, 3, 3); 58 SetSubtreeCount(move, 0, 0); 59 SetSubtreeCount(left, 0, 0); 60 SetSubtreeCount(right, 0, 0); 67 61 68 62 // each symbols is allowed as child of the start symbol 69 allSymbols.ForEach(s => SetAllowedChild(StartSymbol, s, 0)); 63 allSymbols.ForEach(s => AddAllowedChildSymbol(StartSymbol, s)); 64 allSymbols.ForEach(s => AddAllowedChildSymbol(DefunSymbol, s)); 70 65 71 66 // each symbol is allowed as child of all other symbols (except for terminals that have MaxSubtreeCount == 0 72 foreach (var parent in allSymbols) { 73 for (int argIndex = 0; argIndex < GetMaxSubtreeCount(parent); argIndex++) { 74 foreach (var child in allSymbols) { 75 SetAllowedChild(parent, child, argIndex); 76 } 67 foreach (var parent in nonTerminalSymbols) { 68 foreach (var child in allSymbols) { 69 AddAllowedChildSymbol(parent, child); 77 70 } 78 71 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntProblem.cs
r5578 r5686 101 101 get { return EvaluatorParameter; } 102 102 } 103 public IValueParameter<ISymbolicExpression TreeGrammar> ArtificialAntExpressionGrammarParameter {104 get { return (IValueParameter<ISymbolicExpression TreeGrammar>)Parameters["ArtificialAntExpressionGrammar"]; }103 public IValueParameter<ISymbolicExpressionGrammar> ArtificialAntExpressionGrammarParameter { 104 get { return (IValueParameter<ISymbolicExpressionGrammar>)Parameters["ArtificialAntExpressionGrammar"]; } 105 105 } 106 106 public IValueParameter<IntValue> MaxExpressionLengthParameter { … … 173 173 get { return EvaluatorParameter.Value; } 174 174 } 175 public GlobalSymbolicExpressionGrammar ArtificialAntExpressionGrammar {176 get { return ( GlobalSymbolicExpressionGrammar)ArtificialAntExpressionGrammarParameter.Value; }175 public ArtificialAntExpressionGrammar ArtificialAntExpressionGrammar { 176 get { return (ArtificialAntExpressionGrammar)ArtificialAntExpressionGrammarParameter.Value; } 177 177 } 178 178 public DoubleValue BestKnownQuality { … … 211 211 Evaluator evaluator = new Evaluator(); 212 212 BoolMatrix world = new BoolMatrix(santaFeAntTrail); 213 ISymbolicExpressionTreeGrammar grammar = new GlobalSymbolicExpressionGrammar(new ArtificialAntExpressionGrammar());214 213 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true))); 215 214 Parameters.Add(new ValueParameter<ISymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator)); … … 220 219 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3))); 221 220 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))); 222 Parameters.Add(new ValueParameter<ISymbolicExpression TreeGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", grammar));221 Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar())); 223 222 Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world)); 224 223 Parameters.Add(new ValueParameter<IntValue>("MaxTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600))); … … 294 293 295 294 private void MaxFunctionDefinitionsParameter_ValueChanged(object sender, EventArgs e) { 296 ArtificialAntExpressionGrammar.Max FunctionDefinitions = MaxFunctionDefinitions.Value;295 ArtificialAntExpressionGrammar.MaximumFunctionDefinitions = MaxFunctionDefinitions.Value; 297 296 ParameterizeOperators(); 298 297 ParameterizeAnalyzers(); 299 298 } 300 299 private void MaxFunctionArgumentsParameter_ValueChanged(object sender, EventArgs e) { 301 ArtificialAntExpressionGrammar.Max FunctionArguments = MaxFunctionArguments.Value;300 ArtificialAntExpressionGrammar.MaximumFunctionArguments = MaxFunctionArguments.Value; 302 301 ParameterizeOperators(); 303 302 ParameterizeAnalyzers();
Note: See TracChangeset
for help on using the changeset viewer.