1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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.Linq;
|
---|
24 | using HeuristicLab.Analysis;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Optimization.Operators;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 | using HeuristicLab.Random;
|
---|
34 | using HeuristicLab.Selection;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Algorithms.ScatterSearch {
|
---|
37 | /// <summary>
|
---|
38 | /// A scatter search algorithm.
|
---|
39 | /// </summary>
|
---|
40 | [Item("Scatter Search", "A scatter search algorithm.")]
|
---|
41 | [Creatable("Algorithms")]
|
---|
42 | [StorableClass]
|
---|
43 | public sealed class ScatterSearch : HeuristicOptimizationEngineAlgorithm, IStorableContent {
|
---|
44 | public string Filename { get; set; }
|
---|
45 |
|
---|
46 | #region Problem Properties
|
---|
47 | public override Type ProblemType {
|
---|
48 | get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
|
---|
49 | }
|
---|
50 | public new ISingleObjectiveHeuristicOptimizationProblem Problem {
|
---|
51 | get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
|
---|
52 | set { base.Problem = value; }
|
---|
53 | }
|
---|
54 | #endregion
|
---|
55 |
|
---|
56 | #region Parameter Properties
|
---|
57 | public IValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
58 | get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
59 | }
|
---|
60 | public IConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
61 | get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
62 | }
|
---|
63 | public IValueParameter<BoolValue> ExecutePathRelinkingParameter {
|
---|
64 | get { return (IValueLookupParameter<BoolValue>)Parameters["ExecutePathRelinking"]; }
|
---|
65 | }
|
---|
66 | public IConstrainedValueParameter<IImprovementOperator> ImproverParameter {
|
---|
67 | get { return (IConstrainedValueParameter<IImprovementOperator>)Parameters["Improver"]; }
|
---|
68 | }
|
---|
69 | public IValueParameter<IntValue> MaximumIterationsParameter {
|
---|
70 | get { return (IValueParameter<IntValue>)Parameters["MaximumIterations"]; }
|
---|
71 | }
|
---|
72 | public IValueParameter<IntValue> NumberOfHighQualitySolutionsParameter {
|
---|
73 | get { return (IValueParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
|
---|
74 | }
|
---|
75 | public IConstrainedValueParameter<IPathRelinker> PathRelinkerParameter {
|
---|
76 | get { return (IConstrainedValueParameter<IPathRelinker>)Parameters["PathRelinker"]; }
|
---|
77 | }
|
---|
78 | public IValueParameter<IntValue> PopulationSizeParameter {
|
---|
79 | get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
80 | }
|
---|
81 | public IValueParameter<IntValue> ReferenceSetSizeParameter {
|
---|
82 | get { return (IValueParameter<IntValue>)Parameters["ReferenceSetSize"]; }
|
---|
83 | }
|
---|
84 | public IValueParameter<IntValue> SeedParameter {
|
---|
85 | get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
86 | }
|
---|
87 | public IValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
88 | get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
89 | }
|
---|
90 | public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
91 | get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
92 | }
|
---|
93 | #endregion
|
---|
94 |
|
---|
95 | #region Properties
|
---|
96 | public MultiAnalyzer Analyzer {
|
---|
97 | get { return AnalyzerParameter.Value; }
|
---|
98 | set { AnalyzerParameter.Value = value; }
|
---|
99 | }
|
---|
100 | public ICrossover Crossover {
|
---|
101 | get { return CrossoverParameter.Value; }
|
---|
102 | set { CrossoverParameter.Value = value; }
|
---|
103 | }
|
---|
104 | public BoolValue ExecutePathRelinking {
|
---|
105 | get { return ExecutePathRelinkingParameter.Value; }
|
---|
106 | set { ExecutePathRelinkingParameter.Value = value; }
|
---|
107 | }
|
---|
108 | public IImprovementOperator Improver {
|
---|
109 | get { return ImproverParameter.Value; }
|
---|
110 | set { ImproverParameter.Value = value; }
|
---|
111 | }
|
---|
112 | public IntValue MaximumIterations {
|
---|
113 | get { return MaximumIterationsParameter.Value; }
|
---|
114 | set { MaximumIterationsParameter.Value = value; }
|
---|
115 | }
|
---|
116 | public IntValue NumberOfHighQualitySolutions {
|
---|
117 | get { return NumberOfHighQualitySolutionsParameter.Value; }
|
---|
118 | set { NumberOfHighQualitySolutionsParameter.Value = value; }
|
---|
119 | }
|
---|
120 | public IPathRelinker PathRelinker {
|
---|
121 | get { return PathRelinkerParameter.Value; }
|
---|
122 | set { PathRelinkerParameter.Value = value; }
|
---|
123 | }
|
---|
124 | public IntValue PopulationSize {
|
---|
125 | get { return PopulationSizeParameter.Value; }
|
---|
126 | set { PopulationSizeParameter.Value = value; }
|
---|
127 | }
|
---|
128 | public IntValue ReferenceSetSize {
|
---|
129 | get { return ReferenceSetSizeParameter.Value; }
|
---|
130 | set { ReferenceSetSizeParameter.Value = value; }
|
---|
131 | }
|
---|
132 | public IntValue Seed {
|
---|
133 | get { return SeedParameter.Value; }
|
---|
134 | set { SeedParameter.Value = value; }
|
---|
135 | }
|
---|
136 | public BoolValue SetSeedRandomly {
|
---|
137 | get { return SetSeedRandomlyParameter.Value; }
|
---|
138 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
139 | }
|
---|
140 | public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
|
---|
141 | get { return SimilarityCalculatorParameter.Value; }
|
---|
142 | set { SimilarityCalculatorParameter.Value = value; }
|
---|
143 | }
|
---|
144 | private RandomCreator RandomCreator {
|
---|
145 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
146 | }
|
---|
147 | private SolutionsCreator SolutionsCreator {
|
---|
148 | get { return (SolutionsCreator)RandomCreator.Successor; }
|
---|
149 | }
|
---|
150 | private ScatterSearchMainLoop MainLoop {
|
---|
151 | get { return FindMainLoop(SolutionsCreator.Successor); }
|
---|
152 | }
|
---|
153 |
|
---|
154 | [Storable]
|
---|
155 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
156 | #endregion
|
---|
157 |
|
---|
158 | [StorableConstructor]
|
---|
159 | private ScatterSearch(bool deserializing) : base(deserializing) { }
|
---|
160 | [StorableHook(HookType.AfterDeserialization)]
|
---|
161 | private void AfterDeserialization() {
|
---|
162 | Initialize();
|
---|
163 | }
|
---|
164 | private ScatterSearch(ScatterSearch original, Cloner cloner)
|
---|
165 | : base(original, cloner) {
|
---|
166 | qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
|
---|
167 | Initialize();
|
---|
168 | }
|
---|
169 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
170 | return new ScatterSearch(this, cloner);
|
---|
171 | }
|
---|
172 | public ScatterSearch()
|
---|
173 | : base() {
|
---|
174 | #region Create parameters
|
---|
175 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The analyzer used to analyze each iteration.", new MultiAnalyzer()));
|
---|
176 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
177 | Parameters.Add(new ValueParameter<BoolValue>("ExecutePathRelinking", "True if path relinking should be executed instead of crossover, otherwise false.", new BoolValue(true)));
|
---|
178 | Parameters.Add(new ConstrainedValueParameter<IImprovementOperator>("Improver", "The operator used to improve solutions."));
|
---|
179 | Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed.", new IntValue(100)));
|
---|
180 | Parameters.Add(new ValueParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set.", new IntValue(5)));
|
---|
181 | Parameters.Add(new ConstrainedValueParameter<IPathRelinker>("PathRelinker", "The operator used to execute path relinking."));
|
---|
182 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(50)));
|
---|
183 | Parameters.Add(new ValueParameter<IntValue>("ReferenceSetSize", "The size of the reference set.", new IntValue(20)));
|
---|
184 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
185 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
186 | Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
|
---|
187 | #endregion
|
---|
188 |
|
---|
189 | #region Create operators
|
---|
190 | RandomCreator randomCreator = new RandomCreator();
|
---|
191 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
192 | UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
193 | Placeholder solutionEvaluator = new Placeholder();
|
---|
194 | Placeholder solutionImprover = new Placeholder();
|
---|
195 | VariableCreator variableCreator = new VariableCreator();
|
---|
196 | DataReducer dataReducer = new DataReducer();
|
---|
197 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
198 | BestSelector bestSelector = new BestSelector();
|
---|
199 | ScatterSearchMainLoop mainLoop = new ScatterSearchMainLoop();
|
---|
200 | #endregion
|
---|
201 |
|
---|
202 | #region Create operator graph
|
---|
203 | OperatorGraph.InitialOperator = randomCreator;
|
---|
204 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
205 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
206 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
207 | randomCreator.Successor = solutionsCreator;
|
---|
208 |
|
---|
209 | solutionsCreator.Name = "DiversificationGenerationMethod";
|
---|
210 | solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
|
---|
211 | solutionsCreator.Successor = uniformSubScopesProcessor;
|
---|
212 |
|
---|
213 | uniformSubScopesProcessor.Operator = solutionImprover;
|
---|
214 | uniformSubScopesProcessor.ParallelParameter.Value = new BoolValue(true);
|
---|
215 | uniformSubScopesProcessor.Successor = variableCreator;
|
---|
216 |
|
---|
217 | solutionImprover.Name = "SolutionImprover";
|
---|
218 | solutionImprover.OperatorParameter.ActualName = "Improver";
|
---|
219 | solutionImprover.Successor = solutionEvaluator;
|
---|
220 |
|
---|
221 | solutionEvaluator.Name = "SolutionEvaluator";
|
---|
222 | solutionEvaluator.OperatorParameter.ActualName = "Evaluator";
|
---|
223 | solutionEvaluator.Successor = null;
|
---|
224 |
|
---|
225 | variableCreator.Name = "Initialize EvaluatedSolutions";
|
---|
226 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
|
---|
227 | variableCreator.Successor = dataReducer;
|
---|
228 |
|
---|
229 | dataReducer.Name = "Increment EvaluatedSolutions";
|
---|
230 | dataReducer.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
|
---|
231 | dataReducer.TargetParameter.ActualName = "EvaluatedSolutions";
|
---|
232 | dataReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
233 | dataReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
234 | dataReducer.Successor = resultsCollector;
|
---|
235 |
|
---|
236 | resultsCollector.Name = "ResultsCollector";
|
---|
237 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions", null, "EvaluatedSolutions"));
|
---|
238 | resultsCollector.Successor = bestSelector;
|
---|
239 |
|
---|
240 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name;
|
---|
241 | bestSelector.CopySelected = new BoolValue(false);
|
---|
242 | bestSelector.Successor = mainLoop;
|
---|
243 |
|
---|
244 | mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
245 | mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
|
---|
246 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
247 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
248 | mainLoop.IterationsParameter.ActualName = "Iterations";
|
---|
249 | mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
|
---|
250 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
251 | mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
252 | mainLoop.NumberOfHighQualitySolutionsParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name;
|
---|
253 | mainLoop.Successor = null;
|
---|
254 | #endregion
|
---|
255 |
|
---|
256 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
257 | ParameterizeAnalyzers();
|
---|
258 | UpdateAnalyzers();
|
---|
259 |
|
---|
260 | Initialize();
|
---|
261 | }
|
---|
262 |
|
---|
263 | public override void Prepare() {
|
---|
264 | if (Problem != null && Improver != null && PathRelinker != null && SimilarityCalculator != null)
|
---|
265 | base.Prepare();
|
---|
266 | }
|
---|
267 |
|
---|
268 | #region Events
|
---|
269 | protected override void OnProblemChanged() {
|
---|
270 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
271 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
272 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
273 | ParameterizeAnalyzers();
|
---|
274 | ParameterizeSolutionsCreator();
|
---|
275 | ParameterizeBestSelector();
|
---|
276 | UpdateAnalyzers();
|
---|
277 | UpdateCrossovers();
|
---|
278 | UpdateImprovers();
|
---|
279 | UpdatePathRelinkers();
|
---|
280 | UpdateSimilarityCalculators();
|
---|
281 | ParameterizeMainLoop();
|
---|
282 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
283 | base.OnProblemChanged();
|
---|
284 | }
|
---|
285 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
286 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
287 | ParameterizeSolutionsCreator();
|
---|
288 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
289 | }
|
---|
290 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
291 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
292 | ParameterizeSolutionsCreator();
|
---|
293 | ParameterizeMainLoop();
|
---|
294 | ParameterizeAnalyzers();
|
---|
295 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
296 | base.Problem_EvaluatorChanged(sender, e);
|
---|
297 | }
|
---|
298 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
299 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
300 | UpdateAnalyzers();
|
---|
301 | UpdateCrossovers();
|
---|
302 | UpdatePathRelinkers();
|
---|
303 | UpdateSimilarityCalculators();
|
---|
304 | UpdateImprovers();
|
---|
305 | ParameterizeMainLoop();
|
---|
306 | ParameterizeAnalyzers();
|
---|
307 | base.Problem_OperatorsChanged(sender, e);
|
---|
308 | }
|
---|
309 | private void SimilarityCalculatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
310 | ParameterizeMainLoop();
|
---|
311 | }
|
---|
312 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
313 | ParameterizeMainLoop();
|
---|
314 | ParameterizeAnalyzers();
|
---|
315 | ParameterizeBestSelector();
|
---|
316 | ParameterizeSimilarityCalculators();
|
---|
317 | }
|
---|
318 | #endregion
|
---|
319 |
|
---|
320 | #region Helpers
|
---|
321 | private void Initialize() {
|
---|
322 | SimilarityCalculatorParameter.ValueChanged += new EventHandler(SimilarityCalculatorParameter_ValueChanged);
|
---|
323 | if (Problem != null)
|
---|
324 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
325 | }
|
---|
326 | private void UpdateAnalyzers() {
|
---|
327 | Analyzer.Operators.Clear();
|
---|
328 | if (Problem != null) {
|
---|
329 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
330 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
331 | param.Depth = 1;
|
---|
332 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
333 | }
|
---|
334 | }
|
---|
335 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
336 | }
|
---|
337 | private void UpdateCrossovers() {
|
---|
338 | ICrossover oldCrossover = CrossoverParameter.Value;
|
---|
339 | CrossoverParameter.ValidValues.Clear();
|
---|
340 | ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
341 |
|
---|
342 | foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
|
---|
343 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
344 |
|
---|
345 | if (oldCrossover != null) {
|
---|
346 | ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
|
---|
347 | if (crossover != null) CrossoverParameter.Value = crossover;
|
---|
348 | else oldCrossover = null;
|
---|
349 | }
|
---|
350 | if (oldCrossover == null && defaultCrossover != null)
|
---|
351 | CrossoverParameter.Value = defaultCrossover;
|
---|
352 | }
|
---|
353 | private void UpdateImprovers() {
|
---|
354 | IImprovementOperator oldImprover = ImproverParameter.Value;
|
---|
355 | ImproverParameter.ValidValues.Clear();
|
---|
356 | IImprovementOperator defaultImprover = Problem.Operators.OfType<IImprovementOperator>().FirstOrDefault();
|
---|
357 |
|
---|
358 | foreach (IImprovementOperator improver in Problem.Operators.OfType<IImprovementOperator>().OrderBy(x => x.Name))
|
---|
359 | ImproverParameter.ValidValues.Add(improver);
|
---|
360 |
|
---|
361 | if (oldImprover != null) {
|
---|
362 | IImprovementOperator improver = ImproverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldImprover.GetType());
|
---|
363 | if (improver != null) ImproverParameter.Value = improver;
|
---|
364 | else oldImprover = null;
|
---|
365 | }
|
---|
366 | if (oldImprover == null && defaultImprover != null)
|
---|
367 | ImproverParameter.Value = defaultImprover;
|
---|
368 | }
|
---|
369 | private void UpdatePathRelinkers() {
|
---|
370 | IPathRelinker oldPathRelinker = PathRelinkerParameter.Value;
|
---|
371 | PathRelinkerParameter.ValidValues.Clear();
|
---|
372 | IPathRelinker defaultPathRelinker = Problem.Operators.OfType<IPathRelinker>().FirstOrDefault();
|
---|
373 |
|
---|
374 | foreach (IPathRelinker pathRelinker in Problem.Operators.OfType<IPathRelinker>().OrderBy(x => x.Name))
|
---|
375 | PathRelinkerParameter.ValidValues.Add(pathRelinker);
|
---|
376 |
|
---|
377 | if (oldPathRelinker != null) {
|
---|
378 | IPathRelinker pathRelinker = PathRelinkerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldPathRelinker.GetType());
|
---|
379 | if (pathRelinker != null) PathRelinkerParameter.Value = pathRelinker;
|
---|
380 | else oldPathRelinker = null;
|
---|
381 | }
|
---|
382 | if (oldPathRelinker == null && defaultPathRelinker != null)
|
---|
383 | PathRelinkerParameter.Value = defaultPathRelinker;
|
---|
384 | }
|
---|
385 | private void UpdateSimilarityCalculators() {
|
---|
386 | ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
|
---|
387 | SimilarityCalculatorParameter.ValidValues.Clear();
|
---|
388 | ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
|
---|
389 |
|
---|
390 | SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
|
---|
391 | SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator());
|
---|
392 |
|
---|
393 | foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
|
---|
394 | SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
|
---|
395 |
|
---|
396 | if (oldSimilarityCalculator != null) {
|
---|
397 | ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
|
---|
398 | if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
|
---|
399 | else oldSimilarityCalculator = null;
|
---|
400 | }
|
---|
401 | if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null)
|
---|
402 | SimilarityCalculatorParameter.Value = defaultSimilarityCalculator;
|
---|
403 | }
|
---|
404 | private void ParameterizeBestSelector() {
|
---|
405 | OperatorGraph.Operators.OfType<ISingleObjectiveSelector>()
|
---|
406 | .First().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
407 | }
|
---|
408 | private void ParameterizeSolutionsCreator() {
|
---|
409 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
410 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
411 | }
|
---|
412 | private void ParameterizeMainLoop() {
|
---|
413 | if (Problem != null && Improver != null) {
|
---|
414 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
415 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
416 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
417 | MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
418 | MainLoop.OperatorGraph.Operators.OfType<SolutionPoolUpdateMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
419 | foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
|
---|
420 | op.SimilarityCalculator = SimilarityCalculator;
|
---|
421 | }
|
---|
422 | }
|
---|
423 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
424 | if (op is IStochasticOperator) {
|
---|
425 | IStochasticOperator stOp = (IStochasticOperator)op;
|
---|
426 | stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
427 | stOp.RandomParameter.Hidden = true;
|
---|
428 | }
|
---|
429 | }
|
---|
430 | private void ParameterizeAnalyzers() {
|
---|
431 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
432 | qualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
433 | if (Problem != null) {
|
---|
434 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
435 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
436 | qualityAnalyzer.QualityParameter.Hidden = false;
|
---|
437 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
438 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
439 | } else {
|
---|
440 | qualityAnalyzer.MaximizationParameter.Hidden = false;
|
---|
441 | qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
|
---|
442 | }
|
---|
443 | }
|
---|
444 | private void ParameterizeSimilarityCalculators() {
|
---|
445 | foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
|
---|
446 | calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
447 | }
|
---|
448 | }
|
---|
449 | private ScatterSearchMainLoop FindMainLoop(IOperator start) {
|
---|
450 | IOperator mainLoop = start;
|
---|
451 | while (mainLoop != null && !(mainLoop is ScatterSearchMainLoop))
|
---|
452 | mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
|
---|
453 | return mainLoop as ScatterSearchMainLoop;
|
---|
454 | }
|
---|
455 | #endregion
|
---|
456 | }
|
---|
457 | }
|
---|