Changeset 3238
- Timestamp:
- 03/30/10 19:40:13 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntInterpreter.cs
r3223 r3238 83 83 internal void Run(SymbolicExpressionTree tree) { 84 84 while (FoodEaten < N_FOOD_ITEMS && ElapsedTime < MaxTimeSteps) { 85 Step(tree.Root );85 Step(tree.Root.SubTrees[0]); 86 86 } 87 87 } … … 117 117 Step(currentNode.SubTrees[2]); 118 118 return; 119 } else {119 } else { 120 120 throw new InvalidOperationException(currentNode.Symbol.ToString()); 121 121 } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs
r3223 r3238 24 24 using System.Collections.Generic; 25 25 using System; 26 using System.Linq; 26 27 using HeuristicLab.Core; 27 28 namespace HeuristicLab.Problems.ArtificialAnt { … … 142 143 143 144 #endregion 145 146 #region ISymbolicExpressionGrammar Members 147 148 149 public bool IsValidExpression(SymbolicExpressionTree expression) { 150 if (expression.Root.Symbol != StartSymbol) return false; 151 return IsValidExpression(expression.Root); 152 } 153 154 #endregion 155 156 private bool IsValidExpression(SymbolicExpressionTreeNode root) { 157 if (root.SubTrees.Count < MinSubTrees(root.Symbol)) return false; 158 if (root.SubTrees.Count > MaxSubTrees(root.Symbol)) return false; 159 for (int i = 0; i < root.SubTrees.Count; i++) { 160 if (!AllowedSymbols(root.Symbol, i).Contains(root.SubTrees[i].Symbol)) return false; 161 if (!IsValidExpression(root.SubTrees[i])) return false; 162 } 163 return true; 164 } 144 165 } 145 166 } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs
r3223 r3238 127 127 Evaluator evaluator = new Evaluator(); 128 128 ArtificialAntExpressionGrammar grammar = new ArtificialAntExpressionGrammar(); 129 BestAntTrailVisualizer visualizer = new BestAntTrailVisualizer(); 129 130 130 131 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true))); 131 132 Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator)); 132 133 Parameters.Add(new ValueParameter<Evaluator>("Evaluator", "The operator which should be used to evaluate artificial ant solutions.", evaluator)); 133 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue( 200)));134 Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue(89))); 134 135 Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", grammar)); 135 136 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100))); 136 137 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10))); 137 Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", null));138 Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", visualizer)); 138 139 139 140 creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution"; … … 141 142 ParameterizeSolutionCreator(); 142 143 ParameterizeEvaluator(); 144 ParameterizeVisualizer(); 143 145 144 146 Initialize(); … … 212 214 operators.Add(Evaluator); 213 215 operators.Add(SolutionCreator); 216 operators.Add(new SubtreeCrossover()); 214 217 ParameterizeOperators(); 215 218 } … … 224 227 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 225 228 } 226 } 229 foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) { 230 op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name; 231 op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name; 232 op.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name; 233 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 234 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 235 } 236 } 237 private void ParameterizeVisualizer() { 238 if (Visualizer != null) { 239 Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 240 if (Visualizer is IAntTrailVisualizer) 241 ((IAntTrailVisualizer)Visualizer).SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 242 } 243 } 244 227 245 #endregion 228 246 } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLab.Problems.ArtificialAnt-3.3.csproj
r3223 r3238 86 86 <ItemGroup> 87 87 <Compile Include="AntInterpreter.cs" /> 88 <Compile Include="BestAntTrailVisualizer.cs" /> 88 89 <Compile Include="HeuristicLabProblemsArtificialAntPlugin.cs" /> 89 90 <Compile Include="IAntTrailVisualizer.cs" /> … … 96 97 <Compile Include="ArtificialAntProblemView.Designer.cs"> 97 98 <DependentUpon>ArtificialAntProblemView.cs</DependentUpon> 99 </Compile> 100 <Compile Include="AntTrail.cs" /> 101 <Compile Include="AntTrailView.cs"> 102 <SubType>UserControl</SubType> 103 </Compile> 104 <Compile Include="AntTrailView.Designer.cs"> 105 <DependentUpon>AntTrailView.cs</DependentUpon> 98 106 </Compile> 99 107 <Compile Include="Properties\AssemblyInfo.cs" /> … … 117 125 <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project> 118 126 <Name>HeuristicLab.Common.Resources-3.2</Name> 127 </ProjectReference> 128 <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj"> 129 <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project> 130 <Name>HeuristicLab.Common-3.2</Name> 119 131 </ProjectReference> 120 132 <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj"> -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/IAntTrailVisualizer.cs
r3223 r3238 23 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 24 using HeuristicLab.Optimization; 25 using HeuristicLab.Core; 25 26 26 27 namespace HeuristicLab.Problems.ArtificialAnt { 27 public interface IAntTrailVisualizer : ISolutionsVisualizer { 28 public interface IAntTrailVisualizer : ISolutionsVisualizer, ISingleObjectiveSolutionsVisualizer { 29 ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter { get; } 28 30 } 29 31 }
Note: See TracChangeset
for help on using the changeset viewer.