Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2558 Added SucessRatio and SelectionPressure Analyzer

File size: 40.1 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      layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
305      layerVariableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
306
307      groupVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>(GroupResultsParametername));
308      initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
309      initIslandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
310      initGlobalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
311
312      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(GenerationsParametername));
313      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(IslandResultsParametername, "", IslandResultsParametername));
314      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(GroupResultsParametername, "", GroupResultsParametername));
315      resultsCollector.CollectedValues.Add(new ValueLookupParameter<IntValue>(MigrationsParametername));
316      resultsCollector.CopyValue = new BoolValue(false);
317
318      initIslandEvaluationsAss.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
319      initIslandEvaluationsAss.RightSideParameter.Value = new IntValue(0);
320
321      incrementGenerationDr.ValueParameter.ActualName = GenerationsParametername;
322
323      incrementEvaluatedSolutionDr.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
324      incrementEvaluatedSolutionDr.TargetParameter.ActualName = EvaluatedSolutions.Name;
325      incrementEvaluatedSolutionDr.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
326      incrementEvaluatedSolutionDr.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
327
328      setIslandEvaluatedSolutions.ParameterToReduce.ActualName = LayerEvaluatedSolutionsParameter.Name;
329      setIslandEvaluatedSolutions.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
330      setIslandEvaluatedSolutions.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
331      setIslandEvaluatedSolutions.TargetParameter.ActualName = IslandEvaluatedSolutions.Name;
332
333
334      migrationThresholdCounter.ValueParameter.ActualName = MigrationThresholdParametername;
335
336      migrateComparator.Comparison.Value = ComparisonType.GreaterOrEqual;
337      migrateComparator.LeftSideParameter.ActualName = MigrationThresholdParametername;
338      migrateComparator.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
339      migrateComparator.ResultParameter.ActualName = MigrateParametername;
340
341      migrateCondBranch.ConditionParameter.ActualName = MigrateParametername;
342
343      migrationCounter.ValueParameter.ActualName = MigrationsParametername;
344      migrationThresholdAss.LeftSideParameter.ActualName = MigrationThresholdParametername;
345      migrationThresholdAss.RightSideParameter.Value = new IntValue(0);
346
347      selectforMigrationUssp.Depth = new IntValue(2);
348      emigrantSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
349
350      replaceforMigrationUssp.Depth = new IntValue(2);
351      immigrantSelector.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
352
353      groupAnalyzer.OperatorParameter.ActualName = GroupAnalyzerParameter.Name;
354      groupLayerNumberResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("LayerNumber"));
355      groupLayerNumberResultsCollector.ResultsParameter.ActualName = GroupResultsParametername;
356
357      layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
358      layerResultsCollector.ResultsParameter.ActualName = LayerResultsParametername;
359      layerResultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(LayerParametername));
360      islandAnalyzerPlaceholder.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
361      islandResultsCollector.ResultsParameter.ActualName = IslandResultsParametername;
362      islandResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>(LayerResultsParametername));
363      globalAnalyzerPlacerholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
364
365      groupResultsExtractor.SourceNameParameter.Value = new StringValue("GroupScope");
366      groupResultsExtractor.TargetNameParameter.Value = new StringValue(GroupResultsParametername);
367      groupResultsCollector.CollectedValues.Add(new LookupParameter<ItemArray<ResultCollection>>(GroupResultsParametername));
368      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
369
370      ParemetrizeMainOperator(alpsMainOperator);
371
372      //flow
373      OperatorGraph.InitialOperator = globalVariableCreator;
374      globalVariableCreator.Successor = islandVarCreatorUssp;
375      islandVarCreatorUssp.Operator = islandVariableCreator;
376      islandVariableCreator.Successor = layerUssp;
377      layerUssp.Operator = layerVariableCreator;
378      layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
379      initLayerAnalyzerPlaceholder.Successor = null;
380      layerUssp.Successor = initIslandAnalyzerPlaceholder;
381      initLayerAnalyzerPlaceholder.Successor = null;
382      islandVarCreatorUssp.Successor = initGlobalAnalyzerPlacerholder;
383      initGlobalAnalyzerPlacerholder.Successor = resultsCollector;
384      resultsCollector.Successor = processIslandsUssp;
385      processIslandsUssp.Operator = initIslandEvaluationsAss;
386      initIslandEvaluationsAss.Successor = matingPoolCreator;
387      matingPoolCreator.Successor = matingPoolUssp;
388      matingPoolUssp.Operator = alpsMainOperator;
389      alpsMainOperator.Successor = null;
390      matingPoolUssp.Successor = elderMigrator;
391      elderMigrator.Successor = newLayerOpener;
392      newLayerOpener.Successor = reseeder;
393      reseeder.Successor = analyzeLayerUssp;
394      analyzeLayerUssp.Operator = layerAnalyzerPlaceholder;
395      layerAnalyzerPlaceholder.Successor = layerResultsCollector;
396      layerResultsCollector.Successor = null;
397
398      analyzeLayerUssp.Successor = islandAnalyzerPlaceholder;
399      islandAnalyzerPlaceholder.Successor = islandResultsCollector;
400      islandResultsCollector.Successor = setIslandEvaluatedSolutions;
401      setIslandEvaluatedSolutions.Successor = null;
402
403      processIslandsUssp.Successor = incrementGenerationDr;
404      incrementGenerationDr.Successor = incrementEvaluatedSolutionDr;
405      incrementEvaluatedSolutionDr.Successor = migrationThresholdCounter;
406
407      migrationThresholdCounter.Successor = migrateComparator;
408
409      migrateComparator.Successor = migrateCondBranch;
410      migrateCondBranch.FalseBranch = null;
411      migrateCondBranch.TrueBranch = migrationThresholdAss;
412      migrationThresholdAss.Successor = migrationCounter;
413
414      migrationCounter.Successor = selectforMigrationUssp;
415      selectforMigrationUssp.Operator = emigrantSelector;
416      emigrantSelector.Successor = null;
417      selectforMigrationUssp.Successor = migrator;
418
419      migrator.Successor = replaceforMigrationUssp;
420      replaceforMigrationUssp.Operator = immigrantSelector;
421      immigrantSelector.Successor = null;
422      replaceforMigrationUssp.Successor = null;
423
424      migrateCondBranch.Successor = globalAnalyzerPlacerholder;
425
426
427      globalAnalyzerPlacerholder.Successor = groupingOperator;
428      groupingOperator.Operator = groupAnalyzer;
429      groupAnalyzer.Successor = groupLayerNumberResultsCollector;
430      groupLayerNumberResultsCollector.Successor = null;
431      groupingOperator.Successor = groupResultsExtractor;
432      groupResultsExtractor.Successor = groupResultsCollector;
433      groupResultsCollector.Successor = terminator;
434      terminator.ContinueBranch = processIslandsUssp;
435    }
436
437    private void ParemetrizeMainOperator(AlpsOffspringSelectionGeneticAlgorithmMainOperator alpsMainOperator) {
438      alpsMainOperator.RandomParameter.ActualName = LayerRandomParameter.Name;
439      alpsMainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
440      alpsMainOperator.EvaluatedSolutionsParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
441      alpsMainOperator.QualityParameter.ActualName = QualityParameter.Name;
442      alpsMainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
443      alpsMainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
444      alpsMainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
445      alpsMainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
446      alpsMainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
447      alpsMainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
448      alpsMainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
449      alpsMainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
450      alpsMainOperator.AgeParameter.ActualName = AgeParameter.Name;
451      alpsMainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
452      alpsMainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
453
454      alpsMainOperator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
455      alpsMainOperator.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
456      alpsMainOperator.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
457      alpsMainOperator.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
458      alpsMainOperator.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
459      alpsMainOperator.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
460      alpsMainOperator.SelectionPressureParameter.ActualName = "SelectionPressure";             
461    }
462
463    private void AddParameters() {
464      Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
465      Parameters.Add(new ValueLookupParameter<IRandom>("IslandRandom", "A pseudo random number generator."));
466      Parameters.Add(new ValueLookupParameter<IRandom>("LayerRandom", "A pseudo random number generator."));
467
468      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
469      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
470      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
471
472      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of Layers per Island."));
473      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
474      Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
475      Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
476      Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
477      Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
478      Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
479      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
480      Parameters.Add(new ValueLookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population of solutions."));
481
482      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
483      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
484      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
485      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
486      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
487      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
488      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
489      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
490      Parameters.Add(new ValueLookupParameter<ITerminator>("Terminator", "The termination criteria that defines if the algorithm should continue or stop"));
491
492      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
493      Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
494      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."));
495      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
496      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
497      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
498
499      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
500      Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
501      Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each Layer."));
502      Parameters.Add(new ValueLookupParameter<IOperator>("GroupAnalyzer", "The operator used to analyze each Layergroup."));
503
504      Parameters.Add(new LookupParameter<IntValue>(LayerEvaluatedSolutionsParameterName, "The number of times a solution has been evaluated."));
505      Parameters.Add(new LookupParameter<IntValue>("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
506      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
507
508      Parameters.Add(new ValueLookupParameter<BoolValue>(MigrateParametername, "Migrate the island?"));
509
510      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]."));
511      Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved."));
512      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm."));
513      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."));
514      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)));
515
516      Parameters.Add(new LookupParameter<DoubleValue>("CurrentSuccessRatio", "The current success ratio."));
517      Parameters.Add(new LookupParameter<DoubleValue>("SelectionPressure", "The actual selection pressure."));
518    }
519
520    private CombinedOperator CreateEldersEmigrator() {
521      var eldersEmigrator = new CombinedOperator {Name = "Emigrate Elders"};
522      var selectorProsessor = new UniformSubScopesProcessor();
523      var eldersSelector = new EldersSelector();
524      var shiftToRightMigrator = new UnidirectionalRingMigrator {Name = "Shift elders to next layer"};
525      var mergingProsessor = new UniformSubScopesProcessor();
526      var mergingReducer = new MergingReducer();
527      var subScopesCounter = new SubScopesCounter();
528      var reduceToPopulationSizeBranch = new ConditionalBranch {Name = "ReduceToPopulationSize?"};
529      var countCalculator = new ExpressionCalculator {Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)"};
530      var bestSelector = new BestSelector();
531      var rightReducer = new RightReducer();
532
533      eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;
534
535      selectorProsessor.Operator = eldersSelector;
536      selectorProsessor.Successor = shiftToRightMigrator;
537
538      eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
539      eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
540      eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
541      eldersSelector.LayerParameter.ActualName = "Layer";
542      eldersSelector.Successor = null;
543
544      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
545      shiftToRightMigrator.Successor = mergingProsessor;
546
547      mergingProsessor.Operator = mergingReducer;
548
549      mergingReducer.Successor = subScopesCounter;
550
551      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
552      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
553      subScopesCounter.Successor = reduceToPopulationSizeBranch;
554
555      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
556      reduceToPopulationSizeBranch.TrueBranch = countCalculator;
557
558      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
559      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
560      countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
561      countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
562      countCalculator.Successor = bestSelector;
563
564      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
565      bestSelector.CopySelected = new BoolValue(false);
566      bestSelector.Successor = rightReducer;
567
568      return eldersEmigrator;
569    }
570
571
572    private CombinedOperator CreateLayerOpener() {
573      var layerOpener = new CombinedOperator {Name = "Open new Layer if needed"};
574      var maxLayerReached = new Comparator {Name = "MaxLayersReached = OpenLayers >= NumberOfLayers"};
575      var maxLayerReachedBranch = new ConditionalBranch {Name = "MaxLayersReached?"};
576      var openNewLayerCalculator = new ExpressionCalculator {Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]"};
577      var openNewLayerBranch = new ConditionalBranch {Name = "OpenNewLayer?"};
578      var layerCreator = new LastLayerCloner {Name = "Create Layer"};
579      var updateLayerNumber = new Assigner {Name = "Layer = OpenLayers"};
580      var historyWiper = new ResultsHistoryWiper {Name = "Clear History in Results"};
581      var evaluatedSolutionsWiper = new Assigner() { Name = "Clear evaluated Solutions" };
582      var createChildrenViaCrossover = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
583      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter {Name = "Update EvaluatedSolutions"};
584      var incrOpenLayers = new IntCounter {Name = "Incr. OpenLayers"};
585      var newLayerResultsCollector = new ResultsCollector {Name = "Collect new Layer Results"};
586
587      layerOpener.OperatorGraph.InitialOperator = maxLayerReached;
588
589      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
590      maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
591      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
592      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
593      maxLayerReached.Successor = maxLayerReachedBranch;
594
595      maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached";
596      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
597
598      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
599      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
600      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
601      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
602      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
603      openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >");
604      openNewLayerCalculator.Successor = openNewLayerBranch;
605
606      openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer";
607      openNewLayerBranch.TrueBranch = layerCreator;
608
609      layerCreator.NewLayerOperator = updateLayerNumber;
610      layerCreator.Successor = incrOpenLayers;
611
612      updateLayerNumber.LeftSideParameter.ActualName = "Layer";
613      updateLayerNumber.RightSideParameter.ActualName = "OpenLayers";
614      updateLayerNumber.Successor = historyWiper;
615
616      historyWiper.ResultsParameter.ActualName = "LayerResults";
617      historyWiper.Successor = evaluatedSolutionsWiper;
618      evaluatedSolutionsWiper.LeftSideParameter.ActualName = LayerEvaluatedSolutionsParameterName;
619      evaluatedSolutionsWiper.RightSideParameter.Value = new IntValue(0);
620      evaluatedSolutionsWiper.Successor = createChildrenViaCrossover;
621
622      // Maybe use only crossover and no elitism instead of "default operator"
623      createChildrenViaCrossover.RandomParameter.ActualName = LayerRandomParameter.Name;
624      createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
625      createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
626      createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
627      createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
628      createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
629      createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
630      createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
631      createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.ActualName;
632      createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
633      createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
634      createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
635      createChildrenViaCrossover.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
636      createChildrenViaCrossover.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
637      createChildrenViaCrossover.CurrentSuccessRatioParameter.ActualName = "CurrentSuccessRatio";
638      createChildrenViaCrossover.SelectionPressureParameter.ActualName = "SelectionPressure";
639      createChildrenViaCrossover.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
640      createChildrenViaCrossover.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
641      createChildrenViaCrossover.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
642      createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
643      createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
644      createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
645      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
646
647      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
648      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
649
650      incrOpenLayers.ValueParameter.ActualName = "OpenLayers";
651      incrOpenLayers.Increment = new IntValue(1);
652      incrOpenLayers.Successor = newLayerResultsCollector;
653
654      newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
655      newLayerResultsCollector.CopyValue = new BoolValue(false);
656      newLayerResultsCollector.Successor = null;
657
658      return layerOpener;
659    }
660
661    private CombinedOperator CreateReseeder() {
662      var reseeder = new CombinedOperator {Name = "Reseed Layer Zero if needed"};
663      var reseedingController = new ReseedingController {Name = "Reseeding needed (Generation % AgeGap == 0)?"};
664      var removeIndividuals = new SubScopesRemover();
665      var createIndividuals = new SolutionsCreator();
666      var initializeAgeProsessor = new UniformSubScopesProcessor();
667      var initializeAge = new VariableCreator {Name = "Initialize Age"};
668      var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter {Name = "Update EvaluatedSolutions"};
669
670      reseeder.OperatorGraph.InitialOperator = reseedingController;
671
672      reseedingController.GenerationsParameter.ActualName = "Generations";
673      reseedingController.AgeGapParameter.ActualName = AgeGapParameter.Name;
674      reseedingController.FirstLayerOperator = removeIndividuals;
675      reseedingController.Successor = null;
676
677      removeIndividuals.Successor = createIndividuals;
678
679      createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
680      createIndividuals.Successor = initializeAgeProsessor;
681
682      initializeAgeProsessor.Operator = initializeAge;
683      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
684
685      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
686
687      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = LayerEvaluatedSolutionsParameter.Name;
688      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
689
690      return reseeder;
691    }
692
693
694  }
695}
Note: See TracBrowser for help on using the repository browser.