Free cookie consent management tool by TermsFeed Policy Generator

source: branches/IslandALPS/IslandALPS/3.3/Offspring Selection/IslandAlpsOffspringSelectionAlgorithmMainLoop.cs @ 13734

Last change on this file since 13734 was 13734, checked in by pkuelzer, 8 years ago

#2558 FillwithParents parameter hidden because it causes crashes

File size: 39.9 KB
Line 
1using HeuristicLab.Algorithms.ALPS;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Optimization.Operators;
8using HeuristicLab.Parameters;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10using HeuristicLab.Selection;
11
12namespace HeuristicLab.Algorithms.IslandALPS {
13  [Item("IslandAlpsOffspringSelectionAlgorithmMainLoop", "An island ALPS offspring selection main loop operator.")]
14  [StorableClass]
15  public class IslandAlpsOffspringSelectionAlgorithmMainLoop : 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    private IslandAlpsOffspringSelectionAlgorithmMainLoop(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    #endregion
191
192    #region OS
193    public ILookupParameter<DoubleValue> ComparisonFactorParameter {
194      get { return (ILookupParameter<DoubleValue>) Parameters["ComparisonFactor"]; }
195    }
196
197    public IValueLookupParameter<DoubleValue> SuccessRatioParameter {
198      get { return (IValueLookupParameter<DoubleValue>) Parameters["SuccessRatio"]; }
199    }
200
201    public IValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
202      get { return (IValueLookupParameter<DoubleValue>) Parameters["MaximumSelectionPressure"]; }
203    }
204
205    public IValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
206      get { return (IValueLookupParameter<BoolValue>) Parameters["OffspringSelectionBeforeMutation"]; }
207    }
208
209    public IValueLookupParameter<BoolValue> FillPopulationWithParentsParameter {
210      get { return (IValueLookupParameter<BoolValue>) Parameters["FillPopulationWithParents"]; }
211    }
212
213    public ILookupParameter<DoubleValue> CurrentSuccessRatioParameter {
214      get { return (ILookupParameter<DoubleValue>) Parameters["CurrentSuccessRatio"]; }
215    }
216
217    public ILookupParameter<DoubleValue> SelectionPressureParameter {
218      get { return (ILookupParameter<DoubleValue>) Parameters["SelectionPressure"]; }
219    }
220    #endregion
221
222    #endregion
223
224    private IslandAlpsOffspringSelectionAlgorithmMainLoop(IslandAlpsOffspringSelectionAlgorithmMainLoop original, Cloner cloner) :
225      base(original, cloner) {}
226
227    public override IDeepCloneable Clone(Cloner cloner) {
228      return new IslandAlpsOffspringSelectionAlgorithmMainLoop(this, cloner);
229    }
230
231    public IslandAlpsOffspringSelectionAlgorithmMainLoop() {
232      AddParameters();
233
234      #region create Operators
235
236      var globalVariableCreator = new VariableCreator {Name = "Create global values"};
237      var islandVarCreatorUssp = new UniformSubScopesProcessor();
238      var islandVariableCreator = new VariableCreator {Name = "Initialize Results"};
239      var groupVariableCreator = new VariableCreator {Name = "Initialize Group Results"};
240
241      var layerUssp = new UniformSubScopesProcessor();
242      var layerVariableCreator = new VariableCreator();
243
244      var initLayerAnalyzerPlaceholder = new Placeholder {Name = "Layer Analyzer (Placeholder)"};
245      var initIslandAnalyzerPlaceholder = new Placeholder {Name = "Island Analyzer (Placeholder)"};
246      var initGlobalAnalyzerPlacerholder = new Placeholder {Name = "Global Analyzer (Placeholder)"};
247      var resultsCollector = new ResultsCollector();
248
249      var processIslandsUssp = new UniformSubScopesProcessor {Name = "Process Islands", Parallel = new BoolValue(true)};
250      var initIslandEvaluationsAss = new Assigner {Name = "Init Island Evaluations"};
251
252      var incrementGenerationDr = new IntCounter {Name = "Increment Generations"};
253      var incrementEvaluatedSolutionDr = new DataReducer {Name = "Increment Evaluated Solutions"};
254
255      var elderMigrator = CreateEldersEmigrator();
256      var newLayerOpener = CreateLayerOpener();
257      var reseeder = CreateReseeder();
258
259      var analyzeLayerUssp = new UniformSubScopesProcessor();
260
261      var layerAnalyzerPlaceholder = new Placeholder {Name = "Layer Analyzer (Placeholder)"};
262      var layerResultsCollector = new ResultsCollector {Name = "Collect Additional Infos"};
263      var islandAnalyzerPlaceholder = new Placeholder {Name = "Island Analyzer (Placeholder)"};
264      var islandResultsCollector = new ResultsCollector {Name = "Collect layer results into IslandResults"};
265
266      var globalAnalyzerPlacerholder = new Placeholder {Name = "Global Analyzer (Placeholder)"};
267
268      var groupingOperator = new GroupedLayerOperator {Name = "Grouped Analyzer"};
269      var groupAnalyzer = new Placeholder {Name = "Group Analyzer (Placeholder)"};
270      var groupResultsExtractor = new ResultsExtractor {Name = "Collect group results into variable"};
271      var groupResultsCollector = new ResultsCollector {Name = "Collect group results into into global results"};
272      var groupLayerNumberResultsCollector = new ResultsCollector {Name = "Add Layernumber to Results"};
273
274      var matingPoolCreator = new MatingPoolCreator();
275      var matingPoolUssp = new UniformSubScopesProcessor {Name = "Process Mating Pools"};
276      var alpsMainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
277
278      var setIslandEvaluatedSolutions = new DataReducer {Name = "Set IslandEvaluatedSolutions"};
279
280      var migrationThresholdCounter = new IntCounter {Name = "Increment Counter for Migrations"};
281      var migrationThresholdAss = new Assigner {Name = "Reset Counter for Migrations"};
282      var migrationCounter = new IntCounter {Name = "Increment  Migrations"};
283      var selectforMigrationUssp = new UniformSubScopesProcessor();
284      var emigrantSelector = new Placeholder {Name = "Emigrant Selector (Placeholder)"};
285      var migrator = new LayerMigrator();
286      var replaceforMigrationUssp = new UniformSubScopesProcessor();
287      var immigrantSelector = new Placeholder {Name = "Immigrant Replacer (Placeholder)"};
288
289      var migrateComparator = new Comparator();
290      var migrateCondBranch = new ConditionalBranch {Name = "Migrate?"};
291
292      var terminator = new TerminationOperator();
293
294      #endregion
295
296      globalVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(GenerationsParametername, new IntValue(1)));
297      globalVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(MigrationsParametername, new IntValue(0)));
298
299      islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(OpenLayersParametername, new IntValue(1)));
300      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(IslandResultsParametername));
301
302      layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>(LayerParametername, new IntValue(0)));
303      layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(LayerResultsParametername));
304
305      groupVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(GroupResultsParametername));
306      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
307      initIslandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
308      initGlobalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
309
310      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(GenerationsParametername));
311      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(IslandResultsParametername, "", IslandResultsParametername));
312      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(GroupResultsParametername, "", GroupResultsParametername));
313      resultsCollector.CollectedValues.Add(new ValueLookupParameter<IntValue>(MigrationsParametername));
314      resultsCollector.CopyValue = new BoolValue(false);
315
316      initIslandEvaluationsAss.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
317      initIslandEvaluationsAss.RightSideParameter.Value = new IntValue(0);
318
319      incrementGenerationDr.ValueParameter.ActualName = GenerationsParametername;
320
321      incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
322      incrementEvaluatedSolutionDr.TargetParameter.ActualName = EvaluatedSolutions.Name;
323      incrementEvaluatedSolutionDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
324      incrementEvaluatedSolutionDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
325
326      setIslandEvaluatedSolutions.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name;
327      setIslandEvaluatedSolutions.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
328      setIslandEvaluatedSolutions.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
329      setIslandEvaluatedSolutions.TargetParameter.ActualName = IslandEvaluatedSolutions.Name;
330
331
332      migrationThresholdCounter.ValueParameter.ActualName = MigrationThresholdParametername;
333
334      migrateComparator.Comparison.Value = ComparisonType.GreaterOrEqual;
335      migrateComparator.LeftSideParameter.ActualName = MigrationThresholdParametername;
336      migrateComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
337      migrateComparator.ResultParameter.ActualName = MigrateParametername;
338
339      migrateCondBranch.ConditionParameter.ActualName = MigrateParametername;
340
341      migrationCounter.ValueParameter.ActualName = MigrationsParametername;
342      migrationThresholdAss.LeftSideParameter.ActualName = MigrationThresholdParametername;
343      migrationThresholdAss.RightSideParameter.Value = new IntValue(0);
344
345      selectforMigrationUssp.Depth = new IntValue(2);
346      emigrantSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
347
348      replaceforMigrationUssp.Depth = new IntValue(2);
349      immigrantSelector.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
350
351      groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name;
352      groupLayerNumberResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("LayerNumber"));
353      groupLayerNumberResultsCollector.ResultsParameter.ActualName = GroupResultsParametername;
354
355      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
356      layerResultsCollector.ResultsParameter.ActualName = LayerResultsParametername;
357      layerResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(LayerParametername));
358      islandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
359      islandResultsCollector.ResultsParameter.ActualName = IslandResultsParametername;
360      islandResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(LayerResultsParametername));
361      globalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
362
363      groupResultsExtractor.SourceNameParameter.Value = new StringValue("GroupScope");
364      groupResultsExtractor.TargetNameParameter.Value = new StringValue(GroupResultsParametername);
365      groupResultsCollector.CollectedValues.Add(new LookupParameter<ItemArray<ResultCollection>>(GroupResultsParametername));
366      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
367
368      ParemetrizeMainOperator(alpsMainOperator);
369
370      //flow
371      OperatorGraph.InitialOperator = globalVariableCreator;
372      globalVariableCreator.Successor = islandVarCreatorUssp;
373      islandVarCreatorUssp.Operator = islandVariableCreator;
374      islandVariableCreator.Successor = layerUssp;
375      layerUssp.Operator = layerVariableCreator;
376      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
377      initLayerAnalyzerPlaceholder.Successor = null;
378      layerUssp.Successor = initIslandAnalyzerPlaceholder;
379      initLayerAnalyzerPlaceholder.Successor = null;
380      islandVarCreatorUssp.Successor = initGlobalAnalyzerPlacerholder;
381      initGlobalAnalyzerPlacerholder.Successor = resultsCollector;
382      resultsCollector.Successor = processIslandsUssp;
383      processIslandsUssp.Operator = initIslandEvaluationsAss;
384      initIslandEvaluationsAss.Successor = matingPoolCreator;
385      matingPoolCreator.Successor = matingPoolUssp;
386      matingPoolUssp.Operator = alpsMainOperator;
387      alpsMainOperator.Successor = null;
388      matingPoolUssp.Successor = elderMigrator;
389      elderMigrator.Successor = newLayerOpener;
390      newLayerOpener.Successor = reseeder;
391      reseeder.Successor = analyzeLayerUssp;
392      analyzeLayerUssp.Operator = layerAnalyzerPlaceholder;
393      layerAnalyzerPlaceholder.Successor = layerResultsCollector;
394      layerResultsCollector.Successor = null;
395
396      analyzeLayerUssp.Successor = islandAnalyzerPlaceholder;
397      islandAnalyzerPlaceholder.Successor = islandResultsCollector;
398      islandResultsCollector.Successor = setIslandEvaluatedSolutions;
399      setIslandEvaluatedSolutions.Successor = null;
400
401      processIslandsUssp.Successor = incrementGenerationDr;
402      incrementGenerationDr.Successor = incrementEvaluatedSolutionDr;
403      incrementEvaluatedSolutionDr.Successor = migrationThresholdCounter;
404
405      migrationThresholdCounter.Successor = migrateComparator;
406
407      migrateComparator.Successor = migrateCondBranch;
408      migrateCondBranch.FalseBranch = null;
409      migrateCondBranch.TrueBranch = migrationThresholdAss;
410      migrationThresholdAss.Successor = migrationCounter;
411
412      migrationCounter.Successor = selectforMigrationUssp;
413      selectforMigrationUssp.Operator = emigrantSelector;
414      emigrantSelector.Successor = null;
415      selectforMigrationUssp.Successor = migrator;
416
417      migrator.Successor = replaceforMigrationUssp;
418      replaceforMigrationUssp.Operator = immigrantSelector;
419      immigrantSelector.Successor = null;
420      replaceforMigrationUssp.Successor = null;
421
422      migrateCondBranch.Successor = globalAnalyzerPlacerholder;
423
424
425      globalAnalyzerPlacerholder.Successor = groupingOperator;
426      groupingOperator.Operator = groupAnalyzer;
427      groupAnalyzer.Successor = groupLayerNumberResultsCollector;
428      groupLayerNumberResultsCollector.Successor = null;
429      groupingOperator.Successor = groupResultsExtractor;
430      groupResultsExtractor.Successor = groupResultsCollector;
431      groupResultsCollector.Successor = terminator;
432      terminator.ContinueBranch = processIslandsUssp;
433    }
434
435    private void ParemetrizeMainOperator(AlpsOffspringSelectionGeneticAlgorithmMainOperator alpsMainOperator) {
436      alpsMainOperator.RandomParameter.ActualName = LayerRandomParameter.Name;
437      alpsMainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
438      alpsMainOperator.EvaluatedSolutionsParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
439      alpsMainOperator.QualityParameter.ActualName = QualityParameter.Name;
440      alpsMainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
441      alpsMainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
442      alpsMainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
443      alpsMainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
444      alpsMainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
445      alpsMainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
446      alpsMainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
447      alpsMainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
448      alpsMainOperator.AgeParameter.ActualName = AgeParameter.Name;
449      alpsMainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
450      alpsMainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
451
452      alpsMainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
453      alpsMainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
454      alpsMainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
455      alpsMainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
456      alpsMainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
457      alpsMainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
458      alpsMainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";             
459    }
460
461    private void AddParameters() {
462      Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
463      Parameters.Add(new ValueLookupParameter<IRandom>("IslandRandom", "A pseudo random number generator."));
464      Parameters.Add(new ValueLookupParameter<IRandom>("LayerRandom", "A pseudo random number generator."));
465
466      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
467      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
468      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
469
470      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of Layers per Island."));
471      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
472      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
473      Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
474      Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
475      Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
476      Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
477      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
478      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population of solutions."));
479
480      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
481      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
482      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
483      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
484      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
485      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
486      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
487      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
488      Parameters.Add(new ValueLookupParameter<ITerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
489
490      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
491      Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
492      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."));
493      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
494      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
495      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
496
497      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
498      Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
499      Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each Layer."));
500      Parameters.Add(new ValueLookupParameter<IOperator>("GroupAnalyzer", "The operator used to analyze each Layergroup."));
501
502      Parameters.Add(new LookupParameter<IntValue>(LayerEvaluatedSolutionsParameterName, "The number of times a solution has been evaluated."));
503      Parameters.Add(new LookupParameter<IntValue>("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
504      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
505
506      Parameters.Add(new ValueLookupParameter<BoolValue>(MigrateParametername, "Migrate the island?"));
507
508      Parameters.Add(new LookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor is used to determine whether the offspring should be compared to the better parent, the worse parent or a quality value linearly interpolated between them. It is in the range [0;1]."));
509      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
510      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
511      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation."));
512      Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.",new BoolValue(false)));
513
514      Parameters.Add(new LookupParameter<DoubleValue>("CurrentSuccessRatio", "The current success ratio."));
515      Parameters.Add(new LookupParameter<DoubleValue>("SelectionPressure", "The actual selection pressure."));
516    }
517
518    private CombinedOperator CreateEldersEmigrator() {
519      var eldersEmigrator = new CombinedOperator {Name = "Emigrate Elders"};
520      var selectorProsessor = new UniformSubScopesProcessor();
521      var eldersSelector = new EldersSelector();
522      var shiftToRightMigrator = new UnidirectionalRingMigrator {Name = "Shift elders to next layer"};
523      var mergingProsessor = new UniformSubScopesProcessor();
524      var mergingReducer = new MergingReducer();
525      var subScopesCounter = new SubScopesCounter();
526      var reduceToPopulationSizeBranch = new ConditionalBranch {Name = "ReduceToPopulationSize?"};
527      var countCalculator = new ExpressionCalculator {Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)"};
528      var bestSelector = new BestSelector();
529      var rightReducer = new RightReducer();
530
531      eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
532
533      selectorProsessor.Operator = eldersSelector;
534      selectorProsessor.Successor = shiftToRightMigrator;
535
536      eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
537      eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
538      eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
539      eldersSelector.LayerParameter.ActualName = "Layer";
540      eldersSelector.Successor = null;
541
542      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
543      shiftToRightMigrator.Successor = mergingProsessor;
544
545      mergingProsessor.Operator = mergingReducer;
546
547      mergingReducer.Successor = subScopesCounter;
548
549      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
550      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
551      subScopesCounter.Successor = reduceToPopulationSizeBranch;
552
553      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
554      reduceToPopulationSizeBranch.TrueBranch = countCalculator;
555
556      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
557      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
558      countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
559      countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
560      countCalculator.Successor = bestSelector;
561
562      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
563      bestSelector.CopySelected = new BoolValue(false);
564      bestSelector.Successor = rightReducer;
565
566      return eldersEmigrator;
567    }
568
569
570    private CombinedOperator CreateLayerOpener() {
571      var layerOpener = new CombinedOperator {Name = "Open new Layer if needed"};
572      var maxLayerReached = new Comparator {Name = "MaxLayersReached = OpenLayers >= NumberOfLayers"};
573      var maxLayerReachedBranch = new ConditionalBranch {Name = "MaxLayersReached?"};
574      var openNewLayerCalculator = new ExpressionCalculator {Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]"};
575      var openNewLayerBranch = new ConditionalBranch {Name = "OpenNewLayer?"};
576      var layerCreator = new LastLayerCloner {Name = "Create Layer"};
577      var updateLayerNumber = new Assigner {Name = "Layer = OpenLayers"};
578      var historyWiper = new ResultsHistoryWiper {Name = "Clear History in Results"};
579      var evaluatedSolutionsWiper = new Assigner() { Name = "Clear evaluated Solutions" };
580      var createChildrenViaCrossover = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
581      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter {Name = "Update EvaluatedSolutions"};
582      var incrOpenLayers = new IntCounter {Name = "Incr. OpenLayers"};
583      var newLayerResultsCollector = new ResultsCollector {Name = "Collect new Layer Results"};
584
585      layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
586
587      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
588      maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
589      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
590      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
591      maxLayerReached.Successor = maxLayerReachedBranch;
592
593      maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
594      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
595
596      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
597      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
598      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
599      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
600      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
601      openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
602      openNewLayerCalculator.Successor = openNewLayerBranch;
603
604      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
605      openNewLayerBranch.TrueBranch = layerCreator;
606
607      layerCreator.NewLayerOperator = updateLayerNumber;
608      layerCreator.Successor = incrOpenLayers;
609
610      updateLayerNumber.LeftSideParameter.ActualName = "Layer";
611      updateLayerNumber.RightSideParameter.ActualName = "OpenLayers";
612      updateLayerNumber.Successor = historyWiper;
613
614      historyWiper.ResultsParameter.ActualName = "LayerResults";
615      historyWiper.Successor = evaluatedSolutionsWiper;
616      evaluatedSolutionsWiper.LeftSideParameter.ActualName = LayerEvaluatedSolutionsParameterName;
617      evaluatedSolutionsWiper.RightSideParameter.Value = new IntValue(0);
618      evaluatedSolutionsWiper.Successor = createChildrenViaCrossover;
619
620      // Maybe use only crossover and no elitism instead of "default operator"
621      createChildrenViaCrossover.RandomParameter.ActualName = LayerRandomParameter.Name;
622      createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
623      createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
624      createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
625      createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
626      createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
627      createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
628      createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
629      createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName;
630      createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
631      createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
632      createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
633      createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
634      createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
635      createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
636      createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure";
637      createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
638      createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
639      createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
640      createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
641      createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
642      createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
643      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
644
645      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
646      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
647
648      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
649      incrOpenLayers.Increment = new IntValue(1);
650      incrOpenLayers.Successor = newLayerResultsCollector;
651
652      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
653      newLayerResultsCollector.CopyValue = new BoolValue(false);
654      newLayerResultsCollector.Successor = null;
655
656      return layerOpener;
657    }
658
659    private CombinedOperator CreateReseeder() {
660      var reseeder = new CombinedOperator {Name = "Reseed Layer Zero if needed"};
661      var reseedingController = new ReseedingController {Name = "Reseeding needed (Generation % AgeGap == 0)?"};
662      var removeIndividuals = new SubScopesRemover();
663      var createIndividuals = new SolutionsCreator();
664      var initializeAgeProsessor = new UniformSubScopesProcessor();
665      var initializeAge = new VariableCreator {Name = "Initialize Age"};
666      var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter {Name = "Update EvaluatedSolutions"};
667
668      reseeder.OperatorGraph.InitialOperator = reseedingController;
669
670      reseedingController.GenerationsParameter.ActualName = "Generations";
671      reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
672      reseedingController.FirstLayerOperator = removeIndividuals;
673      reseedingController.Successor = null;
674
675      removeIndividuals.Successor = createIndividuals;
676
677      createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
678      createIndividuals.Successor = initializeAgeProsessor;
679
680      initializeAgeProsessor.Operator = initializeAge;
681      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
682
683      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
684
685      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
686      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
687
688      return reseeder;
689    }
690
691
692  }
693}
Note: See TracBrowser for help on using the repository browser.