Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1331: Scatter Search initial commit

File size: 13.2 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.Algorithms.LocalSearch;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Algorithms.ScatterSearch {
33  /// <summary>
34  /// An operator which represents a scatter search.
35  /// </summary>
36  [Item("ScatterSearchMainLoop", "An operator which represents the main loop of a scatter search.")]
37  [StorableClass]
38  public sealed class ScatterSearchMainLoop : AlgorithmOperator {
39    #region Parameter properties
40    internal LookupParameter<IRandom> RandomParameter {
41      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
42    }
43    internal LookupParameter<IntValue> IterationsParameter {
44      get { return (LookupParameter<IntValue>)Parameters["Iterations"]; }
45    }
46    internal LookupParameter<IntValue> MaximumIterationsParameter {
47      get { return (LookupParameter<IntValue>)Parameters["MaximumIterations"]; }
48    }
49    internal LookupParameter<IntValue> SampleSizeParameter {
50      get { return (LookupParameter<IntValue>)Parameters["SampleSize"]; }
51    }
52    internal LookupParameter<IntValue> PopulationSizeParameter {
53      get { return (LookupParameter<IntValue>)Parameters["PopulationSize"]; }
54    }
55    internal LookupParameter<IntValue> ReferenceSetSizeParameter {
56      get { return (LookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
57    }
58    internal LookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
59      get { return (LookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
60    }
61    internal LookupParameter<VariableCollection> ResultsParameter {
62      get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
63    }
64    internal LookupParameter<IMultiAnalyzer> AnalyzerParameter {
65      get { return (LookupParameter<IMultiAnalyzer>)Parameters["Analyzer"]; }
66    }
67    #endregion
68
69    #region Properties
70    public IRandom Random {
71      get { return RandomParameter.ActualValue; }
72      set { RandomParameter.ActualValue = value; }
73    }
74    public IntValue Iterations {
75      get { return IterationsParameter.ActualValue; }
76      set { IterationsParameter.ActualValue = value; }
77    }
78    public IntValue MaximumIterations {
79      get { return MaximumIterationsParameter.ActualValue; }
80      set { MaximumIterationsParameter.ActualValue = value; }
81    }
82    public IntValue SampleSize {
83      get { return SampleSizeParameter.ActualValue; }
84      set { SampleSizeParameter.ActualValue = value; }
85    }
86    public IntValue PopulationSize {
87      get { return PopulationSizeParameter.ActualValue; }
88      set { PopulationSizeParameter.ActualValue = value; }
89    }
90    public IntValue ReferenceSetSize {
91      get { return ReferenceSetSizeParameter.ActualValue; }
92      set { ReferenceSetSizeParameter.ActualValue = value; }
93    }
94    public IntValue NumberOfHighQualitySolutions {
95      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
96      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
97    }
98    public VariableCollection Results {
99      get { return ResultsParameter.ActualValue; }
100      set { ResultsParameter.ActualValue = value; }
101    }
102    public IMultiAnalyzer Analyzer {
103      get { return AnalyzerParameter.ActualValue; }
104      set { AnalyzerParameter.ActualValue = value; }
105    }
106    #endregion
107
108    [StorableConstructor]
109    private ScatterSearchMainLoop(bool deserializing) : base(deserializing) { }
110    private ScatterSearchMainLoop(ScatterSearchMainLoop original, Cloner cloner) : base(original, cloner) { }
111    public ScatterSearchMainLoop() : base() { Initialize(); }
112
113    public override IDeepCloneable Clone(Cloner cloner) {
114      return new ScatterSearchMainLoop(this, cloner);
115    }
116
117    private void Initialize() {
118      #region Create parameters
119      Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
120      Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations performed."));
121      Parameters.Add(new LookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
122      Parameters.Add(new LookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators."));
123      Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population."));
124      Parameters.Add(new LookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
125      Parameters.Add(new LookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
126      Parameters.Add(new LookupParameter<IOperator>("SolutionCreator", "The operator which is used to create new solutions."));
127      Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator which is used to evaluate new solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
128      Parameters.Add(new LookupParameter<IOperator>("Improver", "The operator which is used to improve new solutions. This operator is executed in parallelm, if an engine is used which supports parallelization."));
129      Parameters.Add(new LookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
130      Parameters.Add(new LookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves."));
131      Parameters.Add(new LookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
132      Parameters.Add(new LookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move."));
133      Parameters.Add(new LookupParameter<IMultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves."));
134      #endregion
135
136      #region Create operators
137      Assigner assigner1 = new Assigner();
138      Assigner assigner2 = new Assigner();
139      ChildrenCreator childrenCreator = new ChildrenCreator();
140      Comparator iterationsChecker = new Comparator();
141      ConditionalBranch newSolutionsBranch = new ConditionalBranch();
142      ConditionalBranch terminateBranch = new ConditionalBranch();
143      IntCounter interationsCounter = new IntCounter();
144      LocalSearchImprovementOperator localImprovementOperator = new LocalSearchImprovementOperator();
145      Placeholder solutionImprover = new Placeholder();
146      Placeholder solutionEvaluator = new Placeholder();
147      PopulationRebuildMethod populationRebuildMethod = new PopulationRebuildMethod();
148      ResultsCollector resultsCollector = new ResultsCollector();
149      ReferenceSetUpdateMethod referenceSetUpdateMethod = new ReferenceSetUpdateMethod();
150      SolutionCombinationMethod solutionCombinationMethod = new SolutionCombinationMethod();
151      SolutionPoolUpdateMethod solutionPoolUpdateMethod = new SolutionPoolUpdateMethod();
152      SolutionsCreator solutionsCreator = new SolutionsCreator();
153      SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
154      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
155      SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor();
156      UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
157      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
158      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
159      #endregion
160
161      #region Create operator graph
162      OperatorGraph.InitialOperator = interationsCounter;
163      assigner1.Name = "NewSolutions = true";
164      assigner1.LeftSideParameter.ActualName = "NewSolutions";
165      assigner1.RightSideParameter.Value = new BoolValue(true);
166      assigner1.Successor = newSolutionsBranch;
167
168      assigner2.Name = "NewSolutions = false";
169      assigner2.LeftSideParameter.ActualName = "NewSolutions";
170      assigner2.RightSideParameter.Value = new BoolValue(false);
171      assigner2.Successor = uniformSubScopesProcessor1;
172
173      childrenCreator.Name = "SubsetGenerator";
174      childrenCreator.ParentsPerChildParameter.Value = new IntValue(2);
175      childrenCreator.Successor = assigner2;
176
177      iterationsChecker.Name = "IterationsChecker";
178      iterationsChecker.Comparison.Value = ComparisonType.GreaterOrEqual;
179      iterationsChecker.LeftSideParameter.ActualName = "Iterations";
180      iterationsChecker.RightSideParameter.ActualName = "MaximumIterations";
181      iterationsChecker.ResultParameter.ActualName = "Terminate";
182      iterationsChecker.Successor = terminateBranch;
183
184      localImprovementOperator.Name = "ImprovementMethod";
185      localImprovementOperator.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
186      localImprovementOperator.SampleSizeParameter.ActualName = SampleSizeParameter.Name;
187      localImprovementOperator.Successor = null;
188
189      newSolutionsBranch.Name = "NewSolutionChecker";
190      newSolutionsBranch.ConditionParameter.ActualName = "NewSolutions";
191      newSolutionsBranch.TrueBranch = subScopesProcessor1;
192      newSolutionsBranch.FalseBranch = populationRebuildMethod;
193      newSolutionsBranch.Successor = null;
194
195      terminateBranch.Name = "TerminateChecker";
196      terminateBranch.ConditionParameter.ActualName = "Terminate";
197      terminateBranch.TrueBranch = new EmptyOperator();
198      terminateBranch.FalseBranch = referenceSetUpdateMethod;
199      terminateBranch.Successor = null;
200
201      interationsCounter.Name = "IterationCounter";
202      interationsCounter.IncrementParameter.Value = new IntValue(1);
203      interationsCounter.ValueParameter.ActualName = "Iterations";
204      interationsCounter.Successor = resultsCollector;
205
206      solutionImprover.Name = "SolutionImprover";
207      solutionImprover.OperatorParameter.ActualName = "LocalImprovementOperator";
208      solutionImprover.Successor = solutionEvaluator;
209
210      solutionEvaluator.Name = "SolutionEvaluator";
211      solutionEvaluator.OperatorParameter.ActualName = "Evaluator";
212      solutionEvaluator.Successor = null;
213
214      populationRebuildMethod.Successor = subScopesProcessor3;
215
216      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
217      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
218      resultsCollector.Successor = iterationsChecker;
219
220      referenceSetUpdateMethod.Successor = assigner1;
221
222      solutionCombinationMethod.Successor = subScopesProcessor2;
223
224      solutionsCreator.Name = "DiversificationGenerationMethod";
225      solutionsCreator.NumberOfSolutionsParameter.ActualName = "PopulationSize";
226      solutionsCreator.Successor = uniformSubScopesProcessor3;
227
228      subScopesProcessor1.DepthParameter.Value = new IntValue(1);
229      subScopesProcessor1.Operators.Add(new EmptyOperator());
230      subScopesProcessor1.Operators.Add(childrenCreator);
231      subScopesProcessor1.Successor = newSolutionsBranch;
232
233      subScopesProcessor2.DepthParameter.Value = new IntValue(1);
234      subScopesProcessor2.Operators.Add(new EmptyOperator());
235      subScopesProcessor2.Operators.Add(new EmptyOperator());
236      subScopesProcessor2.Operators.Add(uniformSubScopesProcessor2);
237      subScopesProcessor2.Successor = null;
238
239      subScopesProcessor3.DepthParameter.Value = new IntValue(1);
240      subScopesProcessor3.Operators.Add(solutionsCreator);
241      subScopesProcessor3.Operators.Add(new EmptyOperator());
242      subScopesProcessor3.Successor = interationsCounter;
243
244      uniformSubScopesProcessor1.DepthParameter.Value = new IntValue(1);
245      uniformSubScopesProcessor1.Operator = solutionCombinationMethod;
246      uniformSubScopesProcessor1.Successor = solutionPoolUpdateMethod;
247
248      uniformSubScopesProcessor2.DepthParameter.Value = new IntValue(1);
249      uniformSubScopesProcessor2.Operator = solutionImprover;
250      uniformSubScopesProcessor2.Successor = null;
251
252      uniformSubScopesProcessor3.DepthParameter.Value = new IntValue(1);
253      uniformSubScopesProcessor3.Operator = localImprovementOperator;
254      uniformSubScopesProcessor3.Successor = null;
255      #endregion
256    }
257
258    public override IOperation Apply() {
259      return base.Apply();
260    }
261  }
262}
Note: See TracBrowser for help on using the repository browser.