[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]
|
---|
[4419] | 40 | public sealed class ArtificialAntProblem : ParameterizedNamedItem, ISingleObjectiveProblem, IStorableContent {
|
---|
| 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 | }
|
---|
| 88 | IParameter ISingleObjectiveProblem.MaximizationParameter {
|
---|
| 89 | get { return MaximizationParameter; }
|
---|
| 90 | }
|
---|
[5528] | 91 | public IValueParameter<ISymbolicExpressionTreeCreator> SolutionCreatorParameter {
|
---|
| 92 | get { return (IValueParameter<ISymbolicExpressionTreeCreator>)Parameters["SolutionCreator"]; }
|
---|
[3223] | 93 | }
|
---|
| 94 | IParameter IProblem.SolutionCreatorParameter {
|
---|
| 95 | get { return SolutionCreatorParameter; }
|
---|
| 96 | }
|
---|
[5528] | 97 | public IValueParameter<Evaluator> EvaluatorParameter {
|
---|
| 98 | get { return (IValueParameter<Evaluator>)Parameters["Evaluator"]; }
|
---|
[3223] | 99 | }
|
---|
| 100 | IParameter IProblem.EvaluatorParameter {
|
---|
| 101 | get { return EvaluatorParameter; }
|
---|
| 102 | }
|
---|
[5528] | 103 | public IValueParameter<ISymbolicExpressionTreeGrammar> ArtificialAntExpressionGrammarParameter {
|
---|
| 104 | get { return (IValueParameter<ISymbolicExpressionTreeGrammar>)Parameters["ArtificialAntExpressionGrammar"]; }
|
---|
[3223] | 105 | }
|
---|
[5528] | 106 | public IValueParameter<IntValue> MaxExpressionLengthParameter {
|
---|
| 107 | get { return (IValueParameter<IntValue>)Parameters["MaxExpressionLength"]; }
|
---|
[3223] | 108 | }
|
---|
[5528] | 109 | public IValueParameter<IntValue> MaxExpressionDepthParameter {
|
---|
| 110 | get { return (IValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }
|
---|
[3223] | 111 | }
|
---|
[5528] | 112 | public IValueParameter<IntValue> MaxFunctionDefinitionsParameter {
|
---|
| 113 | get { return (IValueParameter<IntValue>)Parameters["MaxFunctionDefinitions"]; }
|
---|
[3294] | 114 | }
|
---|
[5528] | 115 | public IValueParameter<IntValue> MaxFunctionArgumentsParameter {
|
---|
[3294] | 116 | get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; }
|
---|
| 117 | }
|
---|
[5528] | 118 | public IValueParameter<BoolMatrix> WorldParameter {
|
---|
| 119 | get { return (IValueParameter<BoolMatrix>)Parameters["World"]; }
|
---|
[3239] | 120 | }
|
---|
[5528] | 121 | public IValueParameter<IntValue> MaxTimeStepsParameter {
|
---|
| 122 | get { return (IValueParameter<IntValue>)Parameters["MaxTimeSteps"]; }
|
---|
[3239] | 123 | }
|
---|
[3223] | 124 |
|
---|
[5528] | 125 | public IValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 126 | get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
[3223] | 127 | }
|
---|
| 128 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
| 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 | }
|
---|
| 162 | ISolutionCreator IProblem.SolutionCreator {
|
---|
| 163 | get { return SolutionCreatorParameter.Value; }
|
---|
| 164 | }
|
---|
| 165 | public Evaluator Evaluator {
|
---|
| 166 | get { return EvaluatorParameter.Value; }
|
---|
| 167 | set { EvaluatorParameter.Value = value; }
|
---|
| 168 | }
|
---|
| 169 | ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
|
---|
| 170 | get { return EvaluatorParameter.Value; }
|
---|
| 171 | }
|
---|
| 172 | IEvaluator IProblem.Evaluator {
|
---|
| 173 | get { return EvaluatorParameter.Value; }
|
---|
| 174 | }
|
---|
[3338] | 175 | public GlobalSymbolicExpressionGrammar ArtificialAntExpressionGrammar {
|
---|
| 176 | get { return (GlobalSymbolicExpressionGrammar)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);
|
---|
[5517] | 213 | ISymbolicExpressionTreeGrammar grammar = new GlobalSymbolicExpressionGrammar(new ArtificialAntExpressionGrammar());
|
---|
[3223] | 214 | Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true)));
|
---|
[5528] | 215 | Parameters.Add(new ValueParameter<ISymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator));
|
---|
[3223] | 216 | Parameters.Add(new ValueParameter<Evaluator>("Evaluator", "The operator which should be used to evaluate artificial ant solutions.", evaluator));
|
---|
[3251] | 217 | Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this artificial ant instance.", new DoubleValue(89)));
|
---|
[3223] | 218 | Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
|
---|
| 219 | Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
|
---|
[3294] | 220 | Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefinitions", "Maximal number of automatically defined functions in the expression to control the artificial ant.", new IntValue(3)));
|
---|
| 221 | 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)));
|
---|
[5517] | 222 | Parameters.Add(new ValueParameter<ISymbolicExpressionTreeGrammar>("ArtificialAntExpressionGrammar", "The grammar that should be used for artificial ant expressions.", grammar));
|
---|
[3239] | 223 | Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
|
---|
| 224 | Parameters.Add(new ValueParameter<IntValue>("MaxTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
|
---|
[3223] | 225 |
|
---|
| 226 | creator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
|
---|
[5521] | 227 | creator.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
|
---|
[3223] | 228 | evaluator.QualityParameter.ActualName = "FoodEaten";
|
---|
[4098] | 229 | InitializeOperators();
|
---|
| 230 | AttachEventHandlers();
|
---|
[3223] | 231 | }
|
---|
| 232 |
|
---|
| 233 | #region Events
|
---|
| 234 | public event EventHandler SolutionCreatorChanged;
|
---|
| 235 | private void OnSolutionCreatorChanged() {
|
---|
[3739] | 236 | EventHandler handler = SolutionCreatorChanged;
|
---|
| 237 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3223] | 238 | }
|
---|
| 239 | public event EventHandler EvaluatorChanged;
|
---|
| 240 | private void OnEvaluatorChanged() {
|
---|
[3739] | 241 | EventHandler handler = EvaluatorChanged;
|
---|
| 242 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3223] | 243 | }
|
---|
| 244 | public event EventHandler OperatorsChanged;
|
---|
| 245 | private void OnOperatorsChanged() {
|
---|
[3739] | 246 | EventHandler handler = OperatorsChanged;
|
---|
| 247 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
[3223] | 248 | }
|
---|
[3739] | 249 | public event EventHandler Reset;
|
---|
| 250 | private void OnReset() {
|
---|
| 251 | EventHandler handler = Reset;
|
---|
| 252 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 253 | }
|
---|
[3223] | 254 |
|
---|
| 255 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5528] | 256 | SolutionCreator.SymbolicExpressionTreeParameter.ActualName = "AntTrailSolution";
|
---|
| 257 | var grammarBased = SolutionCreator as ISymbolicExpressionTreeGrammarBasedOperator;
|
---|
| 258 | if (grammarBased != null)
|
---|
| 259 | grammarBased.SymbolicExpressionTreeGrammarParameter.ActualName = "ArtificialAntExpressionGrammar";
|
---|
| 260 |
|
---|
[3223] | 261 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
[3631] | 262 | ParameterizeAnalyzers();
|
---|
[3223] | 263 | ParameterizeOperators();
|
---|
| 264 | OnSolutionCreatorChanged();
|
---|
| 265 | }
|
---|
| 266 | private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3631] | 267 | ParameterizeAnalyzers();
|
---|
[3223] | 268 | ParameterizeOperators();
|
---|
| 269 | }
|
---|
| 270 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[5528] | 271 | Evaluator.QualityParameter.ActualName = "FoodEaten";
|
---|
[3239] | 272 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3631] | 273 | ParameterizeAnalyzers();
|
---|
[5517] | 274 | ParameterizeOperators();
|
---|
[3223] | 275 | OnEvaluatorChanged();
|
---|
| 276 | }
|
---|
[3239] | 277 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
[3631] | 278 | ParameterizeAnalyzers();
|
---|
[5517] | 279 | ParameterizeOperators();
|
---|
[3239] | 280 | }
|
---|
[3223] | 281 | #endregion
|
---|
| 282 |
|
---|
| 283 | #region Helpers
|
---|
[4098] | 284 | private void AttachEventHandlers() {
|
---|
[3223] | 285 | SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
|
---|
| 286 | SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
|
---|
| 287 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
[3239] | 288 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[3338] | 289 | MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(MaxFunctionArgumentsParameter_ValueChanged);
|
---|
| 290 | MaxFunctionArguments.ValueChanged += new EventHandler(MaxFunctionArgumentsParameter_ValueChanged);
|
---|
| 291 | MaxFunctionDefinitionsParameter.ValueChanged += new EventHandler(MaxFunctionDefinitionsParameter_ValueChanged);
|
---|
| 292 | MaxFunctionDefinitions.ValueChanged += new EventHandler(MaxFunctionDefinitionsParameter_ValueChanged);
|
---|
[3223] | 293 | }
|
---|
[3239] | 294 |
|
---|
[5517] | 295 | private void MaxFunctionDefinitionsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3338] | 296 | ArtificialAntExpressionGrammar.MaxFunctionDefinitions = MaxFunctionDefinitions.Value;
|
---|
[5521] | 297 | ParameterizeOperators();
|
---|
| 298 | ParameterizeAnalyzers();
|
---|
[3338] | 299 | }
|
---|
[5517] | 300 | private void MaxFunctionArgumentsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[3338] | 301 | ArtificialAntExpressionGrammar.MaxFunctionArguments = MaxFunctionArguments.Value;
|
---|
[5521] | 302 | ParameterizeOperators();
|
---|
| 303 | ParameterizeAnalyzers();
|
---|
[3338] | 304 | }
|
---|
| 305 |
|
---|
[3239] | 306 | private void InitializeOperators() {
|
---|
[3631] | 307 | operators = new List<IOperator>();
|
---|
| 308 | operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>());
|
---|
[3681] | 309 | operators.Add(new BestAntTrailAnalyzer());
|
---|
[5499] | 310 | operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer());
|
---|
[5395] | 311 | operators.Add(new SymbolicExpressionSymbolFrequencyAnalyzer());
|
---|
[3631] | 312 | ParameterizeAnalyzers();
|
---|
[3239] | 313 | ParameterizeOperators();
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[3631] | 316 | private void ParameterizeAnalyzers() {
|
---|
[3681] | 317 | foreach (IAntTrailAnalyzer analyzer in AntTrailAnalyzers) {
|
---|
[3631] | 318 | analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 319 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 320 | analyzer.WorldParameter.ActualName = WorldParameter.Name;
|
---|
| 321 | analyzer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
|
---|
| 322 | }
|
---|
[3681] | 323 | foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
|
---|
[3651] | 324 | analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 325 | }
|
---|
[3223] | 326 | }
|
---|
| 327 |
|
---|
| 328 | private void ParameterizeOperators() {
|
---|
[5528] | 329 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
[5521] | 330 |
|
---|
| 331 | foreach (ISymbolicExpressionTreeGrammarBasedOperator op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
|
---|
[5517] | 332 | op.SymbolicExpressionTreeGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
|
---|
[3223] | 333 | }
|
---|
[5521] | 334 | foreach (ISymbolicExpressionTreeSizeConstraintOperator op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
|
---|
[5517] | 335 | op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaxExpressionDepthParameter.Name;
|
---|
| 336 | op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaxExpressionLengthParameter.Name;
|
---|
| 337 |
|
---|
| 338 | }
|
---|
[5521] | 339 | foreach (Evaluator op in operators.OfType<Evaluator>()) {
|
---|
[3223] | 340 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
[3239] | 341 | op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
|
---|
| 342 | op.WorldParameter.ActualName = WorldParameter.Name;
|
---|
[3223] | 343 | }
|
---|
[5521] | 344 | foreach (ISymbolicExpressionTreeCrossover op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
|
---|
[3238] | 345 | op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 346 | op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 347 | }
|
---|
[5521] | 348 | foreach (ISymbolicExpressionTreeManipulator op in operators.OfType<ISymbolicExpressionTreeManipulator>()) {
|
---|
[3294] | 349 | op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
| 350 | }
|
---|
[5521] | 351 | foreach (ISymbolicExpressionTreeArchitectureAlteringOperator op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
|
---|
[5517] | 352 | op.MaximumFunctionDefinitionsParameter.ActualName = MaxFunctionDefinitionsParameter.Name;
|
---|
| 353 | op.MaximumFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;
|
---|
[3294] | 354 | }
|
---|
[3223] | 355 | }
|
---|
| 356 | #endregion
|
---|
| 357 | }
|
---|
| 358 | }
|
---|