[3223] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3223] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[4068] | 24 | using System.Drawing;
|
---|
[3223] | 25 | using System.Linq;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[4068] | 29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[3223] | 30 | using HeuristicLab.Optimization;
|
---|
| 31 | using HeuristicLab.Parameters;
|
---|
| 32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 33 | using HeuristicLab.PluginInfrastructure;
|
---|
[3631] | 34 | using HeuristicLab.Problems.ArtificialAnt.Analyzers;
|
---|
[3223] | 35 |
|
---|
| 36 | namespace HeuristicLab.Problems.ArtificialAnt {
|
---|
[3528] | 37 | [Item("Artificial Ant Problem", "Represents the Artificial Ant problem.")]
|
---|
[3223] | 38 | [Creatable("Problems")]
|
---|
| 39 | [StorableClass]
|
---|
[5578] | 40 | public sealed class ArtificialAntProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
|
---|
[4419] | 41 | public string Filename { get; set; }
|
---|
[4098] | 42 |
|
---|
[3223] | 43 | public override Image ItemImage {
|
---|
[5287] | 44 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
|
---|
[3223] | 45 | }
|
---|
| 46 |
|
---|
[3239] | 47 | #region constant for default world (Santa Fe)
|
---|
| 48 | private readonly bool[,] santaFeAntTrail = new bool[,] {
|
---|
| 49 | {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},
|
---|
| 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, false, false, false, false, false, false, false, false},
|
---|
| 51 | {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},
|
---|
| 52 | {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},
|
---|
| 53 | {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},
|
---|
| 54 | {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},
|
---|
| 55 | {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},
|
---|
| 56 | {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},
|
---|
| 57 | {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},
|
---|
| 58 | {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},
|
---|
| 59 | {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},
|
---|
| 60 | {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},
|
---|
| 61 | {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},
|
---|
| 62 | {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},
|
---|
| 63 | {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},
|
---|
| 64 | {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},
|
---|
| 65 | {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},
|
---|
| 66 | {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},
|
---|
| 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, true, false, false, false, false, false, false, false},
|
---|
| 68 | {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},
|
---|
| 69 | {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},
|
---|
| 70 | {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},
|
---|
| 71 | {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},
|
---|
| 72 | {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},
|
---|
| 73 | {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},
|
---|
| 74 | {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},
|
---|
| 75 | {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},
|
---|
| 76 | {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},
|
---|
| 77 | {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},
|
---|
| 78 | {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},
|
---|
| 79 | {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 },
|
---|
| 80 | {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 }
|
---|
| 81 | };
|
---|
| 82 | #endregion
|
---|
| 83 |
|
---|
[3223] | 84 | #region Parameter Properties
|
---|
[5528] | 85 | public IValueParameter<BoolValue> MaximizationParameter {
|
---|
| 86 | get { return (IValueParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
[3223] | 87 | }
|
---|
[5578] | 88 | IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
|
---|
[3223] | 89 | get { return MaximizationParameter; }
|
---|
| 90 | }
|
---|
[5528] | 91 | public IValueParameter<ISymbolicExpressionTreeCreator> SolutionCreatorParameter {
|
---|
| 92 | get { return (IValueParameter<ISymbolicExpressionTreeCreator>)Parameters["SolutionCreator"]; }
|
---|
[3223] | 93 | }
|
---|
[5578] | 94 | IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {
|
---|
[3223] | 95 | get { return SolutionCreatorParameter; }
|
---|
| 96 | }
|
---|
[5528] | 97 | public IValueParameter<Evaluator> EvaluatorParameter {
|
---|
| 98 | get { return (IValueParameter<Evaluator>)Parameters["Evaluator"]; }
|
---|
[3223] | 99 | }
|
---|
[5578] | 100 | IParameter IHeuristicOptimizationProblem.EvaluatorParameter {
|
---|
[3223] | 101 | get { return EvaluatorParameter; }
|
---|
| 102 | }
|
---|
[5686] | 103 | public IValueParameter<ISymbolicExpressionGrammar> ArtificialAntExpressionGrammarParameter {
|
---|
| 104 | get { return (IValueParameter<ISymbolicExpressionGrammar>)Parameters["ArtificialAntExpressionGrammar"]; }
|
---|
[3223] | 105 | }
|
---|
[5528] | 106 | public IValueParameter<IntValue> MaxExpressionLengthParameter {
|
---|
[5712] | 107 | get { return (IValueParameter<IntValue>)Parameters["MaximumExpressionLength"]; }
|
---|
[3223] | 108 | }
|
---|
[5528] | 109 | public IValueParameter<IntValue> MaxExpressionDepthParameter {
|
---|
[5712] | 110 | get { return (IValueParameter<IntValue>)Parameters["MaximumExpressionDepth"]; }
|
---|
[3223] | 111 | }
|
---|
[5528] | 112 | public IValueParameter<IntValue> MaxFunctionDefinitionsParameter {
|
---|
[5712] | 113 | get { return (IValueParameter<IntValue>)Parameters["MaximumFunctionDefinitions"]; }
|
---|
[3294] | 114 | }
|
---|
[5528] | 115 | public IValueParameter<IntValue> MaxFunctionArgumentsParameter {
|
---|
[5712] | 116 | get { return (ValueParameter<IntValue>)Parameters["MaximumFunctionArguments"]; }
|
---|
[3294] | 117 | }
|
---|
[5528] | 118 | public IValueParameter<BoolMatrix> WorldParameter {
|
---|
| 119 | get { return (IValueParameter<BoolMatrix>)Parameters["World"]; }
|
---|
[3239] | 120 | }
|
---|
[5528] | 121 | public IValueParameter<IntValue> MaxTimeStepsParameter {
|
---|
[5712] | 122 | get { return (IValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
|
---|
[3239] | 123 | }
|
---|
[3223] | 124 |
|
---|
[5528] | 125 | public IValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 126 | get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
[3223] | 127 | }
|
---|
[5578] | 128 | IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
|
---|
[3223] | 129 | get { return BestKnownQualityParameter; }
|
---|
| 130 | }
|
---|
| 131 | #endregion
|
---|
| 132 |
|
---|
| 133 | #region Properties
|
---|
[3239] | 134 | public BoolMatrix World {
|
---|
| 135 | get { return WorldParameter.Value; }
|
---|
| 136 | set { WorldParameter.Value = value; }
|
---|
| 137 | }
|
---|
| 138 | public IntValue MaxTimeSteps {
|
---|
| 139 | get { return MaxTimeStepsParameter.Value; }
|
---|
| 140 | set { MaxTimeStepsParameter.Value = value; }
|
---|
| 141 | }
|
---|
| 142 | public IntValue MaxExpressionLength {
|
---|
| 143 | get { return MaxExpressionLengthParameter.Value; }
|
---|
| 144 | set { MaxExpressionLengthParameter.Value = value; }
|
---|
| 145 | }
|
---|
| 146 | public IntValue MaxExpressionDepth {
|
---|
| 147 | get { return MaxExpressionDepthParameter.Value; }
|
---|
| 148 | set { MaxExpressionDepthParameter.Value = value; }
|
---|
| 149 | }
|
---|
[3338] | 150 | public IntValue MaxFunctionDefinitions {
|
---|
| 151 | get { return MaxFunctionDefinitionsParameter.Value; }
|
---|
| 152 | set { MaxFunctionDefinitionsParameter.Value = value; }
|
---|
| 153 | }
|
---|
| 154 | public IntValue MaxFunctionArguments {
|
---|
| 155 | get { return MaxFunctionArgumentsParameter.Value; }
|
---|
| 156 | set { MaxFunctionArgumentsParameter.Value = value; }
|
---|
| 157 | }
|
---|
[5528] | 158 | public ISymbolicExpressionTreeCreator SolutionCreator {
|
---|
[3223] | 159 | get { return SolutionCreatorParameter.Value; }
|
---|
| 160 | set { SolutionCreatorParameter.Value = value; }
|
---|
| 161 | }
|
---|
[5578] | 162 | ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {
|
---|
[3223] | 163 | get { return SolutionCreatorParameter.Value; }
|
---|
| 164 | }
|
---|
| 165 | public Evaluator Evaluator {
|
---|
| 166 | get { return EvaluatorParameter.Value; }
|
---|
| 167 | set { EvaluatorParameter.Value = value; }
|
---|
| 168 | }
|
---|
[5578] | 169 | ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
|
---|
[3223] | 170 | get { return EvaluatorParameter.Value; }
|
---|
| 171 | }
|
---|
[5578] | 172 | IEvaluator IHeuristicOptimizationProblem.Evaluator {
|
---|
[3223] | 173 | get { return EvaluatorParameter.Value; }
|
---|
| 174 | }
|
---|
[5686] | 175 | public ArtificialAntExpressionGrammar ArtificialAntExpressionGrammar {
|
---|
| 176 | get { return (ArtificialAntExpressionGrammar)ArtificialAntExpressionGrammarParameter.Value; }
|
---|
[3223] | 177 | }
|
---|
| 178 | public DoubleValue BestKnownQuality {
|
---|
| 179 | get { return BestKnownQualityParameter.Value; }
|
---|
| 180 | }
|
---|
| 181 | public IEnumerable<IOperator> Operators {
|
---|
[3631] | 182 | get { return operators; }
|
---|
[3223] | 183 | }
|
---|
[3631] | 184 |
|
---|
[3681] | 185 | public IEnumerable<IAntTrailAnalyzer> AntTrailAnalyzers {
|
---|
| 186 | get { return operators.OfType<IAntTrailAnalyzer>(); }
|
---|
[3631] | 187 | }
|
---|
[3223] | 188 | #endregion
|
---|
| 189 |
|
---|
[4098] | 190 | [Storable]
|
---|
| 191 | private List<IOperator> operators;
|
---|
| 192 |
|
---|
| 193 | [StorableConstructor]
|
---|
[4106] | 194 | private ArtificialAntProblem(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 195 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 196 | private void AfterDeserialization() {
|
---|
| 197 | AttachEventHandlers();
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | private ArtificialAntProblem(ArtificialAntProblem original, Cloner cloner)
|
---|
| 201 | : base(original, cloner) {
|
---|
| 202 | operators = original.operators.Select(x => cloner.Clone(x)).ToList();
|
---|
| 203 | AttachEventHandlers();
|
---|
| 204 | }
|
---|
| 205 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 206 | return new ArtificialAntProblem(this, cloner);
|
---|
| 207 | }
|
---|
[3223] | 208 | public ArtificialAntProblem()
|
---|
| 209 | : base() {
|
---|
[5521] | 210 | ProbabilisticTreeCreator creator = new ProbabilisticTreeCreator();
|
---|
[3223] | 211 | Evaluator evaluator = new Evaluator();
|
---|
[3239] | 212 | BoolMatrix world = new BoolMatrix(santaFeAntTrail);
|
---|
[3223] | 213 | Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true)));
|
---|
[5528] | 214 | Parameters.Add(new ValueParameter<ISymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator));
|
---|
[3223] | 215 | Parameters.Add(new ValueParameter<Evaluator>("Evaluator", "The operator which should be used to evaluate artificial ant solutions.", evaluator));
|
---|
[3251] | 216 | Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this artificial ant instance.", new DoubleValue(89)));
|
---|
[5712] | 217 | Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
|
---|
| 218 | Parameters.Add(new ValueParameter<IntValue>("MaximumExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
|
---|
| 219 | Parameters.Add(new ValueParameter<IntValue>("MaximumFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
|
---|
| 220 | Parameters.Add(new ValueParameter<IntValue>("MaximumFunctionArguments", "Maximal number of arguments of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
|
---|
[5686] | 221 | Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", new ArtificialAntExpressionGrammar()));
|
---|
[3239] | 222 | Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
|
---|
[5712] | 223 | Parameters.Add(new ValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
|
---|
[3223] | 224 |
|
---|
| 225 | creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
|
---|
[5521] | 226 | creator.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
|
---|
[3223] | 227 | evaluator.QualityParameter.ActualName = "FoodEaten";
|
---|
[4098] | 228 | InitializeOperators();
|
---|
| 229 | AttachEventHandlers();
|
---|
[3223] | 230 | }
|
---|
| 231 |
|
---|
| 232 | #region Events
|
---|
| 233 | public event EventHandler SolutionCreatorChanged;
|
---|
| 234 | private void OnSolutionCreatorChanged() {
|
---|
[3739] | 235 | EventHandler handler = SolutionCreatorChanged;
|
---|
| 236 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3223] | 237 | }
|
---|
| 238 | public event EventHandler EvaluatorChanged;
|
---|
| 239 | private void OnEvaluatorChanged() {
|
---|
[3739] | 240 | EventHandler handler = EvaluatorChanged;
|
---|
| 241 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3223] | 242 | }
|
---|
| 243 | public event EventHandler OperatorsChanged;
|
---|
| 244 | private void OnOperatorsChanged() {
|
---|
[3739] | 245 | EventHandler handler = OperatorsChanged;
|
---|
| 246 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3223] | 247 | }
|
---|
[3739] | 248 | public event EventHandler Reset;
|
---|
| 249 | private void OnReset() {
|
---|
| 250 | EventHandler handler = Reset;
|
---|
| 251 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 252 | }
|
---|
[3223] | 253 |
|
---|
| 254 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5528] | 255 | SolutionCreator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
|
---|
| 256 | var grammarBased = SolutionCreator as ISymbolicExpressionTreeGrammarBasedOperator;
|
---|
| 257 | if (grammarBased != null)
|
---|
| 258 | grammarBased.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
|
---|
| 259 |
|
---|
[3223] | 260 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
[3631] | 261 | ParameterizeAnalyzers();
|
---|
[3223] | 262 | ParameterizeOperators();
|
---|
| 263 | OnSolutionCreatorChanged();
|
---|
| 264 | }
|
---|
| 265 | private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3631] | 266 | ParameterizeAnalyzers();
|
---|
[3223] | 267 | ParameterizeOperators();
|
---|
| 268 | }
|
---|
| 269 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5528] | 270 | Evaluator.QualityParameter.ActualName = "FoodEaten";
|
---|
[3239] | 271 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3631] | 272 | ParameterizeAnalyzers();
|
---|
[5517] | 273 | ParameterizeOperators();
|
---|
[3223] | 274 | OnEvaluatorChanged();
|
---|
| 275 | }
|
---|
[3239] | 276 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3631] | 277 | ParameterizeAnalyzers();
|
---|
[5517] | 278 | ParameterizeOperators();
|
---|
[3239] | 279 | }
|
---|
[3223] | 280 | #endregion
|
---|
| 281 |
|
---|
| 282 | #region Helpers
|
---|
[4098] | 283 | private void AttachEventHandlers() {
|
---|
[3223] | 284 | SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
|
---|
| 285 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 286 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
[3239] | 287 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3338] | 288 | MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(MaxFunctionArgumentsParameter_ValueChanged);
|
---|
| 289 | MaxFunctionArguments.ValueChanged += new EventHandler(MaxFunctionArgumentsParameter_ValueChanged);
|
---|
| 290 | MaxFunctionDefinitionsParameter.ValueChanged += new EventHandler(MaxFunctionDefinitionsParameter_ValueChanged);
|
---|
| 291 | MaxFunctionDefinitions.ValueChanged += new EventHandler(MaxFunctionDefinitionsParameter_ValueChanged);
|
---|
[3223] | 292 | }
|
---|
[3239] | 293 |
|
---|
[5517] | 294 | private void MaxFunctionDefinitionsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5686] | 295 | ArtificialAntExpressionGrammar.MaximumFunctionDefinitions = MaxFunctionDefinitions.Value;
|
---|
[5521] | 296 | ParameterizeOperators();
|
---|
| 297 | ParameterizeAnalyzers();
|
---|
[3338] | 298 | }
|
---|
[5517] | 299 | private void MaxFunctionArgumentsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5686] | 300 | ArtificialAntExpressionGrammar.MaximumFunctionArguments = MaxFunctionArguments.Value;
|
---|
[5521] | 301 | ParameterizeOperators();
|
---|
| 302 | ParameterizeAnalyzers();
|
---|
[3338] | 303 | }
|
---|
| 304 |
|
---|
[3239] | 305 | private void InitializeOperators() {
|
---|
[3631] | 306 | operators = new List<IOperator>();
|
---|
| 307 | operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
|
---|
[3681] | 308 | operators.Add(new BestAntTrailAnalyzer());
|
---|
[5499] | 309 | operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
|
---|
[5395] | 310 | operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
|
---|
[3631] | 311 | ParameterizeAnalyzers();
|
---|
[3239] | 312 | ParameterizeOperators();
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[3631] | 315 | private void ParameterizeAnalyzers() {
|
---|
[3681] | 316 | foreach (IAntTrailAnalyzer analyzer in AntTrailAnalyzers) {
|
---|
[3631] | 317 | analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 318 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 319 | analyzer.WorldParameter.ActualName = WorldParameter.Name;
|
---|
| 320 | analyzer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
|
---|
| 321 | }
|
---|
[3681] | 322 | foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
|
---|
[3651] | 323 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 324 | }
|
---|
[3223] | 325 | }
|
---|
| 326 |
|
---|
| 327 | private void ParameterizeOperators() {
|
---|
[5528] | 328 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
[5521] | 329 |
|
---|
| 330 | foreach (ISymbolicExpressionTreeGrammarBasedOperator op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
|
---|
[5517] | 331 | op.SymbolicExpressionTreeGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
|
---|
[3223] | 332 | }
|
---|
[5521] | 333 | foreach (ISymbolicExpressionTreeSizeConstraintOperator op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
|
---|
[5517] | 334 | op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaxExpressionDepthParameter.Name;
|
---|
| 335 | op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaxExpressionLengthParameter.Name;
|
---|
| 336 |
|
---|
| 337 | }
|
---|
[5521] | 338 | foreach (Evaluator op in operators.OfType<Evaluator>()) {
|
---|
[3223] | 339 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3239] | 340 | op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
|
---|
| 341 | op.WorldParameter.ActualName = WorldParameter.Name;
|
---|
[3223] | 342 | }
|
---|
[5521] | 343 | foreach (ISymbolicExpressionTreeCrossover op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
|
---|
[3238] | 344 | op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 345 | op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 346 | }
|
---|
[5521] | 347 | foreach (ISymbolicExpressionTreeManipulator op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
|
---|
[3294] | 348 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 349 | }
|
---|
[5521] | 350 | foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
|
---|
[5517] | 351 | op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name;
|
---|
| 352 | op.MaximumFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
|
---|
[3294] | 353 | }
|
---|
[3223] | 354 | }
|
---|
| 355 | #endregion
|
---|
| 356 | }
|
---|
| 357 | }
|
---|