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