Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs @ 7778

Last change on this file since 7778 was 7778, checked in by jkarder, 12 years ago

#1331: added support for path relinking operators that use a multiple guiding strategy

File size: 16.9 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Selection;
31
32namespace HeuristicLab.Algorithms.ScatterSearch {
33  /// <summary>
34  /// An operator which represents a scatter search.
35  /// </summary>
36  [Item("ScatterSearchMainLoop", "An operator which represents a scatter search.")]
37  [StorableClass]
38  public sealed class ScatterSearchMainLoop : AlgorithmOperator {
39    #region Parameter properties
40    public IValueLookupParameter<IMultiAnalyzer> AnalyzerParameter {
41      get { return (IValueLookupParameter<IMultiAnalyzer>)Parameters["Analyzer"]; }
42    }
43    public IValueLookupParameter<ICrossover> CrossoverParameter {
44      get { return (IValueLookupParameter<ICrossover>)Parameters["Crossover"]; }
45    }
46    public IValueLookupParameter<IOperator> ImproverParameter {
47      get { return (IValueLookupParameter<IOperator>)Parameters["Improver"]; }
48    }
49    public IValueLookupParameter<DiversityCalculator> DiversityCalculatorParameter {
50      get { return (IValueLookupParameter<DiversityCalculator>)Parameters["DiversityCalculator"]; }
51    }
52    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
53      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
54    }
55    public IValueLookupParameter<IntValue> PopulationSizeParameter {
56      get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
57    }
58    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
59      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
60    }
61    public IValueLookupParameter<DoubleValue> BestKnownQualityParameter {
62      get { return (IValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
63    }
64    public IValueLookupParameter<IEvaluator> EvaluatorParameter {
65      get { return (IValueLookupParameter<IEvaluator>)Parameters["Evaluator"]; }
66    }
67    public IValueLookupParameter<IntValue> IterationsParameter {
68      get { return (IValueLookupParameter<IntValue>)Parameters["Iterations"]; }
69    }
70    public IValueLookupParameter<BoolValue> MaximizationParameter {
71      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
72    }
73    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
74      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
75    }
76    public IValueLookupParameter<DoubleValue> QualityParameter {
77      get { return (IValueLookupParameter<DoubleValue>)Parameters["Quality"]; }
78    }
79    public IValueLookupParameter<IRandom> RandomParameter {
80      get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; }
81    }
82    public IValueLookupParameter<VariableCollection> ResultsParameter {
83      get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
84    }
85    public IValueLookupParameter<IntValue> SampleSizeParameter {
86      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
87    }
88    public IValueLookupParameter<ISolutionCreator> SolutionCreatorParameter {
89      get { return (IValueLookupParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
90    }
91    #endregion
92
93    #region Properties
94    private IMultiAnalyzer Analyzer {
95      get { return AnalyzerParameter.ActualValue; }
96      set { AnalyzerParameter.ActualValue = value; }
97    }
98    private ICrossover Crossover {
99      get { return CrossoverParameter.ActualValue; }
100      set { CrossoverParameter.ActualValue = value; }
101    }
102    private IOperator Improver {
103      get { return ImproverParameter.ActualValue; }
104      set { ImproverParameter.ActualValue = value; }
105    }
106    private DiversityCalculator DiversityCalculator {
107      get { return DiversityCalculatorParameter.ActualValue; }
108      set { DiversityCalculatorParameter.ActualValue = value; }
109    }
110    private IntValue NumberOfHighQualitySolutions {
111      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
112      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
113    }
114    private IntValue PopulationSize {
115      get { return PopulationSizeParameter.ActualValue; }
116      set { PopulationSizeParameter.ActualValue = value; }
117    }
118    private IntValue ReferenceSetSize {
119      get { return ReferenceSetSizeParameter.ActualValue; }
120      set { ReferenceSetSizeParameter.ActualValue = value; }
121    }
122    private DoubleValue BestKnownQuality {
123      get { return BestKnownQualityParameter.ActualValue; }
124      set { BestKnownQualityParameter.ActualValue = value; }
125    }
126    private IEvaluator Evaluator {
127      get { return EvaluatorParameter.ActualValue; }
128      set { EvaluatorParameter.ActualValue = value; }
129    }
130    private IntValue Iterations {
131      get { return IterationsParameter.ActualValue; }
132      set { IterationsParameter.ActualValue = value; }
133    }
134    private BoolValue Maximization {
135      get { return MaximizationParameter.ActualValue; }
136      set { MaximizationParameter.ActualValue = value; }
137    }
138    private IntValue MaximumIterations {
139      get { return MaximumIterationsParameter.ActualValue; }
140      set { MaximumIterationsParameter.ActualValue = value; }
141    }
142    private DoubleValue Quality {
143      get { return QualityParameter.ActualValue; }
144      set { QualityParameter.ActualValue = value; }
145    }
146    private IRandom Random {
147      get { return RandomParameter.ActualValue; }
148      set { RandomParameter.ActualValue = value; }
149    }
150    private VariableCollection Results {
151      get { return ResultsParameter.ActualValue; }
152      set { ResultsParameter.ActualValue = value; }
153    }
154    private IntValue SampleSize {
155      get { return SampleSizeParameter.ActualValue; }
156      set { SampleSizeParameter.ActualValue = value; }
157    }
158    private ISolutionCreator SolutionCreator {
159      get { return SolutionCreatorParameter.ActualValue; }
160      set { SolutionCreatorParameter.ActualValue = value; }
161    }
162    #endregion
163
164    [StorableConstructor]
165    private ScatterSearchMainLoop(bool deserializing) : base(deserializing) { }
166    private ScatterSearchMainLoop(ScatterSearchMainLoop original, Cloner cloner) : base(original, cloner) { }
167    public ScatterSearchMainLoop() : base() { Initialize(); }
168
169    public override IDeepCloneable Clone(Cloner cloner) {
170      return new ScatterSearchMainLoop(this, cloner);
171    }
172
173    private void Initialize() {
174      #region Create parameters
175      Parameters.Add(new ValueLookupParameter<IMultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves."));
176      Parameters.Add(new ValueLookupParameter<ICrossover>("Crossover", "The operator used to combine solutions."));
177      Parameters.Add(new ValueLookupParameter<IOperator>("Improver", "The operator used to improve solutions."));
178      Parameters.Add(new ValueLookupParameter<DiversityCalculator>("DiversityCalculator", "The operator used to calculate the diversity of two solutions."));
179      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
180      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
181      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
182      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
183      Parameters.Add(new ValueLookupParameter<IEvaluator>("Evaluator", "The operator which is used to evaluate new solutions."));
184      Parameters.Add(new ValueLookupParameter<IntValue>("Iterations", "The number of iterations performed."));
185      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
186      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
187      Parameters.Add(new ValueLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
188      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
189      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
190      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators."));
191      Parameters.Add(new ValueLookupParameter<ISolutionCreator>("SolutionCreator", "The operator which is used to create new solutions."));
192      #endregion
193
194      #region Create operators
195      Assigner assigner1 = new Assigner();
196      Assigner assigner2 = new Assigner();
197      ChildrenCreator childrenCreator = new ChildrenCreator();
198      Comparator iterationsChecker = new Comparator();
199      ConditionalBranch newSolutionsBranch = new ConditionalBranch();
200      ConditionalBranch terminateBranch = new ConditionalBranch();
201      IntCounter interationsCounter = new IntCounter();
202      MergingReducer mergingReducer = new MergingReducer();
203      OffspringProcessor offspringProcessor = new OffspringProcessor();
204      Placeholder analyzer = new Placeholder();
205      Placeholder crossover = new Placeholder();
206      Placeholder solutionEvaluator1 = new Placeholder();
207      Placeholder solutionEvaluator2 = new Placeholder();
208      Placeholder solutionImprover1 = new Placeholder();
209      Placeholder solutionImprover2 = new Placeholder();
210      PopulationRebuildMethod populationRebuildMethod = new PopulationRebuildMethod();
211      ResultsCollector resultsCollector = new ResultsCollector();
212      ReferenceSetUpdateMethod referenceSetUpdateMethod = new ReferenceSetUpdateMethod();
213      RightSelector rightSelector = new RightSelector();
214      SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod();
215      SolutionsCreator solutionsCreator = new SolutionsCreator();
216      SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
217      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
218      SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor();
219      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
220      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
221      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
222      #endregion
223
224      #region Create operator graph
225      OperatorGraph.InitialOperator = interationsCounter;
226      assigner1.Name = "NewSolutions = true";
227      assigner1.LeftSideParameter.ActualName = "NewSolutions";
228      assigner1.RightSideParameter.Value = new BoolValue(true);
229      assigner1.Successor = newSolutionsBranch;
230
231      assigner2.Name = "NewSolutions = false";
232      assigner2.LeftSideParameter.ActualName = "NewSolutions";
233      assigner2.RightSideParameter.Value = new BoolValue(false);
234      assigner2.Successor = uniformSubScopesProcessor1;
235
236      childrenCreator.Name = "SubsetGenerator";
237      childrenCreator.ParentsPerChildParameter.Value = new IntValue(2);
238      childrenCreator.Successor = assigner2;
239
240      iterationsChecker.Name = "IterationsChecker";
241      iterationsChecker.Comparison.Value = ComparisonType.GreaterOrEqual;
242      iterationsChecker.LeftSideParameter.ActualName = "Iterations";
243      iterationsChecker.RightSideParameter.ActualName = "MaximumIterations";
244      iterationsChecker.ResultParameter.ActualName = "Terminate";
245      iterationsChecker.Successor = terminateBranch;
246
247      solutionImprover2.Name = "SolutionImprover";
248      solutionImprover2.OperatorParameter.ActualName = "Improver";
249      solutionImprover2.Successor = solutionEvaluator2;
250
251      solutionEvaluator2.Name = "SolutionEvaluator";
252      solutionEvaluator2.OperatorParameter.ActualName = "Evaluator";
253      solutionEvaluator2.Successor = null;
254
255      newSolutionsBranch.Name = "NewSolutionChecker";
256      newSolutionsBranch.ConditionParameter.ActualName = "NewSolutions";
257      newSolutionsBranch.TrueBranch = subScopesProcessor1;
258      newSolutionsBranch.FalseBranch = populationRebuildMethod;
259      newSolutionsBranch.Successor = null;
260
261      terminateBranch.Name = "TerminateChecker";
262      terminateBranch.ConditionParameter.ActualName = "Terminate";
263      terminateBranch.TrueBranch = new EmptyOperator();
264      terminateBranch.FalseBranch = referenceSetUpdateMethod;
265      terminateBranch.Successor = null;
266
267      interationsCounter.Name = "IterationCounter";
268      interationsCounter.IncrementParameter.Value = new IntValue(1);
269      interationsCounter.ValueParameter.ActualName = "Iterations";
270      interationsCounter.Successor = resultsCollector;
271
272      offspringProcessor.Successor = rightSelector;
273
274      rightSelector.NumberOfSelectedSubScopesParameter.Value = new IntValue(1);
275      rightSelector.CopySelected = new BoolValue(false);
276      rightSelector.Successor = subScopesProcessor2;
277
278      analyzer.Name = "Analyzer";
279      analyzer.OperatorParameter.ActualName = "Analyzer";
280
281      crossover.Name = "Crossover";
282      crossover.OperatorParameter.ActualName = "Crossover";
283      crossover.Successor = offspringProcessor;
284
285      solutionImprover1.Name = "SolutionImprover";
286      solutionImprover1.OperatorParameter.ActualName = "Improver";
287      solutionImprover1.Successor = solutionEvaluator1;
288
289      solutionEvaluator1.Name = "SolutionEvaluator";
290      solutionEvaluator1.OperatorParameter.ActualName = "Evaluator";
291      solutionEvaluator1.Successor = null;
292
293      populationRebuildMethod.Successor = subScopesProcessor3;
294
295      resultsCollector.CopyValue = new BoolValue(false);
296      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
297      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameter.Name, null, BestKnownQualityParameter.Name));
298      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
299      resultsCollector.Successor = iterationsChecker;
300
301      referenceSetUpdateMethod.Successor = assigner1;
302
303      solutionPoolUpdateMethod.Successor = analyzer;
304
305      solutionsCreator.Name = "DiversificationGenerationMethod";
306      solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
307      solutionsCreator.Successor = uniformSubScopesProcessor3;
308
309      subScopesProcessor1.DepthParameter.Value = new IntValue(1);
310      subScopesProcessor1.Operators.Add(new EmptyOperator());
311      subScopesProcessor1.Operators.Add(childrenCreator);
312      subScopesProcessor1.Successor = newSolutionsBranch;
313
314      subScopesProcessor2.DepthParameter.Value = new IntValue(1);
315      subScopesProcessor2.Operators.Add(new EmptyOperator());
316      subScopesProcessor2.Operators.Add(uniformSubScopesProcessor2);
317      subScopesProcessor2.Successor = mergingReducer;
318
319      subScopesProcessor3.DepthParameter.Value = new IntValue(1);
320      subScopesProcessor3.Operators.Add(solutionsCreator);
321      subScopesProcessor3.Operators.Add(new EmptyOperator());
322      subScopesProcessor3.Successor = interationsCounter;
323
324      uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1);
325      uniformSubScopesProcessor1.Operator = crossover;
326      uniformSubScopesProcessor1.Successor = solutionPoolUpdateMethod;
327
328      uniformSubScopesProcessor2.DepthParameter.Value = new IntValue(2);
329      uniformSubScopesProcessor2.Operator = solutionImprover1;
330      uniformSubScopesProcessor2.Successor = null;
331
332      uniformSubScopesProcessor3.DepthParameter.Value = new IntValue(1);
333      uniformSubScopesProcessor3.Operator = solutionImprover2;
334      uniformSubScopesProcessor3.Successor = null;
335      #endregion
336    }
337
338    public override IOperation Apply() {
339      return base.Apply();
340    }
341  }
342}
Note: See TracBrowser for help on using the repository browser.