1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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;
|
---|
24 | using System.Linq;
|
---|
25 | //using HeuristicLab.Analysis;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 | //using HeuristicLab.Optimization.Operators;
|
---|
32 | using HeuristicLab.Parameters;
|
---|
33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
34 | using HeuristicLab.PluginInfrastructure;
|
---|
35 | //using HeuristicLab.Problems.Instances;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Problems.MovingPeaksBenchmark {
|
---|
38 | [Item("Moving Peaks Benchmark", "Moving peaks benchmark problem for dynamic optimization.")]
|
---|
39 | [StorableClass]
|
---|
40 | [Creatable(CreatableAttribute.Categories.Problems, Priority = 97)]
|
---|
41 | public sealed class MovingPeaksBenchmarkProblem : SingleObjectiveHeuristicOptimizationProblem<IMovingPeaksBenchmarkProblemEvaluator, IRealVectorCreator>, IStorableContent {
|
---|
42 | public string Filename { get; set; }
|
---|
43 |
|
---|
44 | //[Storable]
|
---|
45 | //private StdDevStrategyVectorCreator strategyVectorCreator;
|
---|
46 | //[Storable]
|
---|
47 | //private StdDevStrategyVectorCrossover strategyVectorCrossover;
|
---|
48 | //[Storable]
|
---|
49 | //private StdDevStrategyVectorManipulator strategyVectorManipulator;
|
---|
50 |
|
---|
51 | #region Parameter Properties
|
---|
52 | public ValueParameter<DoubleMatrix> BoundsParameter {
|
---|
53 | get { return (ValueParameter<DoubleMatrix>)Parameters["Bounds"]; }
|
---|
54 | }
|
---|
55 | public ValueParameter<IntValue> ProblemSizeParameter {
|
---|
56 | get { return (ValueParameter<IntValue>)Parameters["ProblemSize"]; }
|
---|
57 | }
|
---|
58 | public ValueParameter<IntValue> PeaksParameter {
|
---|
59 | get { return (ValueParameter<IntValue>)Parameters["Peaks"]; }
|
---|
60 | }
|
---|
61 | public ValueParameter<DoubleMatrix> InitialPeakLocationsParameter {
|
---|
62 | get { return (ValueParameter<DoubleMatrix>)Parameters["InitialPeakLocations"]; }
|
---|
63 | }
|
---|
64 | public ValueParameter<DoubleArray> InitialPeakWidthsParameter {
|
---|
65 | get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakWidths"]; }
|
---|
66 | }
|
---|
67 | public ValueParameter<DoubleArray> InitialPeakHeightsParameter {
|
---|
68 | get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakHeights"]; }
|
---|
69 | }
|
---|
70 | public FixedValueParameter<IntValue> MovingPeaksRandomSeedParameter {
|
---|
71 | get { return (FixedValueParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; }
|
---|
72 | }
|
---|
73 | public FixedValueParameter<DoubleValue> MinPeakWidthParameter {
|
---|
74 | get { return (FixedValueParameter<DoubleValue>)Parameters["MinPeakWidth"]; }
|
---|
75 | }
|
---|
76 | public FixedValueParameter<DoubleValue> MaxPeakWidthParameter {
|
---|
77 | get { return (FixedValueParameter<DoubleValue>)Parameters["MaxPeakWidth"]; }
|
---|
78 | }
|
---|
79 | public FixedValueParameter<DoubleValue> MinPeakHeightParameter {
|
---|
80 | get { return (FixedValueParameter<DoubleValue>)Parameters["MinPeakHeight"]; }
|
---|
81 | }
|
---|
82 | public FixedValueParameter<DoubleValue> MaxPeakHeightParameter {
|
---|
83 | get { return (FixedValueParameter<DoubleValue>)Parameters["MaxPeakHeight"]; }
|
---|
84 | }
|
---|
85 | public FixedValueParameter<IntValue> PeakMovementIntervalParameter {
|
---|
86 | get { return (FixedValueParameter<IntValue>)Parameters["PeakMovementInterval"]; }
|
---|
87 | }
|
---|
88 | public FixedValueParameter<DoubleValue> PeakMovementStrengthParameter {
|
---|
89 | get { return (FixedValueParameter<DoubleValue>)Parameters["PeakMovementStrength"]; }
|
---|
90 | }
|
---|
91 | public OptionalValueParameter<RealVector> BestKnownSolutionParameter {
|
---|
92 | get { return (OptionalValueParameter<RealVector>)Parameters["BestKnownSolution"]; }
|
---|
93 | }
|
---|
94 | #endregion
|
---|
95 |
|
---|
96 | #region Properties
|
---|
97 | public DoubleMatrix Bounds {
|
---|
98 | get { return BoundsParameter.Value; }
|
---|
99 | set { BoundsParameter.Value = value; }
|
---|
100 | }
|
---|
101 | public IntValue ProblemSize {
|
---|
102 | get { return ProblemSizeParameter.Value; }
|
---|
103 | set { ProblemSizeParameter.Value = value; }
|
---|
104 | }
|
---|
105 | public IntValue Peaks {
|
---|
106 | get { return PeaksParameter.Value; }
|
---|
107 | set { PeaksParameter.Value = value; }
|
---|
108 | }
|
---|
109 | public DoubleMatrix InitialPeakLocations {
|
---|
110 | get { return InitialPeakLocationsParameter.Value; }
|
---|
111 | set { InitialPeakLocationsParameter.Value = value; }
|
---|
112 | }
|
---|
113 | public DoubleArray InitialPeakWidths {
|
---|
114 | get { return InitialPeakWidthsParameter.Value; }
|
---|
115 | set { InitialPeakWidthsParameter.Value = value; }
|
---|
116 | }
|
---|
117 | public DoubleArray InitialPeakHeights {
|
---|
118 | get { return InitialPeakHeightsParameter.Value; }
|
---|
119 | set { InitialPeakHeightsParameter.Value = value; }
|
---|
120 | }
|
---|
121 | public IntValue MovingPeaksRandomSeed {
|
---|
122 | get { return MovingPeaksRandomSeedParameter.Value; }
|
---|
123 | }
|
---|
124 | public DoubleValue MinPeakWidth {
|
---|
125 | get { return MinPeakWidthParameter.Value; }
|
---|
126 | }
|
---|
127 | public DoubleValue MaxPeakWidth {
|
---|
128 | get { return MaxPeakWidthParameter.Value; }
|
---|
129 | }
|
---|
130 | public DoubleValue MinPeakHeight {
|
---|
131 | get { return MinPeakHeightParameter.Value; }
|
---|
132 | }
|
---|
133 | public DoubleValue MaxPeakHeight {
|
---|
134 | get { return MaxPeakHeightParameter.Value; }
|
---|
135 | }
|
---|
136 | public IntValue PeakMovementInterval {
|
---|
137 | get { return PeakMovementIntervalParameter.Value; }
|
---|
138 | }
|
---|
139 | public DoubleValue PeakMovementStrength {
|
---|
140 | get { return PeakMovementStrengthParameter.Value; }
|
---|
141 | }
|
---|
142 | private BestMovingPeaksBenchmarkSolutionAnalyzer BestMovingPeaksBenchmarkSolutionAnalyzer {
|
---|
143 | get { return Operators.OfType<BestMovingPeaksBenchmarkSolutionAnalyzer>().FirstOrDefault(); }
|
---|
144 | }
|
---|
145 | #endregion
|
---|
146 |
|
---|
147 | [StorableConstructor]
|
---|
148 | private MovingPeaksBenchmarkProblem(bool deserializing) : base(deserializing) { }
|
---|
149 | private MovingPeaksBenchmarkProblem(MovingPeaksBenchmarkProblem original, Cloner cloner)
|
---|
150 | : base(original, cloner) {
|
---|
151 | //strategyVectorCreator = cloner.Clone(original.strategyVectorCreator);
|
---|
152 | //strategyVectorCrossover = cloner.Clone(original.strategyVectorCrossover);
|
---|
153 | //strategyVectorManipulator = cloner.Clone(original.strategyVectorManipulator);
|
---|
154 | RegisterEventHandlers();
|
---|
155 | }
|
---|
156 | public MovingPeaksBenchmarkProblem()
|
---|
157 | : base(new MovingPeaksBenchmarkProblemEvaluator(), new UniformRandomRealVectorCreator()) {
|
---|
158 | var defaultBounds = new double[,] {
|
---|
159 | { 0.0, 100.0 }
|
---|
160 | };
|
---|
161 | var defaultPeaks = new double[,] {
|
---|
162 | { 08.0, 64.0, 67.0, 55.0, 04.0 },
|
---|
163 | { 50.0, 13.0, 76.0, 15.0, 07.0 },
|
---|
164 | { 09.0, 19.0, 27.0, 67.0, 24.0 },
|
---|
165 | { 66.0, 87.0, 65.0, 19.0, 43.0 },
|
---|
166 | { 76.0, 32.0, 43.0, 54.0, 65.0 },
|
---|
167 | { 25.0, 51.0, 17.0, 25.0, 16.0 },
|
---|
168 | { 19.0, 93.0, 06.0, 35.0, 15.0 },
|
---|
169 | { 88.0, 44.0, 37.0, 77.0, 74.0 },
|
---|
170 | { 37.0, 74.0, 55.0, 09.0, 53.0 },
|
---|
171 | { 42.0, 22.0, 93.0, 84.0, 35.0 }
|
---|
172 | };
|
---|
173 | var defaultWidths = new double[] { -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 };
|
---|
174 | var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0 };
|
---|
175 | var defaultBestKnown = new double[] { 08.0, 64.0, 67.0, 55.0, 04.0 };
|
---|
176 |
|
---|
177 | Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds)));
|
---|
178 | Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(5)));
|
---|
179 | Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(10)));
|
---|
180 | Parameters.Add(new ValueParameter<DoubleMatrix>("InitialPeakLocations", "Initial coordinates of each peaks.", new DoubleMatrix(defaultPeaks)));
|
---|
181 | Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakWidths", "Initial width of each peak.", new DoubleArray(defaultWidths)));
|
---|
182 | Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakHeights", "Initial height of each peak.", new DoubleArray(defaultHeights)));
|
---|
183 | Parameters.Add(new FixedValueParameter<IntValue>("MovingPeaksRandomSeed", "The random seed for initializing the PRNG for changing the peaks.", new IntValue(666)));
|
---|
184 | Parameters.Add(new FixedValueParameter<DoubleValue>("MinPeakWidth", "The minimum width of each peak.", new DoubleValue(1.0)));
|
---|
185 | Parameters.Add(new FixedValueParameter<DoubleValue>("MaxPeakWidth", "The maximum width of each peak.", new DoubleValue(12.0)));
|
---|
186 | Parameters.Add(new FixedValueParameter<DoubleValue>("MinPeakHeight", "The minimum height of each peak.", new DoubleValue(30.0)));
|
---|
187 | Parameters.Add(new FixedValueParameter<DoubleValue>("MaxPeakHeight", "The maximum height of each peak.", new DoubleValue(70.0)));
|
---|
188 | Parameters.Add(new FixedValueParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.", new IntValue(5000)));
|
---|
189 | Parameters.Add(new FixedValueParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.", new DoubleValue(1.5)));
|
---|
190 | Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The location of the highest peak.", new RealVector(defaultBestKnown)));
|
---|
191 |
|
---|
192 | Maximization.Value = true;
|
---|
193 | BestKnownQuality = new DoubleValue(defaultHeights.Max());
|
---|
194 |
|
---|
195 | //strategyVectorCreator = new StdDevStrategyVectorCreator();
|
---|
196 | //strategyVectorCreator.LengthParameter.ActualName = ProblemSizeParameter.Name;
|
---|
197 | //strategyVectorCrossover = new StdDevStrategyVectorCrossover();
|
---|
198 | //strategyVectorManipulator = new StdDevStrategyVectorManipulator();
|
---|
199 | //strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(0.5);
|
---|
200 | //strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(0.5);
|
---|
201 |
|
---|
202 | SolutionCreator.RealVectorParameter.ActualName = "Point";
|
---|
203 | ParameterizeSolutionCreator();
|
---|
204 | ParameterizeEvaluator();
|
---|
205 |
|
---|
206 | InitializeOperators();
|
---|
207 | RegisterEventHandlers();
|
---|
208 | UpdateStrategyVectorBounds();
|
---|
209 | }
|
---|
210 |
|
---|
211 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
212 | return new MovingPeaksBenchmarkProblem(this, cloner);
|
---|
213 | }
|
---|
214 |
|
---|
215 | #region Events
|
---|
216 | protected override void OnSolutionCreatorChanged() {
|
---|
217 | base.OnSolutionCreatorChanged();
|
---|
218 | ParameterizeSolutionCreator();
|
---|
219 | ParameterizeAnalyzers();
|
---|
220 | SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged);
|
---|
221 | SolutionCreator_RealVectorParameter_ActualNameChanged(null, EventArgs.Empty);
|
---|
222 | }
|
---|
223 | protected override void OnEvaluatorChanged() {
|
---|
224 | base.OnEvaluatorChanged();
|
---|
225 | ParameterizeEvaluator();
|
---|
226 | UpdateMoveEvaluators();
|
---|
227 | ParameterizeAnalyzers();
|
---|
228 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
229 | Evaluator_QualityParameter_ActualNameChanged(null, EventArgs.Empty);
|
---|
230 | OnReset();
|
---|
231 | }
|
---|
232 | private void ProblemSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
233 | ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
|
---|
234 | ProblemSize_ValueChanged(null, EventArgs.Empty);
|
---|
235 | }
|
---|
236 | private void ProblemSize_ValueChanged(object sender, EventArgs e) {
|
---|
237 | if (ProblemSize.Value < 1) ProblemSize.Value = 1;
|
---|
238 | ParameterizeSolutionCreator();
|
---|
239 | ParameterizeEvaluator();
|
---|
240 | //strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));
|
---|
241 | //strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));
|
---|
242 | OnReset();
|
---|
243 | }
|
---|
244 | private void SolutionCreator_RealVectorParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
245 | ParameterizeEvaluator();
|
---|
246 | ParameterizeOperators();
|
---|
247 | ParameterizeAnalyzers();
|
---|
248 | }
|
---|
249 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
250 | ParameterizeOperators();
|
---|
251 | }
|
---|
252 | private void BoundsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
253 | Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
|
---|
254 | Bounds_ToStringChanged(null, EventArgs.Empty);
|
---|
255 | }
|
---|
256 | private void Bounds_ToStringChanged(object sender, EventArgs e) {
|
---|
257 | if (Bounds.Columns != 2 || Bounds.Rows < 1)
|
---|
258 | Bounds = new DoubleMatrix(1, 2);
|
---|
259 | ParameterizeOperators();
|
---|
260 | UpdateStrategyVectorBounds();
|
---|
261 | }
|
---|
262 | private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
263 | if (e.Value2 == 0 && Bounds[e.Value, 1] <= Bounds[e.Value, 0])
|
---|
264 | Bounds[e.Value, 1] = Bounds[e.Value, 0] + 0.1;
|
---|
265 | if (e.Value2 == 1 && Bounds[e.Value, 0] >= Bounds[e.Value, 1])
|
---|
266 | Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1;
|
---|
267 | ParameterizeOperators();
|
---|
268 | UpdateStrategyVectorBounds();
|
---|
269 | }
|
---|
270 | private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
271 | string name = ((ILookupParameter<AdditiveMove>)sender).ActualName;
|
---|
272 | foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
|
---|
273 | op.AdditiveMoveParameter.ActualName = name;
|
---|
274 | }
|
---|
275 | }
|
---|
276 | //private void SphereEvaluator_Parameter_ValueChanged(object sender, EventArgs e) {
|
---|
277 | // SphereEvaluator eval = (Evaluator as SphereEvaluator);
|
---|
278 | // if (eval != null) {
|
---|
279 | // foreach (ISphereMoveEvaluator op in Operators.OfType<ISphereMoveEvaluator>()) {
|
---|
280 | // op.C = eval.C;
|
---|
281 | // op.Alpha = eval.Alpha;
|
---|
282 | // }
|
---|
283 | // }
|
---|
284 | //}
|
---|
285 | //private void RastriginEvaluator_Parameter_ValueChanged(object sender, EventArgs e) {
|
---|
286 | // RastriginEvaluator eval = (Evaluator as RastriginEvaluator);
|
---|
287 | // if (eval != null) {
|
---|
288 | // foreach (IRastriginMoveEvaluator op in Operators.OfType<IRastriginMoveEvaluator>()) {
|
---|
289 | // op.A = eval.A;
|
---|
290 | // }
|
---|
291 | // }
|
---|
292 | //}
|
---|
293 | //private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
294 | // strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();
|
---|
295 | //}
|
---|
296 | //private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
297 | // string name = strategyVectorCreator.StrategyParameterParameter.ActualName;
|
---|
298 | // strategyVectorCrossover.ParentsParameter.ActualName = name;
|
---|
299 | // strategyVectorCrossover.StrategyParameterParameter.ActualName = name;
|
---|
300 | // strategyVectorManipulator.StrategyParameterParameter.ActualName = name;
|
---|
301 | //}
|
---|
302 | #endregion
|
---|
303 |
|
---|
304 | #region Helpers
|
---|
305 | [StorableHook(HookType.AfterDeserialization)]
|
---|
306 | private void AfterDeserialization() {
|
---|
307 | RegisterEventHandlers();
|
---|
308 | }
|
---|
309 |
|
---|
310 | private void RegisterEventHandlers() {
|
---|
311 | ProblemSizeParameter.ValueChanged += new EventHandler(ProblemSizeParameter_ValueChanged);
|
---|
312 | ProblemSize.ValueChanged += new EventHandler(ProblemSize_ValueChanged);
|
---|
313 | BoundsParameter.ValueChanged += new EventHandler(BoundsParameter_ValueChanged);
|
---|
314 | Bounds.ToStringChanged += new EventHandler(Bounds_ToStringChanged);
|
---|
315 | Bounds.ItemChanged += new EventHandler<EventArgs<int, int>>(Bounds_ItemChanged);
|
---|
316 | SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged);
|
---|
317 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
318 | //strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged);
|
---|
319 | //strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged);
|
---|
320 | }
|
---|
321 | private void ParameterizeAnalyzers() {
|
---|
322 | if (BestMovingPeaksBenchmarkSolutionAnalyzer != null) {
|
---|
323 | BestMovingPeaksBenchmarkSolutionAnalyzer.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
324 | BestMovingPeaksBenchmarkSolutionAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
325 | BestMovingPeaksBenchmarkSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
326 | BestMovingPeaksBenchmarkSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
|
---|
327 | BestMovingPeaksBenchmarkSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
|
---|
328 | BestMovingPeaksBenchmarkSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
329 | }
|
---|
330 | }
|
---|
331 | private void InitializeOperators() {
|
---|
332 | //Operators.Add(new SingleObjectiveTestFunctionImprovementOperator());
|
---|
333 | //Operators.Add(new SingleObjectiveTestFunctionPathRelinker());
|
---|
334 | //Operators.Add(new SingleObjectiveTestFunctionSimilarityCalculator());
|
---|
335 | //Operators.Add(new HammingSimilarityCalculator());
|
---|
336 | //Operators.Add(new EuclideanSimilarityCalculator());
|
---|
337 | //Operators.Add(new QualitySimilarityCalculator());
|
---|
338 |
|
---|
339 | Operators.Add(new BestMovingPeaksBenchmarkSolutionAnalyzer());
|
---|
340 | //Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
|
---|
341 | ParameterizeAnalyzers();
|
---|
342 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
|
---|
343 | //Operators.Add(strategyVectorCreator);
|
---|
344 | //Operators.Add(strategyVectorCrossover);
|
---|
345 | //Operators.Add(strategyVectorManipulator);
|
---|
346 | UpdateMoveEvaluators();
|
---|
347 | ParameterizeOperators();
|
---|
348 | InitializeMoveGenerators();
|
---|
349 | }
|
---|
350 | private void InitializeMoveGenerators() {
|
---|
351 | foreach (IAdditiveRealVectorMoveOperator op in Operators.OfType<IAdditiveRealVectorMoveOperator>()) {
|
---|
352 | if (op is IMoveGenerator) {
|
---|
353 | op.AdditiveMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_AdditiveMoveParameter_ActualNameChanged);
|
---|
354 | }
|
---|
355 | }
|
---|
356 | }
|
---|
357 | private void UpdateMoveEvaluators() {
|
---|
358 | //foreach (ISingleObjectiveTestFunctionMoveEvaluator op in Operators.OfType<ISingleObjectiveTestFunctionMoveEvaluator>().ToList())
|
---|
359 | // Operators.Remove(op);
|
---|
360 | //foreach (ISingleObjectiveTestFunctionMoveEvaluator op in ApplicationManager.Manager.GetInstances<ISingleObjectiveTestFunctionMoveEvaluator>())
|
---|
361 | // if (op.EvaluatorType == Evaluator.GetType()) {
|
---|
362 | // Operators.Add(op);
|
---|
363 | // #region Synchronize evaluator specific parameters with the parameters of the corresponding move evaluators
|
---|
364 | // if (op is ISphereMoveEvaluator) {
|
---|
365 | // SphereEvaluator e = (Evaluator as SphereEvaluator);
|
---|
366 | // e.AlphaParameter.ValueChanged += new EventHandler(SphereEvaluator_Parameter_ValueChanged);
|
---|
367 | // e.CParameter.ValueChanged += new EventHandler(SphereEvaluator_Parameter_ValueChanged);
|
---|
368 | // ISphereMoveEvaluator em = (op as ISphereMoveEvaluator);
|
---|
369 | // em.C = e.C;
|
---|
370 | // em.Alpha = e.Alpha;
|
---|
371 | // } else if (op is IRastriginMoveEvaluator) {
|
---|
372 | // RastriginEvaluator e = (Evaluator as RastriginEvaluator);
|
---|
373 | // e.AParameter.ValueChanged += new EventHandler(RastriginEvaluator_Parameter_ValueChanged);
|
---|
374 | // IRastriginMoveEvaluator em = (op as IRastriginMoveEvaluator);
|
---|
375 | // em.A = e.A;
|
---|
376 | // }
|
---|
377 | // #endregion
|
---|
378 | // }
|
---|
379 | ParameterizeOperators();
|
---|
380 | OnOperatorsChanged();
|
---|
381 | }
|
---|
382 | private void ParameterizeSolutionCreator() {
|
---|
383 | SolutionCreator.LengthParameter.Value = new IntValue(ProblemSize.Value);
|
---|
384 | SolutionCreator.LengthParameter.Hidden = true;
|
---|
385 | SolutionCreator.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
386 | SolutionCreator.BoundsParameter.Hidden = true;
|
---|
387 | }
|
---|
388 | private void ParameterizeEvaluator() {
|
---|
389 | Evaluator.PointParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
390 | Evaluator.PointParameter.Hidden = true;
|
---|
391 | //try {
|
---|
392 | // BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
|
---|
393 | //}
|
---|
394 | //catch (ArgumentException e) {
|
---|
395 | // ErrorHandling.ShowErrorDialog(e);
|
---|
396 | // ProblemSize.Value = Evaluator.MinimumProblemSize;
|
---|
397 | //}
|
---|
398 | }
|
---|
399 | private void ParameterizeOperators() {
|
---|
400 | foreach (var op in Operators.OfType<IRealVectorCrossover>()) {
|
---|
401 | op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
402 | op.ParentsParameter.Hidden = true;
|
---|
403 | op.ChildParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
404 | op.ChildParameter.Hidden = true;
|
---|
405 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
406 | op.BoundsParameter.Hidden = true;
|
---|
407 | }
|
---|
408 | foreach (var op in Operators.OfType<IRealVectorManipulator>()) {
|
---|
409 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
410 | op.RealVectorParameter.Hidden = true;
|
---|
411 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
412 | op.BoundsParameter.Hidden = true;
|
---|
413 | }
|
---|
414 | foreach (var op in Operators.OfType<IRealVectorMoveOperator>()) {
|
---|
415 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
416 | op.RealVectorParameter.Hidden = true;
|
---|
417 | }
|
---|
418 | foreach (var op in Operators.OfType<IRealVectorMoveGenerator>()) {
|
---|
419 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
420 | op.BoundsParameter.Hidden = true;
|
---|
421 | }
|
---|
422 | //foreach (var op in Operators.OfType<ISingleObjectiveTestFunctionAdditiveMoveEvaluator>()) {
|
---|
423 | // op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
424 | // op.QualityParameter.Hidden = true;
|
---|
425 | // op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
426 | // op.RealVectorParameter.Hidden = true;
|
---|
427 | //}
|
---|
428 | foreach (var op in Operators.OfType<IRealVectorParticleCreator>()) {
|
---|
429 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
430 | op.RealVectorParameter.Hidden = true;
|
---|
431 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
432 | op.BoundsParameter.Hidden = true;
|
---|
433 | }
|
---|
434 | foreach (var op in Operators.OfType<IRealVectorParticleUpdater>()) {
|
---|
435 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
436 | op.RealVectorParameter.Hidden = true;
|
---|
437 | op.BoundsParameter.ActualName = BoundsParameter.Name;
|
---|
438 | op.BoundsParameter.Hidden = true;
|
---|
439 | }
|
---|
440 | foreach (var op in Operators.OfType<IRealVectorSwarmUpdater>()) {
|
---|
441 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
442 | op.RealVectorParameter.Hidden = true;
|
---|
443 | op.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
444 | op.MaximizationParameter.Hidden = true;
|
---|
445 | }
|
---|
446 | foreach (var op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) {
|
---|
447 | op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
448 | op.RealVectorParameter.Hidden = true;
|
---|
449 | }
|
---|
450 | foreach (var op in Operators.OfType<ISingleObjectiveImprovementOperator>()) {
|
---|
451 | op.SolutionParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
452 | op.SolutionParameter.Hidden = true;
|
---|
453 | }
|
---|
454 | foreach (var op in Operators.OfType<ISingleObjectivePathRelinker>()) {
|
---|
455 | op.ParentsParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
456 | op.ParentsParameter.Hidden = true;
|
---|
457 | }
|
---|
458 | foreach (var op in Operators.OfType<ISolutionSimilarityCalculator>()) {
|
---|
459 | op.SolutionVariableName = SolutionCreator.RealVectorParameter.ActualName;
|
---|
460 | op.QualityVariableName = Evaluator.QualityParameter.ActualName;
|
---|
461 | //var calc = op as SingleObjectiveTestFunctionSimilarityCalculator;
|
---|
462 | //if (calc != null) calc.Bounds = Bounds;
|
---|
463 | }
|
---|
464 | }
|
---|
465 | private void UpdateStrategyVectorBounds() {
|
---|
466 | //var strategyBounds = (DoubleMatrix)Bounds.Clone();
|
---|
467 | //for (int i = 0; i < strategyBounds.Rows; i++) {
|
---|
468 | // if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
|
---|
469 | // strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]);
|
---|
470 | //}
|
---|
471 | //strategyVectorCreator.BoundsParameter.Value = strategyBounds;
|
---|
472 | }
|
---|
473 | #endregion
|
---|
474 | }
|
---|
475 | }
|
---|