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