1 | using HeuristicLab.Algorithms.ALPS;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Optimization.Operators;
|
---|
8 | using HeuristicLab.Parameters;
|
---|
9 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
10 | using HeuristicLab.Selection;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.Algorithms.IslandALPS {
|
---|
13 | [Item("IslandALPSAlgorithmMainLoop", "An island ALPS main loop operator.")]
|
---|
14 | [StorableClass]
|
---|
15 | public class IslandAlpsAlgorithmMainLoop : AlgorithmOperator {
|
---|
16 | private const string LayerResultsParametername = "LayerResults";
|
---|
17 | private const string GenerationsParametername = "Generations";
|
---|
18 | private const string IslandResultsParametername = "IslandResults";
|
---|
19 | private const string LayerParametername = "Layer";
|
---|
20 | private const string MigrationsParametername = "Migrations";
|
---|
21 | private const string OpenLayersParametername = "OpenLayers";
|
---|
22 | private const string GroupResultsParametername = "GroupResults";
|
---|
23 | private const string MigrationThresholdParametername = "MigrationThreshold";
|
---|
24 | private const string MigrateParametername = "Migrate";
|
---|
25 | private const string LayerEvaluatedSolutionsParameterName = "LayerEvaluatedSolutions";
|
---|
26 |
|
---|
27 | [StorableConstructor]
|
---|
28 | public IslandAlpsAlgorithmMainLoop(bool deserializing) : base(deserializing) {}
|
---|
29 |
|
---|
30 | #region Parameter Properties
|
---|
31 |
|
---|
32 | public ValueLookupParameter<IRandom> GlobalRandomParameter {
|
---|
33 | get { return (ValueLookupParameter<IRandom>) Parameters["GlobalRandom"]; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public ValueLookupParameter<IRandom> IslandRandomParameter {
|
---|
37 | get { return (ValueLookupParameter<IRandom>) Parameters["IslandRandom"]; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ValueLookupParameter<IRandom> LayerRandomParameter {
|
---|
41 | get { return (ValueLookupParameter<IRandom>) Parameters["LayerRandom"]; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public ValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
45 | get { return (ValueLookupParameter<BoolValue>) Parameters["Maximization"]; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
49 | get { return (ScopeTreeLookupParameter<DoubleValue>) Parameters["Quality"]; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
|
---|
53 | get { return (ValueLookupParameter<DoubleValue>) Parameters["BestKnownQuality"]; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | public ValueLookupParameter<IntValue> PopulationSizeParameter {
|
---|
57 | get { return (ValueLookupParameter<IntValue>) Parameters["PopulationSize"]; }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public ValueLookupParameter<IOperator> SelectorParameter {
|
---|
61 | get { return (ValueLookupParameter<IOperator>) Parameters["Selector"]; }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public ValueLookupParameter<IOperator> CrossoverParameter {
|
---|
65 | get { return (ValueLookupParameter<IOperator>) Parameters["Crossover"]; }
|
---|
66 | }
|
---|
67 |
|
---|
68 | public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
|
---|
69 | get { return (ValueLookupParameter<PercentValue>) Parameters["MutationProbability"]; }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public ValueLookupParameter<IOperator> MutatorParameter {
|
---|
73 | get { return (ValueLookupParameter<IOperator>) Parameters["Mutator"]; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public ValueLookupParameter<IOperator> EvaluatorParameter {
|
---|
77 | get { return (ValueLookupParameter<IOperator>) Parameters["Evaluator"]; }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public ValueLookupParameter<IntValue> ElitesParameter {
|
---|
81 | get { return (ValueLookupParameter<IntValue>) Parameters["Elites"]; }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
|
---|
85 | get { return (IValueLookupParameter<BoolValue>) Parameters["ReevaluateElites"]; }
|
---|
86 | }
|
---|
87 |
|
---|
88 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
89 | get { return (ValueLookupParameter<ResultCollection>) Parameters["Results"]; }
|
---|
90 | }
|
---|
91 |
|
---|
92 | public ILookupParameter<ITerminator> TerminatorParameter {
|
---|
93 | get { return (ILookupParameter<ITerminator>) Parameters["Terminator"]; }
|
---|
94 | }
|
---|
95 |
|
---|
96 | public ValueLookupParameter<IOperator> AnalyzerParameter {
|
---|
97 | get { return (ValueLookupParameter<IOperator>) Parameters["Analyzer"]; }
|
---|
98 | }
|
---|
99 |
|
---|
100 | public ValueLookupParameter<IOperator> IslandAnalyzerParameter {
|
---|
101 | get { return (ValueLookupParameter<IOperator>) Parameters["IslandAnalyzer"]; }
|
---|
102 | }
|
---|
103 |
|
---|
104 | public ValueLookupParameter<IOperator> LayerAnalyzerParameter {
|
---|
105 | get { return (ValueLookupParameter<IOperator>) Parameters["LayerAnalyzer"]; }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public ValueLookupParameter<IOperator> GroupAnalyzerParameter {
|
---|
109 | get { return (ValueLookupParameter<IOperator>) Parameters["GroupAnalyzer"]; }
|
---|
110 | }
|
---|
111 |
|
---|
112 | public LookupParameter<IntValue> LayerEvaluatedSolutionsParameter {
|
---|
113 | get { return (LookupParameter<IntValue>) Parameters[LayerEvaluatedSolutionsParameterName]; }
|
---|
114 | }
|
---|
115 |
|
---|
116 | public LookupParameter<IntValue> EvaluatedSolutions {
|
---|
117 | get { return (LookupParameter<IntValue>) Parameters["EvaluatedSolutions"]; }
|
---|
118 | }
|
---|
119 |
|
---|
120 | #region island
|
---|
121 |
|
---|
122 | public ValueLookupParameter<IntValue> NumberOfIslandsParameter {
|
---|
123 | get { return (ValueLookupParameter<IntValue>) Parameters["NumberOfIslands"]; }
|
---|
124 | }
|
---|
125 |
|
---|
126 | public ValueLookupParameter<IntValue> MigrationIntervalParameter {
|
---|
127 | get { return (ValueLookupParameter<IntValue>) Parameters["MigrationInterval"]; }
|
---|
128 | }
|
---|
129 |
|
---|
130 | public ValueLookupParameter<PercentValue> MigrationRateParameter {
|
---|
131 | get { return (ValueLookupParameter<PercentValue>) Parameters["MigrationRate"]; }
|
---|
132 | }
|
---|
133 |
|
---|
134 | public ValueLookupParameter<IOperator> MigratorParameter {
|
---|
135 | get { return (ValueLookupParameter<IOperator>) Parameters["Migrator"]; }
|
---|
136 | }
|
---|
137 |
|
---|
138 | public ValueLookupParameter<IOperator> EmigrantsSelectorParameter {
|
---|
139 | get { return (ValueLookupParameter<IOperator>) Parameters["EmigrantsSelector"]; }
|
---|
140 | }
|
---|
141 |
|
---|
142 | public ValueLookupParameter<IOperator> ImmigrationReplacerParameter {
|
---|
143 | get { return (ValueLookupParameter<IOperator>) Parameters["ImmigrationReplacer"]; }
|
---|
144 | }
|
---|
145 |
|
---|
146 | public ValueLookupParameter<BoolValue> Migrate {
|
---|
147 | get { return (ValueLookupParameter<BoolValue>) Parameters[MigrateParametername]; }
|
---|
148 | }
|
---|
149 |
|
---|
150 | public LookupParameter<IntValue> IslandEvaluatedSolutions {
|
---|
151 | get { return (LookupParameter<IntValue>) Parameters["IslandEvaluatedSolutions"]; }
|
---|
152 | }
|
---|
153 |
|
---|
154 | #endregion
|
---|
155 |
|
---|
156 | #region alps
|
---|
157 |
|
---|
158 | public ILookupParameter<IntValue> CurrentPopulationSizeParameter {
|
---|
159 | get { return (ILookupParameter<IntValue>) Parameters["CurrentPopulationSize"]; }
|
---|
160 | }
|
---|
161 |
|
---|
162 | public IValueLookupParameter<IntValue> NumberOfLayersParameter {
|
---|
163 | get { return (IValueLookupParameter<IntValue>) Parameters["NumberOfLayers"]; }
|
---|
164 | }
|
---|
165 |
|
---|
166 | public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
|
---|
167 | get { return (IScopeTreeLookupParameter<DoubleValue>) Parameters["Age"]; }
|
---|
168 | }
|
---|
169 |
|
---|
170 | public IValueLookupParameter<IntValue> AgeGapParameter {
|
---|
171 | get { return (IValueLookupParameter<IntValue>) Parameters["AgeGap"]; }
|
---|
172 | }
|
---|
173 |
|
---|
174 | public IValueLookupParameter<DoubleValue> AgeInheritanceParameter {
|
---|
175 | get { return (IValueLookupParameter<DoubleValue>) Parameters["AgeInheritance"]; }
|
---|
176 | }
|
---|
177 |
|
---|
178 | public IValueLookupParameter<IntArray> AgeLimitsParameter {
|
---|
179 | get { return (IValueLookupParameter<IntArray>) Parameters["AgeLimits"]; }
|
---|
180 | }
|
---|
181 |
|
---|
182 | public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
|
---|
183 | get { return (IValueLookupParameter<IntValue>) Parameters["MatingPoolRange"]; }
|
---|
184 | }
|
---|
185 |
|
---|
186 | public IValueLookupParameter<BoolValue> ReduceToPopulationSizeParameter {
|
---|
187 | get { return (IValueLookupParameter<BoolValue>) Parameters["ReduceToPopulationSize"]; }
|
---|
188 | }
|
---|
189 |
|
---|
190 | public IValueLookupParameter<BoolValue> PlusSelectionParameter {
|
---|
191 | get { return (IValueLookupParameter<BoolValue>) Parameters["PlusSelection"]; }
|
---|
192 | }
|
---|
193 |
|
---|
194 | #endregion
|
---|
195 |
|
---|
196 | #endregion
|
---|
197 |
|
---|
198 | public IslandAlpsAlgorithmMainLoop(IslandAlpsAlgorithmMainLoop original, Cloner cloner) :
|
---|
199 | base(original, cloner) {}
|
---|
200 |
|
---|
201 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
202 | return new IslandAlpsAlgorithmMainLoop(this, cloner);
|
---|
203 | }
|
---|
204 |
|
---|
205 | public IslandAlpsAlgorithmMainLoop() {
|
---|
206 | AddParameters();
|
---|
207 |
|
---|
208 | #region create Operators
|
---|
209 |
|
---|
210 | var globalVariableCreator = new VariableCreator {Name = "Create global values"};
|
---|
211 | var islandVarCreatorUssp = new UniformSubScopesProcessor();
|
---|
212 | var islandVariableCreator = new VariableCreator {Name = "Initialize Results"};
|
---|
213 | var groupVariableCreator = new VariableCreator {Name = "Initialize Group Results"};
|
---|
214 |
|
---|
215 | var layerUssp = new UniformSubScopesProcessor();
|
---|
216 | var layerVariableCreator = new VariableCreator();
|
---|
217 |
|
---|
218 | var initLayerAnalyzerPlaceholder = new Placeholder {Name = "Layer Analyzer (Placeholder)"};
|
---|
219 | var initIslandAnalyzerPlaceholder = new Placeholder {Name = "Island Analyzer (Placeholder)"};
|
---|
220 | var initGlobalAnalyzerPlacerholder = new Placeholder {Name = "Global Analyzer (Placeholder)"};
|
---|
221 | var resultsCollector = new ResultsCollector();
|
---|
222 |
|
---|
223 | var processIslandsUssp = new UniformSubScopesProcessor {Name = "Process Islands", Parallel = new BoolValue(true)};
|
---|
224 | var initIslandEvaluationsAss = new Assigner {Name = "Init Island Evaluations"};
|
---|
225 |
|
---|
226 | var incrementGenerationDr = new IntCounter {Name = "Increment Generations"};
|
---|
227 | var incrementEvaluatedSolutionDr = new DataReducer {Name = "Increment Evaluated Solutions"};
|
---|
228 |
|
---|
229 | var elderMigrator = CreateEldersEmigrator();
|
---|
230 | var newLayerOpener = CreateLayerOpener();
|
---|
231 | var reseeder = CreateReseeder();
|
---|
232 |
|
---|
233 | var analyzeLayerUssp = new UniformSubScopesProcessor();
|
---|
234 |
|
---|
235 | var layerAnalyzerPlaceholder = new Placeholder {Name = "Layer Analyzer (Placeholder)"};
|
---|
236 | var layerResultsCollector = new ResultsCollector {Name = "Collect Additional Infos"};
|
---|
237 | var islandAnalyzerPlaceholder = new Placeholder {Name = "Island Analyzer (Placeholder)"};
|
---|
238 | var islandResultsCollector = new ResultsCollector {Name = "Collect layer results into IslandResults"};
|
---|
239 |
|
---|
240 | var globalAnalyzerPlacerholder = new Placeholder {Name = "Global Analyzer (Placeholder)"};
|
---|
241 |
|
---|
242 | var groupingOperator = new GroupedLayerOperator {Name = "Grouped Analyzer"};
|
---|
243 | var groupAnalyzer = new Placeholder {Name = "Group Analyzer (Placeholder)"};
|
---|
244 | var groupResultsExtractor = new ResultsExtractor {Name = "Collect group results into variable"};
|
---|
245 | var groupResultsCollector = new ResultsCollector {Name = "Collect group results into into global results"};
|
---|
246 | var groupLayerNumberResultsCollector = new ResultsCollector {Name = "Add Layernumber to Results"};
|
---|
247 |
|
---|
248 | var matingPoolCreator = new MatingPoolCreator();
|
---|
249 | var matingPoolUssp = new UniformSubScopesProcessor {Name = "Process Mating Pools"};
|
---|
250 | var alpsMainOperator = new AlpsGeneticAlgorithmMainOperator();
|
---|
251 |
|
---|
252 | var setIslandEvaluatedSolutions = new DataReducer {Name = "Set IslandEvaluatedSolutions"};
|
---|
253 |
|
---|
254 | var migrationThresholdCounter = new IntCounter {Name = "Increment Counter for Migrations"};
|
---|
255 | var migrationThresholdAss = new Assigner {Name = "Reset Counter for Migrations"};
|
---|
256 | var migrationCounter = new IntCounter {Name = "Increment Migrations"};
|
---|
257 | var selectforMigrationUssp = new UniformSubScopesProcessor();
|
---|
258 | var emigrantSelector = new Placeholder {Name = "Emigrant Selector (Placeholder)"};
|
---|
259 | var migrator = new LayerMigrator();
|
---|
260 | var replaceforMigrationUssp = new UniformSubScopesProcessor();
|
---|
261 | var immigrantSelector = new Placeholder {Name = "Immigrant Replacer (Placeholder)"};
|
---|
262 |
|
---|
263 | var migrateComparator = new Comparator();
|
---|
264 | var migrateCondBranch = new ConditionalBranch {Name = "Migrate?"};
|
---|
265 |
|
---|
266 | var terminator = new TerminationOperator();
|
---|
267 |
|
---|
268 | #endregion
|
---|
269 |
|
---|
270 | globalVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(GenerationsParametername, new IntValue(1)));
|
---|
271 | globalVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(MigrationsParametername, new IntValue(0)));
|
---|
272 |
|
---|
273 | islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(OpenLayersParametername, new IntValue(1)));
|
---|
274 | islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(IslandResultsParametername));
|
---|
275 |
|
---|
276 | layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(LayerParametername, new IntValue(0)));
|
---|
277 | layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(LayerResultsParametername));
|
---|
278 |
|
---|
279 | groupVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(GroupResultsParametername));
|
---|
280 | initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
281 | initIslandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
|
---|
282 | initGlobalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
283 |
|
---|
284 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(GenerationsParametername));
|
---|
285 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(IslandResultsParametername, "", IslandResultsParametername));
|
---|
286 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(GroupResultsParametername, "", GroupResultsParametername));
|
---|
287 | resultsCollector.CollectedValues.Add(new ValueLookupParameter<IntValue>(MigrationsParametername));
|
---|
288 | resultsCollector.CopyValue = new BoolValue(false);
|
---|
289 |
|
---|
290 | initIslandEvaluationsAss.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
|
---|
291 | initIslandEvaluationsAss.RightSideParameter.Value = new IntValue(0);
|
---|
292 |
|
---|
293 | incrementGenerationDr.ValueParameter.ActualName = GenerationsParametername;
|
---|
294 |
|
---|
295 | incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
|
---|
296 | incrementEvaluatedSolutionDr.TargetParameter.ActualName = EvaluatedSolutions.Name;
|
---|
297 | incrementEvaluatedSolutionDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
298 | incrementEvaluatedSolutionDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
|
---|
299 |
|
---|
300 | setIslandEvaluatedSolutions.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name;
|
---|
301 | setIslandEvaluatedSolutions.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
302 | setIslandEvaluatedSolutions.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
|
---|
303 | setIslandEvaluatedSolutions.TargetParameter.ActualName = IslandEvaluatedSolutions.Name;
|
---|
304 |
|
---|
305 |
|
---|
306 | migrationThresholdCounter.ValueParameter.ActualName = MigrationThresholdParametername;
|
---|
307 |
|
---|
308 | migrateComparator.Comparison.Value = ComparisonType.GreaterOrEqual;
|
---|
309 | migrateComparator.LeftSideParameter.ActualName = MigrationThresholdParametername;
|
---|
310 | migrateComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
|
---|
311 | migrateComparator.ResultParameter.ActualName = MigrateParametername;
|
---|
312 |
|
---|
313 | migrateCondBranch.ConditionParameter.ActualName = MigrateParametername;
|
---|
314 |
|
---|
315 | migrationCounter.ValueParameter.ActualName = MigrationsParametername;
|
---|
316 | migrationThresholdAss.LeftSideParameter.ActualName = MigrationThresholdParametername;
|
---|
317 | migrationThresholdAss.RightSideParameter.Value = new IntValue(0);
|
---|
318 |
|
---|
319 | selectforMigrationUssp.Depth = new IntValue(2);
|
---|
320 | emigrantSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
|
---|
321 |
|
---|
322 | replaceforMigrationUssp.Depth = new IntValue(2);
|
---|
323 | immigrantSelector.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
|
---|
324 |
|
---|
325 | groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name;
|
---|
326 | groupLayerNumberResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("LayerNumber"));
|
---|
327 | groupLayerNumberResultsCollector.ResultsParameter.ActualName = GroupResultsParametername;
|
---|
328 |
|
---|
329 | layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
330 | layerResultsCollector.ResultsParameter.ActualName = LayerResultsParametername;
|
---|
331 | layerResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(LayerParametername));
|
---|
332 | islandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
|
---|
333 | islandResultsCollector.ResultsParameter.ActualName = IslandResultsParametername;
|
---|
334 | islandResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(LayerResultsParametername));
|
---|
335 | globalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
336 |
|
---|
337 | groupResultsExtractor.SourceNameParameter.Value = new StringValue("GroupScope");
|
---|
338 | groupResultsExtractor.TargetNameParameter.Value = new StringValue(GroupResultsParametername);
|
---|
339 | groupResultsCollector.CollectedValues.Add(new LookupParameter<ItemArray<ResultCollection>>(GroupResultsParametername));
|
---|
340 | matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
|
---|
341 |
|
---|
342 | ParemetrizeMainOperator(alpsMainOperator);
|
---|
343 |
|
---|
344 | //flow
|
---|
345 | OperatorGraph.InitialOperator = globalVariableCreator;
|
---|
346 | globalVariableCreator.Successor = islandVarCreatorUssp;
|
---|
347 | islandVarCreatorUssp.Operator = islandVariableCreator;
|
---|
348 | islandVariableCreator.Successor = layerUssp;
|
---|
349 | layerUssp.Operator = layerVariableCreator;
|
---|
350 | layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
|
---|
351 | initLayerAnalyzerPlaceholder.Successor = null;
|
---|
352 | layerUssp.Successor = initIslandAnalyzerPlaceholder;
|
---|
353 | initLayerAnalyzerPlaceholder.Successor = null;
|
---|
354 | islandVarCreatorUssp.Successor = initGlobalAnalyzerPlacerholder;
|
---|
355 | initGlobalAnalyzerPlacerholder.Successor = resultsCollector;
|
---|
356 | resultsCollector.Successor = processIslandsUssp;
|
---|
357 | processIslandsUssp.Operator = initIslandEvaluationsAss;
|
---|
358 | initIslandEvaluationsAss.Successor = matingPoolCreator;
|
---|
359 | matingPoolCreator.Successor = matingPoolUssp;
|
---|
360 | matingPoolUssp.Operator = alpsMainOperator;
|
---|
361 | alpsMainOperator.Successor = null;
|
---|
362 | matingPoolUssp.Successor = elderMigrator;
|
---|
363 | elderMigrator.Successor = newLayerOpener;
|
---|
364 | newLayerOpener.Successor = reseeder;
|
---|
365 | reseeder.Successor = analyzeLayerUssp;
|
---|
366 | analyzeLayerUssp.Operator = layerAnalyzerPlaceholder;
|
---|
367 | layerAnalyzerPlaceholder.Successor = layerResultsCollector;
|
---|
368 | layerResultsCollector.Successor = null;
|
---|
369 |
|
---|
370 | analyzeLayerUssp.Successor = islandAnalyzerPlaceholder;
|
---|
371 | islandAnalyzerPlaceholder.Successor = islandResultsCollector;
|
---|
372 | islandResultsCollector.Successor = setIslandEvaluatedSolutions;
|
---|
373 | setIslandEvaluatedSolutions.Successor = null;
|
---|
374 |
|
---|
375 | processIslandsUssp.Successor = incrementGenerationDr;
|
---|
376 | incrementGenerationDr.Successor = incrementEvaluatedSolutionDr;
|
---|
377 | incrementEvaluatedSolutionDr.Successor = migrationThresholdCounter;
|
---|
378 |
|
---|
379 | migrationThresholdCounter.Successor = migrateComparator;
|
---|
380 |
|
---|
381 | migrateComparator.Successor = migrateCondBranch;
|
---|
382 | migrateCondBranch.FalseBranch = null;
|
---|
383 | migrateCondBranch.TrueBranch = migrationThresholdAss;
|
---|
384 | migrationThresholdAss.Successor = migrationCounter;
|
---|
385 |
|
---|
386 | migrationCounter.Successor = selectforMigrationUssp;
|
---|
387 | selectforMigrationUssp.Operator = emigrantSelector;
|
---|
388 | emigrantSelector.Successor = null;
|
---|
389 | selectforMigrationUssp.Successor = migrator;
|
---|
390 |
|
---|
391 | migrator.Successor = replaceforMigrationUssp;
|
---|
392 | replaceforMigrationUssp.Operator = immigrantSelector;
|
---|
393 | immigrantSelector.Successor = null;
|
---|
394 | replaceforMigrationUssp.Successor = null;
|
---|
395 |
|
---|
396 | migrateCondBranch.Successor = globalAnalyzerPlacerholder;
|
---|
397 |
|
---|
398 |
|
---|
399 | globalAnalyzerPlacerholder.Successor = groupingOperator;
|
---|
400 | groupingOperator.Operator = groupAnalyzer;
|
---|
401 | groupAnalyzer.Successor = groupLayerNumberResultsCollector;
|
---|
402 | groupLayerNumberResultsCollector.Successor = null;
|
---|
403 | groupingOperator.Successor = groupResultsExtractor;
|
---|
404 | groupResultsExtractor.Successor = groupResultsCollector;
|
---|
405 | groupResultsCollector.Successor = terminator;
|
---|
406 | terminator.ContinueBranch = processIslandsUssp;
|
---|
407 | }
|
---|
408 |
|
---|
409 | private void ParemetrizeMainOperator(AlpsGeneticAlgorithmMainOperator alpsMainOperator) {
|
---|
410 | alpsMainOperator.RandomParameter.ActualName = LayerRandomParameter.Name;
|
---|
411 | alpsMainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
412 | alpsMainOperator.EvaluatedSolutionsParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
|
---|
413 | alpsMainOperator.QualityParameter.ActualName = QualityParameter.Name;
|
---|
414 | alpsMainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
415 | alpsMainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
416 | alpsMainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
417 | alpsMainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
418 | alpsMainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
|
---|
419 | alpsMainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
420 | alpsMainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
421 | alpsMainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
422 | alpsMainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
|
---|
423 | alpsMainOperator.AgeParameter.ActualName = AgeParameter.Name;
|
---|
424 | alpsMainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
425 | alpsMainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
|
---|
426 | }
|
---|
427 |
|
---|
428 | private void AddParameters() {
|
---|
429 | Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
|
---|
430 | Parameters.Add(new ValueLookupParameter<IRandom>("IslandRandom", "A pseudo random number generator."));
|
---|
431 | Parameters.Add(new ValueLookupParameter<IRandom>("LayerRandom", "A pseudo random number generator."));
|
---|
432 |
|
---|
433 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
434 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
435 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
|
---|
436 |
|
---|
437 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of Layers per Island."));
|
---|
438 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
|
---|
439 | Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
|
---|
440 | Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
|
---|
441 | Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
|
---|
442 | Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
|
---|
443 | Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
|
---|
444 | Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
|
---|
445 | Parameters.Add(new ValueLookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population of solutions."));
|
---|
446 |
|
---|
447 | Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
|
---|
448 | Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
|
---|
449 | Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
|
---|
450 | Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
|
---|
451 | Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
|
---|
452 | Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
|
---|
453 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
454 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
|
---|
455 | Parameters.Add(new ValueLookupParameter<ITerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
|
---|
456 |
|
---|
457 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
|
---|
458 | Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
|
---|
459 | Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
|
---|
460 | Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
|
---|
461 | Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation."));
|
---|
462 | Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
|
---|
463 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
|
---|
464 |
|
---|
465 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
|
---|
466 | Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
|
---|
467 | Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each Layer."));
|
---|
468 | Parameters.Add(new ValueLookupParameter<IOperator>("GroupAnalyzer", "The operator used to analyze each Layergroup."));
|
---|
469 |
|
---|
470 | Parameters.Add(new LookupParameter<IntValue>(LayerEvaluatedSolutionsParameterName, "The number of times a solution has been evaluated."));
|
---|
471 | Parameters.Add(new LookupParameter<IntValue>("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
|
---|
472 | Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
|
---|
473 |
|
---|
474 | Parameters.Add(new ValueLookupParameter<BoolValue>(MigrateParametername, "Migrate the island?"));
|
---|
475 | }
|
---|
476 |
|
---|
477 | private CombinedOperator CreateEldersEmigrator() {
|
---|
478 | var eldersEmigrator = new CombinedOperator {Name = "Emigrate Elders"};
|
---|
479 | var selectorProsessor = new UniformSubScopesProcessor();
|
---|
480 | var eldersSelector = new EldersSelector();
|
---|
481 | var shiftToRightMigrator = new UnidirectionalRingMigrator {Name = "Shift elders to next layer"};
|
---|
482 | var mergingProsessor = new UniformSubScopesProcessor();
|
---|
483 | var mergingReducer = new MergingReducer();
|
---|
484 | var subScopesCounter = new SubScopesCounter();
|
---|
485 | var reduceToPopulationSizeBranch = new ConditionalBranch {Name = "ReduceToPopulationSize?"};
|
---|
486 | var countCalculator = new ExpressionCalculator {Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)"};
|
---|
487 | var bestSelector = new BestSelector();
|
---|
488 | var rightReducer = new RightReducer();
|
---|
489 |
|
---|
490 | eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
|
---|
491 |
|
---|
492 | selectorProsessor.Operator = eldersSelector;
|
---|
493 | selectorProsessor.Successor = shiftToRightMigrator;
|
---|
494 |
|
---|
495 | eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
|
---|
496 | eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
|
---|
497 | eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
498 | eldersSelector.LayerParameter.ActualName = LayerParametername;
|
---|
499 | eldersSelector.Successor = null;
|
---|
500 |
|
---|
501 | shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
|
---|
502 | shiftToRightMigrator.Successor = mergingProsessor;
|
---|
503 |
|
---|
504 | mergingProsessor.Operator = mergingReducer;
|
---|
505 |
|
---|
506 | mergingReducer.Successor = subScopesCounter;
|
---|
507 |
|
---|
508 | subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
509 | subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
|
---|
510 | subScopesCounter.Successor = reduceToPopulationSizeBranch;
|
---|
511 |
|
---|
512 | reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
|
---|
513 | reduceToPopulationSizeBranch.TrueBranch = countCalculator;
|
---|
514 |
|
---|
515 | countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
|
---|
516 | countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
|
---|
517 | countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
|
---|
518 | countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
519 | countCalculator.Successor = bestSelector;
|
---|
520 |
|
---|
521 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
|
---|
522 | bestSelector.CopySelected = new BoolValue(false);
|
---|
523 | bestSelector.Successor = rightReducer;
|
---|
524 |
|
---|
525 | return eldersEmigrator;
|
---|
526 | }
|
---|
527 |
|
---|
528 | private CombinedOperator CreateLayerOpener() {
|
---|
529 | var layerOpener = new CombinedOperator {Name = "Open new Layer if needed"};
|
---|
530 | var maxLayerReached = new Comparator {Name = "MaxLayersReached = OpenLayers >= NumberOfLayers"};
|
---|
531 | var maxLayerReachedBranch = new ConditionalBranch {Name = "MaxLayersReached?"};
|
---|
532 | var openNewLayerCalculator = new ExpressionCalculator {Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]"};
|
---|
533 | var openNewLayerBranch = new ConditionalBranch {Name = "OpenNewLayer?"};
|
---|
534 | var layerCreator = new LastLayerCloner {Name = "Create Layer"};
|
---|
535 | var updateLayerNumber = new Assigner {Name = "Layer = OpenLayers"};
|
---|
536 | var historyWiper = new ResultsHistoryWiper {Name = "Clear History in Results"};
|
---|
537 | var evaluatedSolutionsWiper = new Assigner() {Name = "Clear evaluated Solutions"};
|
---|
538 | var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator();
|
---|
539 | var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter {Name = "Update EvaluatedSolutions"};
|
---|
540 | var incrOpenLayers = new IntCounter {Name = "Incr. OpenLayers"};
|
---|
541 |
|
---|
542 | layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
|
---|
543 |
|
---|
544 | maxLayerReached.LeftSideParameter.ActualName = OpenLayersParametername;
|
---|
545 | maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
|
---|
546 | maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
|
---|
547 | maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
548 | maxLayerReached.Successor = maxLayerReachedBranch;
|
---|
549 |
|
---|
550 | maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
|
---|
551 | maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
|
---|
552 |
|
---|
553 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
|
---|
554 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(GenerationsParametername));
|
---|
555 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
|
---|
556 | openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(OpenLayersParametername));
|
---|
557 | openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
|
---|
558 | openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
|
---|
559 | openNewLayerCalculator.Successor = openNewLayerBranch;
|
---|
560 |
|
---|
561 | openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
|
---|
562 | openNewLayerBranch.TrueBranch = layerCreator;
|
---|
563 |
|
---|
564 | layerCreator.NewLayerOperator = updateLayerNumber;
|
---|
565 | layerCreator.Successor = incrOpenLayers;
|
---|
566 |
|
---|
567 | updateLayerNumber.LeftSideParameter.ActualName = LayerParametername;
|
---|
568 | updateLayerNumber.RightSideParameter.ActualName = OpenLayersParametername;
|
---|
569 | updateLayerNumber.Successor = historyWiper;
|
---|
570 |
|
---|
571 | historyWiper.ResultsParameter.ActualName = LayerResultsParametername;
|
---|
572 | historyWiper.Successor = evaluatedSolutionsWiper;
|
---|
573 | evaluatedSolutionsWiper.LeftSideParameter.ActualName = LayerEvaluatedSolutionsParameterName;
|
---|
574 | evaluatedSolutionsWiper.RightSideParameter.Value = new IntValue(0);
|
---|
575 | evaluatedSolutionsWiper.Successor = createChildrenViaCrossover;
|
---|
576 |
|
---|
577 | // Maybe use only crossover and no elitism instead of "default operator"
|
---|
578 | createChildrenViaCrossover.RandomParameter.ActualName = LayerRandomParameter.Name;
|
---|
579 | createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
580 | createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = LayerEvaluatedSolutionsParameterName;
|
---|
581 | createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
|
---|
582 | createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
583 | createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
|
---|
584 | createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
585 | createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
586 | createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
587 | createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
588 | createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
589 | createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
|
---|
590 | createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
|
---|
591 | createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
|
---|
592 | createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
|
---|
593 | createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
|
---|
594 | createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
|
---|
595 |
|
---|
596 | incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
|
---|
597 | incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
|
---|
598 |
|
---|
599 | incrOpenLayers.ValueParameter.ActualName = OpenLayersParametername;
|
---|
600 | incrOpenLayers.Increment = new IntValue(1);
|
---|
601 |
|
---|
602 | return layerOpener;
|
---|
603 | }
|
---|
604 |
|
---|
605 | private CombinedOperator CreateReseeder() {
|
---|
606 | var reseeder = new CombinedOperator {Name = "Reseed Layer Zero if needed"};
|
---|
607 | var reseedingController = new ReseedingController {Name = "Reseeding needed (Generation % AgeGap == 0)?"};
|
---|
608 | var removeIndividuals = new SubScopesRemover();
|
---|
609 | var createIndividuals = new SolutionsCreator();
|
---|
610 | var initializeAgeProsessor = new UniformSubScopesProcessor();
|
---|
611 | var initializeAge = new VariableCreator {Name = "Initialize Age"};
|
---|
612 | var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter {Name = "Update EvaluatedSolutions"};
|
---|
613 |
|
---|
614 | reseeder.OperatorGraph.InitialOperator = reseedingController;
|
---|
615 |
|
---|
616 | reseedingController.GenerationsParameter.ActualName = GenerationsParametername;
|
---|
617 | reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
|
---|
618 | reseedingController.FirstLayerOperator = removeIndividuals;
|
---|
619 | reseedingController.Successor = null;
|
---|
620 |
|
---|
621 | removeIndividuals.Successor = createIndividuals;
|
---|
622 |
|
---|
623 | createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
624 | createIndividuals.Successor = initializeAgeProsessor;
|
---|
625 |
|
---|
626 | initializeAgeProsessor.Operator = initializeAge;
|
---|
627 | initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
|
---|
628 |
|
---|
629 | initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
|
---|
630 |
|
---|
631 | incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
|
---|
632 | incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
|
---|
633 |
|
---|
634 | return reseeder;
|
---|
635 | }
|
---|
636 | }
|
---|
637 | }
|
---|