- Timestamp:
- 03/31/10 14:26:45 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs
r3238 r3239 42 42 } 43 43 44 #region constant for default world (Santa Fe) 45 private readonly bool[,] santaFeAntTrail = new bool[,] { 46 {false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 47 {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 48 {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, false, false, false, false}, 49 {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false}, 50 {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false}, 51 {false, false, false, true, true, true, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false}, 52 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false}, 53 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 54 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 55 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, true, false, false}, 56 {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 57 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 58 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false}, 59 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false}, 60 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, true, true, true, false, false, false}, 61 {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false}, 62 {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 63 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 64 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false}, 65 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false}, 66 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 67 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 68 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false}, 69 {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false}, 70 {false, false, false, true, true, false, false, true, true, true, true, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 71 {false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 72 {false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 73 {false, true, false, false, false, false, false, false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 74 {false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 75 {false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}, 76 {false, false, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }, 77 {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false } 78 }; 79 #endregion 80 44 81 #region Parameter Properties 45 82 public ValueParameter<BoolValue> MaximizationParameter { … … 70 107 get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; } 71 108 } 109 public ValueParameter<BoolMatrix> WorldParameter { 110 get { return (ValueParameter<BoolMatrix>)Parameters["World"]; } 111 } 112 public ValueParameter<IntValue> MaxTimeStepsParameter { 113 get { return (ValueParameter<IntValue>)Parameters["MaxTimeSteps"]; } 114 } 72 115 73 116 public OptionalValueParameter<IAntTrailVisualizer> VisualizerParameter { … … 86 129 87 130 #region Properties 131 public BoolMatrix World { 132 get { return WorldParameter.Value; } 133 set { WorldParameter.Value = value; } 134 } 135 public IntValue MaxTimeSteps { 136 get { return MaxTimeStepsParameter.Value; } 137 set { MaxTimeStepsParameter.Value = value; } 138 } 139 public IntValue MaxExpressionLength { 140 get { return MaxExpressionLengthParameter.Value; } 141 set { MaxExpressionLengthParameter.Value = value; } 142 } 143 public IntValue MaxExpressionDepth { 144 get { return MaxExpressionDepthParameter.Value; } 145 set { MaxExpressionDepthParameter.Value = value; } 146 } 88 147 public SymbolicExpressionTreeCreator SolutionCreator { 89 148 get { return SolutionCreatorParameter.Value; } … … 116 175 get { return BestKnownQualityParameter.Value; } 117 176 } 118 private List<I Operator> operators;177 private List<ISymbolicExpressionTreeOperator> operators; 119 178 public IEnumerable<IOperator> Operators { 120 get { return operators ; }179 get { return operators.Cast<IOperator>(); } 121 180 } 122 181 #endregion … … 128 187 ArtificialAntExpressionGrammar grammar = new ArtificialAntExpressionGrammar(); 129 188 BestAntTrailVisualizer visualizer = new BestAntTrailVisualizer(); 130 189 BoolMatrix world = new BoolMatrix(santaFeAntTrail); 131 190 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true))); 132 191 Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator)); … … 136 195 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100))); 137 196 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10))); 197 Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world)); 198 Parameters.Add(new ValueParameter<IntValue>("MaxTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600))); 138 199 Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", visualizer)); 139 200 … … 159 220 public event EventHandler SolutionCreatorChanged; 160 221 private void OnSolutionCreatorChanged() { 161 if (SolutionCreatorChanged != null) 162 SolutionCreatorChanged(this, EventArgs.Empty); 222 var changed = SolutionCreatorChanged; 223 if (changed != null) 224 changed(this, EventArgs.Empty); 163 225 } 164 226 public event EventHandler EvaluatorChanged; 165 227 private void OnEvaluatorChanged() { 166 if (EvaluatorChanged != null) 167 EvaluatorChanged(this, EventArgs.Empty); 228 var changed = EvaluatorChanged; 229 if (changed != null) 230 changed(this, EventArgs.Empty); 168 231 } 169 232 public event EventHandler VisualizerChanged; 170 233 private void OnVisualizerChanged() { 171 if (VisualizerChanged != null) 172 VisualizerChanged(this, EventArgs.Empty); 234 var changed = VisualizerChanged; 235 if (changed != null) 236 changed(this, EventArgs.Empty); 173 237 } 174 238 175 239 public event EventHandler OperatorsChanged; 176 240 private void OnOperatorsChanged() { 177 if (OperatorsChanged != null) 178 OperatorsChanged(this, EventArgs.Empty); 241 var changed = OperatorsChanged; 242 if (changed != null) 243 changed(this, EventArgs.Empty); 179 244 } 180 245 … … 183 248 ParameterizeSolutionCreator(); 184 249 ParameterizeEvaluator(); 250 ParameterizeVisualizer(); 185 251 ParameterizeOperators(); 186 252 OnSolutionCreatorChanged(); … … 188 254 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 189 255 ParameterizeEvaluator(); 256 ParameterizeVisualizer(); 190 257 ParameterizeOperators(); 191 258 } 192 259 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 260 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 193 261 ParameterizeEvaluator(); 262 ParameterizeVisualizer(); 194 263 OnEvaluatorChanged(); 195 264 } 265 266 private void VisualizerParameter_ValueChanged(object sender, EventArgs e) { 267 ParameterizeVisualizer(); 268 OnVisualizerChanged(); 269 } 270 271 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 272 ParameterizeVisualizer(); 273 } 274 196 275 #endregion 197 276 … … 203 282 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged); 204 283 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 205 } 284 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 285 VisualizerParameter.ValueChanged += new EventHandler(VisualizerParameter_ValueChanged); 286 } 287 288 private void InitializeOperators() { 289 operators = new List<ISymbolicExpressionTreeOperator>(); 290 operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>()); 291 ParameterizeOperators(); 292 } 293 206 294 private void ParameterizeSolutionCreator() { 207 295 SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name; 296 SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name; 297 SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name; 208 298 } 209 299 private void ParameterizeEvaluator() { 210 300 Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 211 } 212 private void InitializeOperators() { 213 operators = new List<IOperator>(); 214 operators.Add(Evaluator); 215 operators.Add(SolutionCreator); 216 operators.Add(new SubtreeCrossover()); 217 ParameterizeOperators(); 301 Evaluator.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name; 302 Evaluator.WorldParameter.ActualName = WorldParameter.Name; 303 } 304 private void ParameterizeVisualizer() { 305 if (Visualizer != null) { 306 Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 307 var antTrailVisualizer = Visualizer as IAntTrailVisualizer; 308 if (antTrailVisualizer != null) { 309 antTrailVisualizer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 310 antTrailVisualizer.WorldParameter.ActualName = WorldParameter.Name; 311 antTrailVisualizer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name; 312 } 313 } 218 314 } 219 315 220 316 private void ParameterizeOperators() { 221 foreach ( ProbabilisticTreeCreator op in Operators.OfType<ProbabilisticTreeCreator>()) {317 foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) { 222 318 op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name; 223 319 op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name; … … 226 322 foreach (Evaluator op in Operators.OfType<Evaluator>()) { 227 323 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 324 op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name; 325 op.WorldParameter.ActualName = WorldParameter.Name; 228 326 } 229 327 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 328 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 234 329 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 235 330 } 236 331 } 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 } 332 244 333 245 334 #endregion
Note: See TracChangeset
for help on using the changeset viewer.