1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Analysis;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Operators;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 | using HeuristicLab.Optimization.Operators;
|
---|
32 | using HeuristicLab.Parameters;
|
---|
33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
34 | using HeuristicLab.PluginInfrastructure;
|
---|
35 | using HeuristicLab.Random;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm {
|
---|
38 | /// <summary>
|
---|
39 | /// An offspring selection island genetic algorithm.
|
---|
40 | /// </summary>
|
---|
41 | [Item("Island Offspring Selection Genetic Algorithm", "An island offspring selection genetic algorithm.")]
|
---|
42 | [Creatable("Algorithms")]
|
---|
43 | [StorableClass]
|
---|
44 | public sealed class IslandOffspringSelectionGeneticAlgorithm : EngineAlgorithm {
|
---|
45 |
|
---|
46 | #region Problem Properties
|
---|
47 | public override Type ProblemType {
|
---|
48 | get { return typeof(ISingleObjectiveProblem); }
|
---|
49 | }
|
---|
50 | public new ISingleObjectiveProblem Problem {
|
---|
51 | get { return (ISingleObjectiveProblem)base.Problem; }
|
---|
52 | set { base.Problem = value; }
|
---|
53 | }
|
---|
54 | #endregion
|
---|
55 |
|
---|
56 | #region Parameter Properties
|
---|
57 | private ValueParameter<IntValue> SeedParameter {
|
---|
58 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
59 | }
|
---|
60 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
61 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
62 | }
|
---|
63 | private ValueParameter<IntValue> NumberOfIslandsParameter {
|
---|
64 | get { return (ValueParameter<IntValue>)Parameters["NumberOfIslands"]; }
|
---|
65 | }
|
---|
66 | private ValueParameter<IntValue> MigrationIntervalParameter {
|
---|
67 | get { return (ValueParameter<IntValue>)Parameters["MigrationInterval"]; }
|
---|
68 | }
|
---|
69 | private ValueParameter<PercentValue> MigrationRateParameter {
|
---|
70 | get { return (ValueParameter<PercentValue>)Parameters["MigrationRate"]; }
|
---|
71 | }
|
---|
72 | private ConstrainedValueParameter<IMigrator> MigratorParameter {
|
---|
73 | get { return (ConstrainedValueParameter<IMigrator>)Parameters["Migrator"]; }
|
---|
74 | }
|
---|
75 | private ConstrainedValueParameter<ISelector> EmigrantsSelectorParameter {
|
---|
76 | get { return (ConstrainedValueParameter<ISelector>)Parameters["EmigrantsSelector"]; }
|
---|
77 | }
|
---|
78 | private ConstrainedValueParameter<IReplacer> ImmigrationReplacerParameter {
|
---|
79 | get { return (ConstrainedValueParameter<IReplacer>)Parameters["ImmigrationReplacer"]; }
|
---|
80 | }
|
---|
81 | private ValueParameter<IntValue> PopulationSizeParameter {
|
---|
82 | get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
83 | }
|
---|
84 | private ValueParameter<IntValue> MaximumGenerationsParameter {
|
---|
85 | get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
86 | }
|
---|
87 | private ConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
88 | get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
89 | }
|
---|
90 | private ConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
91 | get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
92 | }
|
---|
93 | private ValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
94 | get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
95 | }
|
---|
96 | private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
97 | get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
98 | }
|
---|
99 | private ValueParameter<IntValue> ElitesParameter {
|
---|
100 | get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
101 | }
|
---|
102 | private ValueLookupParameter<DoubleValue> SuccessRatioParameter {
|
---|
103 | get { return (ValueLookupParameter<DoubleValue>)Parameters["SuccessRatio"]; }
|
---|
104 | }
|
---|
105 | private ValueLookupParameter<DoubleValue> ComparisonFactorLowerBoundParameter {
|
---|
106 | get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorLowerBound"]; }
|
---|
107 | }
|
---|
108 | private ValueLookupParameter<DoubleValue> ComparisonFactorUpperBoundParameter {
|
---|
109 | get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
|
---|
110 | }
|
---|
111 | private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
|
---|
112 | get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
|
---|
113 | }
|
---|
114 | private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
|
---|
115 | get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumSelectionPressure"]; }
|
---|
116 | }
|
---|
117 | private ValueLookupParameter<BoolValue> OffspringSelectionBeforeMutationParameter {
|
---|
118 | get { return (ValueLookupParameter<BoolValue>)Parameters["OffspringSelectionBeforeMutation"]; }
|
---|
119 | }
|
---|
120 | private ValueLookupParameter<IntValue> SelectedParentsParameter {
|
---|
121 | get { return (ValueLookupParameter<IntValue>)Parameters["SelectedParents"]; }
|
---|
122 | }
|
---|
123 | private ValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
124 | get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
125 | }
|
---|
126 | private ValueParameter<MultiAnalyzer> IslandAnalyzerParameter {
|
---|
127 | get { return (ValueParameter<MultiAnalyzer>)Parameters["IslandAnalyzer"]; }
|
---|
128 | }
|
---|
129 | #endregion
|
---|
130 |
|
---|
131 | #region Properties
|
---|
132 | public IntValue Seed {
|
---|
133 | get { return SeedParameter.Value; }
|
---|
134 | set { SeedParameter.Value = value; }
|
---|
135 | }
|
---|
136 | public BoolValue SetSeedRandomly {
|
---|
137 | get { return SetSeedRandomlyParameter.Value; }
|
---|
138 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
139 | }
|
---|
140 | public IntValue NumberOfIslands {
|
---|
141 | get { return NumberOfIslandsParameter.Value; }
|
---|
142 | set { NumberOfIslandsParameter.Value = value; }
|
---|
143 | }
|
---|
144 | public IntValue MigrationInterval {
|
---|
145 | get { return MigrationIntervalParameter.Value; }
|
---|
146 | set { MigrationIntervalParameter.Value = value; }
|
---|
147 | }
|
---|
148 | public PercentValue MigrationRate {
|
---|
149 | get { return MigrationRateParameter.Value; }
|
---|
150 | set { MigrationRateParameter.Value = value; }
|
---|
151 | }
|
---|
152 | public IMigrator Migrator {
|
---|
153 | get { return MigratorParameter.Value; }
|
---|
154 | set { MigratorParameter.Value = value; }
|
---|
155 | }
|
---|
156 | public ISelector EmigrantsSelector {
|
---|
157 | get { return EmigrantsSelectorParameter.Value; }
|
---|
158 | set { EmigrantsSelectorParameter.Value = value; }
|
---|
159 | }
|
---|
160 | public IReplacer ImmigrationReplacer {
|
---|
161 | get { return ImmigrationReplacerParameter.Value; }
|
---|
162 | set { ImmigrationReplacerParameter.Value = value; }
|
---|
163 | }
|
---|
164 | public IntValue PopulationSize {
|
---|
165 | get { return PopulationSizeParameter.Value; }
|
---|
166 | set { PopulationSizeParameter.Value = value; }
|
---|
167 | }
|
---|
168 | public IntValue MaximumGenerations {
|
---|
169 | get { return MaximumGenerationsParameter.Value; }
|
---|
170 | set { MaximumGenerationsParameter.Value = value; }
|
---|
171 | }
|
---|
172 | public ISelector Selector {
|
---|
173 | get { return SelectorParameter.Value; }
|
---|
174 | set { SelectorParameter.Value = value; }
|
---|
175 | }
|
---|
176 | public ICrossover Crossover {
|
---|
177 | get { return CrossoverParameter.Value; }
|
---|
178 | set { CrossoverParameter.Value = value; }
|
---|
179 | }
|
---|
180 | public PercentValue MutationProbability {
|
---|
181 | get { return MutationProbabilityParameter.Value; }
|
---|
182 | set { MutationProbabilityParameter.Value = value; }
|
---|
183 | }
|
---|
184 | public IManipulator Mutator {
|
---|
185 | get { return MutatorParameter.Value; }
|
---|
186 | set { MutatorParameter.Value = value; }
|
---|
187 | }
|
---|
188 | public IntValue Elites {
|
---|
189 | get { return ElitesParameter.Value; }
|
---|
190 | set { ElitesParameter.Value = value; }
|
---|
191 | }
|
---|
192 | private DoubleValue SuccessRatio {
|
---|
193 | get { return SuccessRatioParameter.Value; }
|
---|
194 | set { SuccessRatioParameter.Value = value; }
|
---|
195 | }
|
---|
196 | private DoubleValue ComparisonFactorLowerBound {
|
---|
197 | get { return ComparisonFactorLowerBoundParameter.Value; }
|
---|
198 | set { ComparisonFactorLowerBoundParameter.Value = value; }
|
---|
199 | }
|
---|
200 | private DoubleValue ComparisonFactorUpperBound {
|
---|
201 | get { return ComparisonFactorUpperBoundParameter.Value; }
|
---|
202 | set { ComparisonFactorUpperBoundParameter.Value = value; }
|
---|
203 | }
|
---|
204 | private IDiscreteDoubleValueModifier ComparisonFactorModifier {
|
---|
205 | get { return ComparisonFactorModifierParameter.Value; }
|
---|
206 | set { ComparisonFactorModifierParameter.Value = value; }
|
---|
207 | }
|
---|
208 | private DoubleValue MaximumSelectionPressure {
|
---|
209 | get { return MaximumSelectionPressureParameter.Value; }
|
---|
210 | set { MaximumSelectionPressureParameter.Value = value; }
|
---|
211 | }
|
---|
212 | private BoolValue OffspringSelectionBeforeMutation {
|
---|
213 | get { return OffspringSelectionBeforeMutationParameter.Value; }
|
---|
214 | set { OffspringSelectionBeforeMutationParameter.Value = value; }
|
---|
215 | }
|
---|
216 | public MultiAnalyzer Analyzer {
|
---|
217 | get { return AnalyzerParameter.Value; }
|
---|
218 | set { AnalyzerParameter.Value = value; }
|
---|
219 | }
|
---|
220 | public MultiAnalyzer IslandAnalyzer {
|
---|
221 | get { return IslandAnalyzerParameter.Value; }
|
---|
222 | set { IslandAnalyzerParameter.Value = value; }
|
---|
223 | }
|
---|
224 | private RandomCreator RandomCreator {
|
---|
225 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
226 | }
|
---|
227 | private UniformSubScopesProcessor IslandProcessor {
|
---|
228 | get { return ((RandomCreator.Successor as SubScopesCreator).Successor as UniformSubScopesProcessor); }
|
---|
229 | }
|
---|
230 | private SolutionsCreator SolutionsCreator {
|
---|
231 | get { return (SolutionsCreator)IslandProcessor.Operator; }
|
---|
232 | }
|
---|
233 | private IslandOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
|
---|
234 | get { return (IslandOffspringSelectionGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
|
---|
235 | }
|
---|
236 | [Storable]
|
---|
237 | private BestAverageWorstQualityAnalyzer islandQualityAnalyzer;
|
---|
238 | [Storable]
|
---|
239 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
240 | [Storable]
|
---|
241 | private ValueAnalyzer islandSelectionPressureAnalyzer;
|
---|
242 | [Storable]
|
---|
243 | private ValueAnalyzer selectionPressureAnalyzer;
|
---|
244 | #endregion
|
---|
245 |
|
---|
246 | [StorableConstructor]
|
---|
247 | private IslandOffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
|
---|
248 | public IslandOffspringSelectionGeneticAlgorithm()
|
---|
249 | : base() {
|
---|
250 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
251 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
252 | Parameters.Add(new ValueParameter<IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
|
---|
253 | Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
|
---|
254 | Parameters.Add(new ValueParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
|
---|
255 | Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
|
---|
256 | Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
|
---|
257 | Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Replaces part of the original population with the immigrants."));
|
---|
258 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions of each island.", new IntValue(100)));
|
---|
259 | Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(100)));
|
---|
260 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
261 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
262 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
263 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
264 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
265 | Parameters.Add(new ValueLookupParameter<DoubleValue>("SuccessRatio", "The ratio of successful to total children that should be achieved.", new DoubleValue(1)));
|
---|
266 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
|
---|
267 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
|
---|
268 | Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
|
---|
269 | Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
|
---|
270 | 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.", new BoolValue(false)));
|
---|
271 | Parameters.Add(new ValueLookupParameter<IntValue>("SelectedParents", "How much parents should be selected each time the offspring selection step is performed until the population is filled. This parameter should be about the same or twice the size of PopulationSize for smaller problems, and less for large problems.", new IntValue(200)));
|
---|
272 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
|
---|
273 | Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
|
---|
274 |
|
---|
275 | RandomCreator randomCreator = new RandomCreator();
|
---|
276 | SubScopesCreator populationCreator = new SubScopesCreator();
|
---|
277 | UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
|
---|
278 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
279 | IslandOffspringSelectionGeneticAlgorithmMainLoop mainLoop = new IslandOffspringSelectionGeneticAlgorithmMainLoop();
|
---|
280 | OperatorGraph.InitialOperator = randomCreator;
|
---|
281 |
|
---|
282 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
283 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
284 | randomCreator.SeedParameter.Value = null;
|
---|
285 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
286 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
287 | randomCreator.Successor = populationCreator;
|
---|
288 |
|
---|
289 | populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
|
---|
290 | populationCreator.Successor = ussp1;
|
---|
291 |
|
---|
292 | ussp1.Operator = solutionsCreator;
|
---|
293 | ussp1.Successor = mainLoop;
|
---|
294 |
|
---|
295 | solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
296 | solutionsCreator.Successor = null;
|
---|
297 |
|
---|
298 | mainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
|
---|
299 | mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
|
---|
300 | mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
301 | mainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
|
---|
302 | mainLoop.MigrationRateParameter.ActualName = MigrationRateParameter.Name;
|
---|
303 | mainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
|
---|
304 | mainLoop.NumberOfIslandsParameter.ActualName = NumberOfIslandsParameter.Name;
|
---|
305 | mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
306 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
307 | mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
308 | mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
309 | mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
310 | mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
|
---|
311 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
312 | mainLoop.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
|
---|
313 | mainLoop.ComparisonFactorParameter.ActualName = "ComparisonFactor";
|
---|
314 | mainLoop.ComparisonFactorStartParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
|
---|
315 | mainLoop.ComparisonFactorModifierParameter.ActualName = ComparisonFactorModifierParameter.Name;
|
---|
316 | mainLoop.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
|
---|
317 | mainLoop.OffspringSelectionBeforeMutationParameter.ActualName = OffspringSelectionBeforeMutationParameter.Name;
|
---|
318 | mainLoop.Successor = null;
|
---|
319 |
|
---|
320 | foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
|
---|
321 | SelectorParameter.ValidValues.Add(selector);
|
---|
322 | ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
|
---|
323 | if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
|
---|
324 |
|
---|
325 | foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
|
---|
326 | EmigrantsSelectorParameter.ValidValues.Add(selector);
|
---|
327 |
|
---|
328 | foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name))
|
---|
329 | ImmigrationReplacerParameter.ValidValues.Add(replacer);
|
---|
330 |
|
---|
331 | ParameterizeSelectors();
|
---|
332 |
|
---|
333 | foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
|
---|
334 | MigratorParameter.ValidValues.Add(migrator);
|
---|
335 |
|
---|
336 | foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
|
---|
337 | ComparisonFactorModifierParameter.ValidValues.Add(modifier);
|
---|
338 | IDiscreteDoubleValueModifier linearModifier = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("LinearDiscreteDoubleValueModifier"));
|
---|
339 | if (linearModifier != null) ComparisonFactorModifierParameter.Value = linearModifier;
|
---|
340 | ParameterizeComparisonFactorModifiers();
|
---|
341 |
|
---|
342 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
343 | islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
344 | selectionPressureAnalyzer = new ValueAnalyzer();
|
---|
345 | islandSelectionPressureAnalyzer = new ValueAnalyzer();
|
---|
346 | ParameterizeAnalyzers();
|
---|
347 | UpdateAnalyzers();
|
---|
348 |
|
---|
349 | Initialize();
|
---|
350 | }
|
---|
351 |
|
---|
352 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
353 | IslandOffspringSelectionGeneticAlgorithm clone = (IslandOffspringSelectionGeneticAlgorithm)base.Clone(cloner);
|
---|
354 | clone.islandQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(islandQualityAnalyzer);
|
---|
355 | clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
|
---|
356 | clone.islandSelectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(islandSelectionPressureAnalyzer);
|
---|
357 | clone.selectionPressureAnalyzer = (ValueAnalyzer)cloner.Clone(selectionPressureAnalyzer);
|
---|
358 | clone.Initialize();
|
---|
359 | return clone;
|
---|
360 | }
|
---|
361 |
|
---|
362 | public override void Prepare() {
|
---|
363 | if (Problem != null) base.Prepare();
|
---|
364 | }
|
---|
365 |
|
---|
366 | #region Events
|
---|
367 | protected override void OnProblemChanged() {
|
---|
368 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
369 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
370 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
371 | ParameterizeSolutionsCreator();
|
---|
372 | ParameterizeMainLoop();
|
---|
373 | ParameterizeSelectors();
|
---|
374 | ParameterizeAnalyzers();
|
---|
375 | ParameterizeIterationBasedOperators();
|
---|
376 | UpdateCrossovers();
|
---|
377 | UpdateMutators();
|
---|
378 | UpdateAnalyzers();
|
---|
379 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
380 | base.OnProblemChanged();
|
---|
381 | }
|
---|
382 |
|
---|
383 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
384 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
385 | ParameterizeSolutionsCreator();
|
---|
386 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
387 | }
|
---|
388 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
389 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
390 | ParameterizeSolutionsCreator();
|
---|
391 | ParameterizeMainLoop();
|
---|
392 | ParameterizeSelectors();
|
---|
393 | ParameterizeAnalyzers();
|
---|
394 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
395 | base.Problem_EvaluatorChanged(sender, e);
|
---|
396 | }
|
---|
397 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
398 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
399 | ParameterizeIterationBasedOperators();
|
---|
400 | UpdateCrossovers();
|
---|
401 | UpdateMutators();
|
---|
402 | UpdateAnalyzers();
|
---|
403 | base.Problem_OperatorsChanged(sender, e);
|
---|
404 | }
|
---|
405 | private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
406 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
407 | ParameterizeSelectors();
|
---|
408 | }
|
---|
409 | private void Elites_ValueChanged(object sender, EventArgs e) {
|
---|
410 | ParameterizeSelectors();
|
---|
411 | }
|
---|
412 | private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
413 | NumberOfIslands.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
414 | ParameterizeSelectors();
|
---|
415 | }
|
---|
416 | private void PopulationSize_ValueChanged(object sender, EventArgs e) {
|
---|
417 | ParameterizeSelectors();
|
---|
418 | }
|
---|
419 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
420 | ParameterizeMainLoop();
|
---|
421 | ParameterizeSelectors();
|
---|
422 | ParameterizeAnalyzers();
|
---|
423 | }
|
---|
424 | private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
|
---|
425 | MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
|
---|
426 | ParameterizeSelectors();
|
---|
427 | }
|
---|
428 | private void MigrationRate_ValueChanged(object sender, EventArgs e) {
|
---|
429 | ParameterizeSelectors();
|
---|
430 | }
|
---|
431 | private void MaximumMigrationsParameter_ValueChanged(object sender, EventArgs e) {
|
---|
432 | MaximumGenerations.ValueChanged += new EventHandler(MaximumMigrations_ValueChanged);
|
---|
433 | ParameterizeComparisonFactorModifiers();
|
---|
434 | }
|
---|
435 | private void MaximumMigrations_ValueChanged(object sender, EventArgs e) {
|
---|
436 | ParameterizeComparisonFactorModifiers();
|
---|
437 | }
|
---|
438 | private void MigrationIntervalParameter_ValueChanged(object sender, EventArgs e) {
|
---|
439 | MigrationInterval.ValueChanged += new EventHandler(MigrationInterval_ValueChanged);
|
---|
440 | ParameterizeComparisonFactorModifiers();
|
---|
441 | }
|
---|
442 | private void MigrationInterval_ValueChanged(object sender, EventArgs e) {
|
---|
443 | ParameterizeComparisonFactorModifiers();
|
---|
444 | }
|
---|
445 | #endregion
|
---|
446 |
|
---|
447 | #region Helpers
|
---|
448 | [StorableHook(HookType.AfterDeserialization)]
|
---|
449 | private void Initialize() {
|
---|
450 | PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
|
---|
451 | PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
452 | MigrationRateParameter.ValueChanged += new EventHandler(MigrationRateParameter_ValueChanged);
|
---|
453 | MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
|
---|
454 | ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
|
---|
455 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
456 | MigrationIntervalParameter.ValueChanged += new EventHandler(MigrationIntervalParameter_ValueChanged);
|
---|
457 | MigrationInterval.ValueChanged += new EventHandler(MigrationInterval_ValueChanged);
|
---|
458 | MaximumGenerationsParameter.ValueChanged += new EventHandler(MaximumMigrationsParameter_ValueChanged);
|
---|
459 | MaximumGenerations.ValueChanged += new EventHandler(MaximumMigrations_ValueChanged);
|
---|
460 | if (Problem != null) {
|
---|
461 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
462 | }
|
---|
463 | }
|
---|
464 | private void ParameterizeSolutionsCreator() {
|
---|
465 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
466 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
467 | }
|
---|
468 | private void ParameterizeMainLoop() {
|
---|
469 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
470 | MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
471 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
472 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
473 | }
|
---|
474 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
475 | if (op is IStochasticOperator)
|
---|
476 | ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
477 | }
|
---|
478 | private void ParameterizeSelectors() {
|
---|
479 | foreach (ISelector selector in SelectorParameter.ValidValues) {
|
---|
480 | selector.CopySelected = new BoolValue(true);
|
---|
481 | selector.NumberOfSelectedSubScopesParameter.Value = null;
|
---|
482 | selector.NumberOfSelectedSubScopesParameter.ActualName = SelectedParentsParameter.Name;
|
---|
483 | ParameterizeStochasticOperator(selector);
|
---|
484 | }
|
---|
485 | foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) {
|
---|
486 | selector.CopySelected = new BoolValue(true);
|
---|
487 | selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value));
|
---|
488 | ParameterizeStochasticOperator(selector);
|
---|
489 | }
|
---|
490 | foreach (IReplacer selector in ImmigrationReplacerParameter.ValidValues) {
|
---|
491 | ParameterizeStochasticOperator(selector);
|
---|
492 | }
|
---|
493 | if (Problem != null) {
|
---|
494 | foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
495 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
496 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
497 | }
|
---|
498 | foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
499 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
500 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
501 | }
|
---|
502 | foreach (ISingleObjectiveReplacer replacer in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) {
|
---|
503 | replacer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
504 | replacer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
505 | }
|
---|
506 | }
|
---|
507 | }
|
---|
508 | private void ParameterizeAnalyzers() {
|
---|
509 | islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
510 | islandQualityAnalyzer.QualityParameter.Depth = 1;
|
---|
511 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
512 | qualityAnalyzer.QualityParameter.Depth = 2;
|
---|
513 |
|
---|
514 | islandSelectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
515 | islandSelectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
|
---|
516 | islandSelectionPressureAnalyzer.ValueParameter.Depth = 0;
|
---|
517 | islandSelectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
|
---|
518 | islandSelectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
|
---|
519 |
|
---|
520 | selectionPressureAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
521 | selectionPressureAnalyzer.Name = "SelectionPressure Analyzer";
|
---|
522 | selectionPressureAnalyzer.ValueParameter.Depth = 1;
|
---|
523 | selectionPressureAnalyzer.ValueParameter.ActualName = "SelectionPressure";
|
---|
524 | selectionPressureAnalyzer.ValuesParameter.ActualName = "Selection Pressure History";
|
---|
525 |
|
---|
526 | if (Problem != null) {
|
---|
527 | islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
528 | islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
529 | islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
530 |
|
---|
531 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
532 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
533 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
534 | }
|
---|
535 | }
|
---|
536 | private void ParameterizeComparisonFactorModifiers() {
|
---|
537 | foreach (IDiscreteDoubleValueModifier modifier in ComparisonFactorModifierParameter.ValidValues) {
|
---|
538 | modifier.IndexParameter.ActualName = "Generations";
|
---|
539 | modifier.EndIndexParameter.Value = new IntValue(MigrationInterval.Value * MaximumGenerations.Value);
|
---|
540 | modifier.EndValueParameter.ActualName = ComparisonFactorUpperBoundParameter.Name;
|
---|
541 | modifier.StartIndexParameter.Value = new IntValue(0);
|
---|
542 | modifier.StartValueParameter.ActualName = ComparisonFactorLowerBoundParameter.Name;
|
---|
543 | modifier.ValueParameter.ActualName = "ComparisonFactor";
|
---|
544 | }
|
---|
545 | }
|
---|
546 | private void ParameterizeIterationBasedOperators() {
|
---|
547 | if (Problem != null) {
|
---|
548 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
549 | op.IterationsParameter.ActualName = "Generations";
|
---|
550 | op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
551 | }
|
---|
552 | }
|
---|
553 | }
|
---|
554 | private void UpdateCrossovers() {
|
---|
555 | ICrossover oldCrossover = CrossoverParameter.Value;
|
---|
556 | CrossoverParameter.ValidValues.Clear();
|
---|
557 | foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
|
---|
558 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
559 | if (oldCrossover != null) {
|
---|
560 | ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
|
---|
561 | if (crossover != null) CrossoverParameter.Value = crossover;
|
---|
562 | }
|
---|
563 | }
|
---|
564 | private void UpdateMutators() {
|
---|
565 | IManipulator oldMutator = MutatorParameter.Value;
|
---|
566 | MutatorParameter.ValidValues.Clear();
|
---|
567 | foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
|
---|
568 | MutatorParameter.ValidValues.Add(mutator);
|
---|
569 | if (oldMutator != null) {
|
---|
570 | IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
|
---|
571 | if (mutator != null) MutatorParameter.Value = mutator;
|
---|
572 | }
|
---|
573 | }
|
---|
574 | private void UpdateAnalyzers() {
|
---|
575 | IslandAnalyzer.Operators.Clear();
|
---|
576 | Analyzer.Operators.Clear();
|
---|
577 | IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
|
---|
578 | IslandAnalyzer.Operators.Add(islandSelectionPressureAnalyzer);
|
---|
579 | if (Problem != null) {
|
---|
580 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>().OrderBy(x => x.Name)) {
|
---|
581 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
582 | param.Depth = 2;
|
---|
583 | Analyzer.Operators.Add(analyzer);
|
---|
584 | }
|
---|
585 | }
|
---|
586 | Analyzer.Operators.Add(qualityAnalyzer);
|
---|
587 | Analyzer.Operators.Add(selectionPressureAnalyzer);
|
---|
588 | }
|
---|
589 | #endregion
|
---|
590 | }
|
---|
591 | }
|
---|