1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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 (IValueParameter<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(false)));
|
---|
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.SeedParameter.Value = null;
|
---|
207 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
208 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
209 | randomCreator.Successor = solutionsCreator;
|
---|
210 |
|
---|
211 | solutionsCreator.Name = "DiversificationGenerationMethod";
|
---|
212 | solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
|
---|
213 | solutionsCreator.Successor = uniformSubScopesProcessor;
|
---|
214 |
|
---|
215 | uniformSubScopesProcessor.Operator = solutionImprover;
|
---|
216 | uniformSubScopesProcessor.ParallelParameter.Value = new BoolValue(true);
|
---|
217 | uniformSubScopesProcessor.Successor = variableCreator;
|
---|
218 |
|
---|
219 | solutionImprover.Name = "SolutionImprover";
|
---|
220 | solutionImprover.OperatorParameter.ActualName = "Improver";
|
---|
221 | solutionImprover.Successor = solutionEvaluator;
|
---|
222 |
|
---|
223 | solutionEvaluator.Name = "SolutionEvaluator";
|
---|
224 | solutionEvaluator.OperatorParameter.ActualName = "Evaluator";
|
---|
225 | solutionEvaluator.Successor = null;
|
---|
226 |
|
---|
227 | variableCreator.Name = "Initialize EvaluatedSolutions";
|
---|
228 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
|
---|
229 | variableCreator.Successor = dataReducer;
|
---|
230 |
|
---|
231 | dataReducer.Name = "Increment EvaluatedSolutions";
|
---|
232 | dataReducer.ParameterToReduce.ActualName = "LocalEvaluatedSolutions";
|
---|
233 | dataReducer.TargetParameter.ActualName = "EvaluatedSolutions";
|
---|
234 | dataReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
235 | dataReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
236 | dataReducer.Successor = resultsCollector;
|
---|
237 |
|
---|
238 | resultsCollector.Name = "ResultsCollector";
|
---|
239 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions", null, "EvaluatedSolutions"));
|
---|
240 | resultsCollector.Successor = bestSelector;
|
---|
241 |
|
---|
242 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name;
|
---|
243 | bestSelector.CopySelected = new BoolValue(false);
|
---|
244 | bestSelector.Successor = mainLoop;
|
---|
245 |
|
---|
246 | mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
|
---|
247 | mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
|
---|
248 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
249 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
250 | mainLoop.IterationsParameter.ActualName = "Iterations";
|
---|
251 | mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
|
---|
252 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
253 | mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
254 | mainLoop.NumberOfHighQualitySolutionsParameter.ActualName = NumberOfHighQualitySolutionsParameter.Name;
|
---|
255 | mainLoop.Successor = null;
|
---|
256 | #endregion
|
---|
257 |
|
---|
258 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
259 | ParameterizeAnalyzers();
|
---|
260 | UpdateAnalyzers();
|
---|
261 |
|
---|
262 | Initialize();
|
---|
263 | }
|
---|
264 |
|
---|
265 | public override void Prepare() {
|
---|
266 | if (Problem != null && Improver != null && (PathRelinker != null || ExecutePathRelinking.Value == false) && SimilarityCalculator != null)
|
---|
267 | base.Prepare();
|
---|
268 | }
|
---|
269 |
|
---|
270 | #region Events
|
---|
271 | protected override void OnProblemChanged() {
|
---|
272 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
273 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
274 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
275 | ParameterizeAnalyzers();
|
---|
276 | ParameterizeSolutionsCreator();
|
---|
277 | ParameterizeBestSelector();
|
---|
278 | UpdateAnalyzers();
|
---|
279 | UpdateCrossovers();
|
---|
280 | UpdateImprovers();
|
---|
281 | UpdatePathRelinkers();
|
---|
282 | UpdateSimilarityCalculators();
|
---|
283 | ParameterizeMainLoop();
|
---|
284 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
285 | base.OnProblemChanged();
|
---|
286 | }
|
---|
287 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
288 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
289 | ParameterizeSolutionsCreator();
|
---|
290 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
291 | }
|
---|
292 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
293 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
294 | ParameterizeSolutionsCreator();
|
---|
295 | ParameterizeMainLoop();
|
---|
296 | ParameterizeAnalyzers();
|
---|
297 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
298 | base.Problem_EvaluatorChanged(sender, e);
|
---|
299 | }
|
---|
300 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
301 | foreach (IOperator op in Problem.Operators.OfType<IOperator>()) ParameterizeStochasticOperator(op);
|
---|
302 | UpdateAnalyzers();
|
---|
303 | UpdateCrossovers();
|
---|
304 | UpdatePathRelinkers();
|
---|
305 | UpdateSimilarityCalculators();
|
---|
306 | UpdateImprovers();
|
---|
307 | ParameterizeMainLoop();
|
---|
308 | ParameterizeAnalyzers();
|
---|
309 | base.Problem_OperatorsChanged(sender, e);
|
---|
310 | }
|
---|
311 | private void PathRelinkerParameter_ValueChanged(object sender, EventArgs e) {
|
---|
312 | ExecutePathRelinking.Value = PathRelinkerParameter.Value != null;
|
---|
313 | }
|
---|
314 | private void SimilarityCalculatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
315 | ParameterizeMainLoop();
|
---|
316 | }
|
---|
317 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
318 | ParameterizeMainLoop();
|
---|
319 | ParameterizeAnalyzers();
|
---|
320 | ParameterizeBestSelector();
|
---|
321 | ParameterizeSimilarityCalculators();
|
---|
322 | }
|
---|
323 | #endregion
|
---|
324 |
|
---|
325 | #region Helpers
|
---|
326 | private void Initialize() {
|
---|
327 | PathRelinkerParameter.ValueChanged += new EventHandler(PathRelinkerParameter_ValueChanged);
|
---|
328 | SimilarityCalculatorParameter.ValueChanged += new EventHandler(SimilarityCalculatorParameter_ValueChanged);
|
---|
329 | if (Problem != null)
|
---|
330 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
331 | }
|
---|
332 | private void UpdateAnalyzers() {
|
---|
333 | Analyzer.Operators.Clear();
|
---|
334 | if (Problem != null) {
|
---|
335 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
336 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
337 | param.Depth = 1;
|
---|
338 | Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
|
---|
339 | }
|
---|
340 | }
|
---|
341 | Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
|
---|
342 | }
|
---|
343 | private void UpdateCrossovers() {
|
---|
344 | ICrossover oldCrossover = CrossoverParameter.Value;
|
---|
345 | CrossoverParameter.ValidValues.Clear();
|
---|
346 | ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
|
---|
347 |
|
---|
348 | foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
|
---|
349 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
350 |
|
---|
351 | if (oldCrossover != null) {
|
---|
352 | ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
|
---|
353 | if (crossover != null) CrossoverParameter.Value = crossover;
|
---|
354 | else oldCrossover = null;
|
---|
355 | }
|
---|
356 | if (oldCrossover == null && defaultCrossover != null)
|
---|
357 | CrossoverParameter.Value = defaultCrossover;
|
---|
358 | }
|
---|
359 | private void UpdateImprovers() {
|
---|
360 | IImprovementOperator oldImprover = ImproverParameter.Value;
|
---|
361 | ImproverParameter.ValidValues.Clear();
|
---|
362 | IImprovementOperator defaultImprover = Problem.Operators.OfType<IImprovementOperator>().FirstOrDefault();
|
---|
363 |
|
---|
364 | foreach (IImprovementOperator improver in Problem.Operators.OfType<IImprovementOperator>().OrderBy(x => x.Name))
|
---|
365 | ImproverParameter.ValidValues.Add(improver);
|
---|
366 |
|
---|
367 | if (oldImprover != null) {
|
---|
368 | IImprovementOperator improver = ImproverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldImprover.GetType());
|
---|
369 | if (improver != null) ImproverParameter.Value = improver;
|
---|
370 | else oldImprover = null;
|
---|
371 | }
|
---|
372 | if (oldImprover == null && defaultImprover != null)
|
---|
373 | ImproverParameter.Value = defaultImprover;
|
---|
374 | }
|
---|
375 | private void UpdatePathRelinkers() {
|
---|
376 | IPathRelinker oldPathRelinker = PathRelinkerParameter.Value;
|
---|
377 | PathRelinkerParameter.ValidValues.Clear();
|
---|
378 | IPathRelinker defaultPathRelinker = Problem.Operators.OfType<IPathRelinker>().FirstOrDefault();
|
---|
379 |
|
---|
380 | foreach (IPathRelinker pathRelinker in Problem.Operators.OfType<IPathRelinker>().OrderBy(x => x.Name))
|
---|
381 | PathRelinkerParameter.ValidValues.Add(pathRelinker);
|
---|
382 |
|
---|
383 | if (oldPathRelinker != null) {
|
---|
384 | IPathRelinker pathRelinker = PathRelinkerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldPathRelinker.GetType());
|
---|
385 | if (pathRelinker != null) PathRelinkerParameter.Value = pathRelinker;
|
---|
386 | else oldPathRelinker = null;
|
---|
387 | }
|
---|
388 | if (oldPathRelinker == null && defaultPathRelinker != null)
|
---|
389 | PathRelinkerParameter.Value = defaultPathRelinker;
|
---|
390 | }
|
---|
391 | private void UpdateSimilarityCalculators() {
|
---|
392 | ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
|
---|
393 | SimilarityCalculatorParameter.ValidValues.Clear();
|
---|
394 | ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
|
---|
395 |
|
---|
396 | SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
|
---|
397 | SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
|
---|
398 |
|
---|
399 | foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
|
---|
400 | SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
|
---|
401 |
|
---|
402 | if (oldSimilarityCalculator != null) {
|
---|
403 | ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
|
---|
404 | if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
|
---|
405 | else oldSimilarityCalculator = null;
|
---|
406 | }
|
---|
407 | if (oldSimilarityCalculator == null && defaultSimilarityCalculator != null)
|
---|
408 | SimilarityCalculatorParameter.Value = defaultSimilarityCalculator;
|
---|
409 | }
|
---|
410 | private void ParameterizeBestSelector() {
|
---|
411 | OperatorGraph.Operators.OfType<ISingleObjectiveSelector>()
|
---|
412 | .First().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
413 | }
|
---|
414 | private void ParameterizeSolutionsCreator() {
|
---|
415 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
416 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
417 | }
|
---|
418 | private void ParameterizeMainLoop() {
|
---|
419 | if (Problem != null && Improver != null) {
|
---|
420 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
421 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
422 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
423 | MainLoop.OperatorGraph.Operators.OfType<PopulationRebuildMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
424 | MainLoop.OperatorGraph.Operators.OfType<SolutionPoolUpdateMethod>().Single().QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
425 | foreach (ISimilarityBasedOperator op in MainLoop.OperatorGraph.Operators.OfType<ISimilarityBasedOperator>())
|
---|
426 | op.SimilarityCalculator = SimilarityCalculator;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
430 | if (op is IStochasticOperator) {
|
---|
431 | IStochasticOperator stOp = (IStochasticOperator)op;
|
---|
432 | stOp.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
433 | stOp.RandomParameter.Hidden = true;
|
---|
434 | }
|
---|
435 | }
|
---|
436 | private void ParameterizeAnalyzers() {
|
---|
437 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
438 | qualityAnalyzer.ResultsParameter.Hidden = true;
|
---|
439 | if (Problem != null) {
|
---|
440 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
441 | qualityAnalyzer.MaximizationParameter.Hidden = true;
|
---|
442 | qualityAnalyzer.QualityParameter.Hidden = false;
|
---|
443 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
444 | qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
|
---|
445 | } else {
|
---|
446 | qualityAnalyzer.MaximizationParameter.Hidden = false;
|
---|
447 | qualityAnalyzer.BestKnownQualityParameter.Hidden = false;
|
---|
448 | }
|
---|
449 | }
|
---|
450 | private void ParameterizeSimilarityCalculators() {
|
---|
451 | foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
|
---|
452 | calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
453 | }
|
---|
454 | }
|
---|
455 | private ScatterSearchMainLoop FindMainLoop(IOperator start) {
|
---|
456 | IOperator mainLoop = start;
|
---|
457 | while (mainLoop != null && !(mainLoop is ScatterSearchMainLoop))
|
---|
458 | mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
|
---|
459 | return mainLoop as ScatterSearchMainLoop;
|
---|
460 | }
|
---|
461 | #endregion
|
---|
462 | }
|
---|
463 | }
|
---|