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.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Optimization.Operators;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 | using HeuristicLab.PluginInfrastructure;
|
---|
34 | using HeuristicLab.Random;
|
---|
35 | using HeuristicLab.Selection;
|
---|
36 | using HeuristicLab.Analysis;
|
---|
37 |
|
---|
38 | namespace HeuristicLab.Algorithms.GeneticAlgorithm {
|
---|
39 | /// <summary>
|
---|
40 | /// An island genetic algorithm.
|
---|
41 | /// </summary>
|
---|
42 | [Item("Island Genetic Algorithm", "An island genetic algorithm.")]
|
---|
43 | [Creatable("Algorithms")]
|
---|
44 | [StorableClass]
|
---|
45 | public sealed class IslandGeneticAlgorithm : EngineAlgorithm {
|
---|
46 |
|
---|
47 | #region Problem Properties
|
---|
48 | public override Type ProblemType {
|
---|
49 | get { return typeof(ISingleObjectiveProblem); }
|
---|
50 | }
|
---|
51 | public new ISingleObjectiveProblem Problem {
|
---|
52 | get { return (ISingleObjectiveProblem)base.Problem; }
|
---|
53 | set { base.Problem = value; }
|
---|
54 | }
|
---|
55 | #endregion
|
---|
56 |
|
---|
57 | #region Parameter Properties
|
---|
58 | private ValueParameter<IntValue> SeedParameter {
|
---|
59 | get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
|
---|
60 | }
|
---|
61 | private ValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
62 | get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
|
---|
63 | }
|
---|
64 | private ValueParameter<IntValue> NumberOfIslandsParameter {
|
---|
65 | get { return (ValueParameter<IntValue>)Parameters["NumberOfIslands"]; }
|
---|
66 | }
|
---|
67 | private ValueParameter<IntValue> MigrationIntervalParameter {
|
---|
68 | get { return (ValueParameter<IntValue>)Parameters["MigrationInterval"]; }
|
---|
69 | }
|
---|
70 | private ValueParameter<PercentValue> MigrationRateParameter {
|
---|
71 | get { return (ValueParameter<PercentValue>)Parameters["MigrationRate"]; }
|
---|
72 | }
|
---|
73 | private ConstrainedValueParameter<IMigrator> MigratorParameter {
|
---|
74 | get { return (ConstrainedValueParameter<IMigrator>)Parameters["Migrator"]; }
|
---|
75 | }
|
---|
76 | private ConstrainedValueParameter<ISelector> EmigrantsSelectorParameter {
|
---|
77 | get { return (ConstrainedValueParameter<ISelector>)Parameters["EmigrantsSelector"]; }
|
---|
78 | }
|
---|
79 | private ConstrainedValueParameter<IReplacer> ImmigrationReplacerParameter {
|
---|
80 | get { return (ConstrainedValueParameter<IReplacer>)Parameters["ImmigrationReplacer"]; }
|
---|
81 | }
|
---|
82 | private ValueParameter<IntValue> PopulationSizeParameter {
|
---|
83 | get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
84 | }
|
---|
85 | private ValueParameter<IntValue> MaximumGenerationsParameter {
|
---|
86 | get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
87 | }
|
---|
88 | private ConstrainedValueParameter<ISelector> SelectorParameter {
|
---|
89 | get { return (ConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
|
---|
90 | }
|
---|
91 | private ConstrainedValueParameter<ICrossover> CrossoverParameter {
|
---|
92 | get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
|
---|
93 | }
|
---|
94 | private ValueParameter<PercentValue> MutationProbabilityParameter {
|
---|
95 | get { return (ValueParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
96 | }
|
---|
97 | private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
|
---|
98 | get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
|
---|
99 | }
|
---|
100 | private ValueParameter<IntValue> ElitesParameter {
|
---|
101 | get { return (ValueParameter<IntValue>)Parameters["Elites"]; }
|
---|
102 | }
|
---|
103 | private ValueParameter<MultiAnalyzer> AnalyzerParameter {
|
---|
104 | get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
|
---|
105 | }
|
---|
106 | private ValueParameter<MultiAnalyzer> IslandAnalyzerParameter {
|
---|
107 | get { return (ValueParameter<MultiAnalyzer>)Parameters["IslandAnalyzer"]; }
|
---|
108 | }
|
---|
109 | #endregion
|
---|
110 |
|
---|
111 | #region Properties
|
---|
112 | public IntValue Seed {
|
---|
113 | get { return SeedParameter.Value; }
|
---|
114 | set { SeedParameter.Value = value; }
|
---|
115 | }
|
---|
116 | public BoolValue SetSeedRandomly {
|
---|
117 | get { return SetSeedRandomlyParameter.Value; }
|
---|
118 | set { SetSeedRandomlyParameter.Value = value; }
|
---|
119 | }
|
---|
120 | public IntValue NumberOfIslands {
|
---|
121 | get { return NumberOfIslandsParameter.Value; }
|
---|
122 | set { NumberOfIslandsParameter.Value = value; }
|
---|
123 | }
|
---|
124 | public IntValue MigrationInterval {
|
---|
125 | get { return MigrationIntervalParameter.Value; }
|
---|
126 | set { MigrationIntervalParameter.Value = value; }
|
---|
127 | }
|
---|
128 | public PercentValue MigrationRate {
|
---|
129 | get { return MigrationRateParameter.Value; }
|
---|
130 | set { MigrationRateParameter.Value = value; }
|
---|
131 | }
|
---|
132 | public IMigrator Migrator {
|
---|
133 | get { return MigratorParameter.Value; }
|
---|
134 | set { MigratorParameter.Value = value; }
|
---|
135 | }
|
---|
136 | public ISelector EmigrantsSelector {
|
---|
137 | get { return EmigrantsSelectorParameter.Value; }
|
---|
138 | set { EmigrantsSelectorParameter.Value = value; }
|
---|
139 | }
|
---|
140 | public IReplacer ImmigrationReplacer {
|
---|
141 | get { return ImmigrationReplacerParameter.Value; }
|
---|
142 | set { ImmigrationReplacerParameter.Value = value; }
|
---|
143 | }
|
---|
144 | public IntValue PopulationSize {
|
---|
145 | get { return PopulationSizeParameter.Value; }
|
---|
146 | set { PopulationSizeParameter.Value = value; }
|
---|
147 | }
|
---|
148 | public IntValue MaximumGenerations {
|
---|
149 | get { return MaximumGenerationsParameter.Value; }
|
---|
150 | set { MaximumGenerationsParameter.Value = value; }
|
---|
151 | }
|
---|
152 | public ISelector Selector {
|
---|
153 | get { return SelectorParameter.Value; }
|
---|
154 | set { SelectorParameter.Value = value; }
|
---|
155 | }
|
---|
156 | public ICrossover Crossover {
|
---|
157 | get { return CrossoverParameter.Value; }
|
---|
158 | set { CrossoverParameter.Value = value; }
|
---|
159 | }
|
---|
160 | public PercentValue MutationProbability {
|
---|
161 | get { return MutationProbabilityParameter.Value; }
|
---|
162 | set { MutationProbabilityParameter.Value = value; }
|
---|
163 | }
|
---|
164 | public IManipulator Mutator {
|
---|
165 | get { return MutatorParameter.Value; }
|
---|
166 | set { MutatorParameter.Value = value; }
|
---|
167 | }
|
---|
168 | public IntValue Elites {
|
---|
169 | get { return ElitesParameter.Value; }
|
---|
170 | set { ElitesParameter.Value = value; }
|
---|
171 | }
|
---|
172 | public MultiAnalyzer Analyzer {
|
---|
173 | get { return AnalyzerParameter.Value; }
|
---|
174 | set { AnalyzerParameter.Value = value; }
|
---|
175 | }
|
---|
176 | public MultiAnalyzer IslandAnalyzer {
|
---|
177 | get { return IslandAnalyzerParameter.Value; }
|
---|
178 | set { IslandAnalyzerParameter.Value = value; }
|
---|
179 | }
|
---|
180 | private RandomCreator RandomCreator {
|
---|
181 | get { return (RandomCreator)OperatorGraph.InitialOperator; }
|
---|
182 | }
|
---|
183 | private UniformSubScopesProcessor IslandProcessor {
|
---|
184 | get { return ((RandomCreator.Successor as SubScopesCreator).Successor as UniformSubScopesProcessor); }
|
---|
185 | }
|
---|
186 | private SolutionsCreator SolutionsCreator {
|
---|
187 | get { return (SolutionsCreator)IslandProcessor.Operator; }
|
---|
188 | }
|
---|
189 | private IslandGeneticAlgorithmMainLoop MainLoop {
|
---|
190 | get { return (IslandGeneticAlgorithmMainLoop)IslandProcessor.Successor; }
|
---|
191 | }
|
---|
192 | [Storable]
|
---|
193 | private BestAverageWorstQualityAnalyzer islandQualityAnalyzer;
|
---|
194 | [Storable]
|
---|
195 | private BestAverageWorstQualityAnalyzer qualityAnalyzer;
|
---|
196 | #endregion
|
---|
197 |
|
---|
198 | [StorableConstructor]
|
---|
199 | private IslandGeneticAlgorithm(bool deserializing) : base(deserializing) { }
|
---|
200 | public IslandGeneticAlgorithm()
|
---|
201 | : base() {
|
---|
202 | Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
203 | Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
204 | Parameters.Add(new ValueParameter<IntValue>("NumberOfIslands", "The number of islands.", new IntValue(5)));
|
---|
205 | Parameters.Add(new ValueParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases.", new IntValue(20)));
|
---|
206 | Parameters.Add(new ValueParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands.", new PercentValue(0.15)));
|
---|
207 | Parameters.Add(new ConstrainedValueParameter<IMigrator>("Migrator", "The migration strategy."));
|
---|
208 | Parameters.Add(new ConstrainedValueParameter<ISelector>("EmigrantsSelector", "Selects the individuals that will be migrated."));
|
---|
209 | Parameters.Add(new ConstrainedValueParameter<IReplacer>("ImmigrationReplacer", "Selects the population from the unification of the original population and the immigrants."));
|
---|
210 | Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
|
---|
211 | Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
|
---|
212 | Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
|
---|
213 | Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
|
---|
214 | Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
|
---|
215 | Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
|
---|
216 | Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
|
---|
217 | Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
|
---|
218 | Parameters.Add(new ValueParameter<MultiAnalyzer>("IslandAnalyzer", "The operator used to analyze each island.", new MultiAnalyzer()));
|
---|
219 |
|
---|
220 | RandomCreator randomCreator = new RandomCreator();
|
---|
221 | SubScopesCreator populationCreator = new SubScopesCreator();
|
---|
222 | UniformSubScopesProcessor ussp1 = new UniformSubScopesProcessor();
|
---|
223 | SolutionsCreator solutionsCreator = new SolutionsCreator();
|
---|
224 | IslandGeneticAlgorithmMainLoop mainLoop = new IslandGeneticAlgorithmMainLoop();
|
---|
225 | OperatorGraph.InitialOperator = randomCreator;
|
---|
226 |
|
---|
227 | randomCreator.RandomParameter.ActualName = "Random";
|
---|
228 | randomCreator.SeedParameter.ActualName = SeedParameter.Name;
|
---|
229 | randomCreator.SeedParameter.Value = null;
|
---|
230 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
|
---|
231 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
232 | randomCreator.Successor = populationCreator;
|
---|
233 |
|
---|
234 | populationCreator.NumberOfSubScopesParameter.ActualName = NumberOfIslandsParameter.Name;
|
---|
235 | populationCreator.Successor = ussp1;
|
---|
236 |
|
---|
237 | ussp1.Operator = solutionsCreator;
|
---|
238 | ussp1.Successor = mainLoop;
|
---|
239 |
|
---|
240 | solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
|
---|
241 | solutionsCreator.Successor = null;
|
---|
242 |
|
---|
243 | mainLoop.EmigrantsSelectorParameter.ActualName = EmigrantsSelectorParameter.Name;
|
---|
244 | mainLoop.ImmigrationReplacerParameter.ActualName = ImmigrationReplacerParameter.Name;
|
---|
245 | mainLoop.MaximumGenerationsParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
246 | mainLoop.MigrationIntervalParameter.ActualName = MigrationIntervalParameter.Name;
|
---|
247 | mainLoop.MigrationRateParameter.ActualName = MigrationRateParameter.Name;
|
---|
248 | mainLoop.MigratorParameter.ActualName = MigratorParameter.Name;
|
---|
249 | mainLoop.NumberOfIslandsParameter.ActualName = NumberOfIslandsParameter.Name;
|
---|
250 | mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
|
---|
251 | mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
|
---|
252 | mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
253 | mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
|
---|
254 | mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
255 | mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
|
---|
256 | mainLoop.ResultsParameter.ActualName = "Results";
|
---|
257 | mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
|
---|
258 | mainLoop.IslandAnalyzerParameter.ActualName = IslandAnalyzerParameter.Name;
|
---|
259 | mainLoop.Successor = null;
|
---|
260 |
|
---|
261 | foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
|
---|
262 | SelectorParameter.ValidValues.Add(selector);
|
---|
263 | ISelector proportionalSelector = SelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("ProportionalSelector"));
|
---|
264 | if (proportionalSelector != null) SelectorParameter.Value = proportionalSelector;
|
---|
265 |
|
---|
266 | foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name))
|
---|
267 | EmigrantsSelectorParameter.ValidValues.Add(selector);
|
---|
268 |
|
---|
269 | foreach (IReplacer replacer in ApplicationManager.Manager.GetInstances<IReplacer>().OrderBy(x => x.Name))
|
---|
270 | ImmigrationReplacerParameter.ValidValues.Add(replacer);
|
---|
271 |
|
---|
272 | ParameterizeSelectors();
|
---|
273 |
|
---|
274 | foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
|
---|
275 | MigratorParameter.ValidValues.Add(migrator);
|
---|
276 |
|
---|
277 | qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
278 | islandQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
|
---|
279 | ParameterizeAnalyzers();
|
---|
280 | UpdateAnalyzers();
|
---|
281 |
|
---|
282 | Initialize();
|
---|
283 | }
|
---|
284 |
|
---|
285 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
286 | IslandGeneticAlgorithm clone = (IslandGeneticAlgorithm)base.Clone(cloner);
|
---|
287 | clone.islandQualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(islandQualityAnalyzer);
|
---|
288 | clone.qualityAnalyzer = (BestAverageWorstQualityAnalyzer)cloner.Clone(qualityAnalyzer);
|
---|
289 | clone.Initialize();
|
---|
290 | return clone;
|
---|
291 | }
|
---|
292 |
|
---|
293 | public override void Prepare() {
|
---|
294 | if (Problem != null) base.Prepare();
|
---|
295 | }
|
---|
296 |
|
---|
297 | #region Events
|
---|
298 | protected override void OnProblemChanged() {
|
---|
299 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
300 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
301 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
302 | ParameterizeSolutionsCreator();
|
---|
303 | ParameterizeMainLoop();
|
---|
304 | ParameterizeSelectors();
|
---|
305 | ParameterizeAnalyzers();
|
---|
306 | ParameterizeIterationBasedOperators();
|
---|
307 | UpdateCrossovers();
|
---|
308 | UpdateMutators();
|
---|
309 | UpdateAnalyzers();
|
---|
310 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
311 | base.OnProblemChanged();
|
---|
312 | }
|
---|
313 |
|
---|
314 | protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
|
---|
315 | ParameterizeStochasticOperator(Problem.SolutionCreator);
|
---|
316 | ParameterizeSolutionsCreator();
|
---|
317 | base.Problem_SolutionCreatorChanged(sender, e);
|
---|
318 | }
|
---|
319 | protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
|
---|
320 | ParameterizeStochasticOperator(Problem.Evaluator);
|
---|
321 | ParameterizeSolutionsCreator();
|
---|
322 | ParameterizeMainLoop();
|
---|
323 | ParameterizeSelectors();
|
---|
324 | ParameterizeAnalyzers();
|
---|
325 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
326 | base.Problem_EvaluatorChanged(sender, e);
|
---|
327 | }
|
---|
328 | protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
|
---|
329 | foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
|
---|
330 | ParameterizeIterationBasedOperators();
|
---|
331 | UpdateCrossovers();
|
---|
332 | UpdateMutators();
|
---|
333 | UpdateAnalyzers();
|
---|
334 | base.Problem_OperatorsChanged(sender, e);
|
---|
335 | }
|
---|
336 | private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
337 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
338 | ParameterizeSelectors();
|
---|
339 | }
|
---|
340 | private void Elites_ValueChanged(object sender, EventArgs e) {
|
---|
341 | ParameterizeSelectors();
|
---|
342 | }
|
---|
343 | private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
344 | NumberOfIslands.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
345 | ParameterizeSelectors();
|
---|
346 | }
|
---|
347 | private void PopulationSize_ValueChanged(object sender, EventArgs e) {
|
---|
348 | ParameterizeSelectors();
|
---|
349 | }
|
---|
350 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
351 | ParameterizeMainLoop();
|
---|
352 | ParameterizeSelectors();
|
---|
353 | ParameterizeAnalyzers();
|
---|
354 | }
|
---|
355 | private void MigrationRateParameter_ValueChanged(object sender, EventArgs e) {
|
---|
356 | MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
|
---|
357 | ParameterizeSelectors();
|
---|
358 | }
|
---|
359 | private void MigrationRate_ValueChanged(object sender, EventArgs e) {
|
---|
360 | ParameterizeSelectors();
|
---|
361 | }
|
---|
362 | #endregion
|
---|
363 |
|
---|
364 | #region Helpers
|
---|
365 | [StorableHook(HookType.AfterDeserialization)]
|
---|
366 | private void Initialize() {
|
---|
367 | PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
|
---|
368 | PopulationSize.ValueChanged += new EventHandler(PopulationSize_ValueChanged);
|
---|
369 | MigrationRateParameter.ValueChanged += new EventHandler(MigrationRateParameter_ValueChanged);
|
---|
370 | MigrationRate.ValueChanged += new EventHandler(MigrationRate_ValueChanged);
|
---|
371 | ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
|
---|
372 | Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
|
---|
373 | if (Problem != null) {
|
---|
374 | Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
375 | }
|
---|
376 | }
|
---|
377 | private void ParameterizeSolutionsCreator() {
|
---|
378 | SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
379 | SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
|
---|
380 | }
|
---|
381 | private void ParameterizeMainLoop() {
|
---|
382 | MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
383 | MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
|
---|
384 | MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
385 | MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
386 | }
|
---|
387 | private void ParameterizeStochasticOperator(IOperator op) {
|
---|
388 | if (op is IStochasticOperator)
|
---|
389 | ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
|
---|
390 | }
|
---|
391 | private void ParameterizeSelectors() {
|
---|
392 | foreach (ISelector selector in SelectorParameter.ValidValues) {
|
---|
393 | selector.CopySelected = new BoolValue(true);
|
---|
394 | selector.NumberOfSelectedSubScopesParameter.Value = new IntValue(2 * (PopulationSize.Value - Elites.Value));
|
---|
395 | ParameterizeStochasticOperator(selector);
|
---|
396 | }
|
---|
397 | foreach (ISelector selector in EmigrantsSelectorParameter.ValidValues) {
|
---|
398 | selector.CopySelected = new BoolValue(true);
|
---|
399 | selector.NumberOfSelectedSubScopesParameter.Value = new IntValue((int)Math.Ceiling(PopulationSize.Value * MigrationRate.Value));
|
---|
400 | ParameterizeStochasticOperator(selector);
|
---|
401 | }
|
---|
402 | foreach (IReplacer replacer in ImmigrationReplacerParameter.ValidValues) {
|
---|
403 | ParameterizeStochasticOperator(replacer);
|
---|
404 | }
|
---|
405 | if (Problem != null) {
|
---|
406 | foreach (ISingleObjectiveSelector selector in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
407 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
408 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
409 | }
|
---|
410 | foreach (ISingleObjectiveSelector selector in EmigrantsSelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
|
---|
411 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
412 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
413 | }
|
---|
414 | foreach (ISingleObjectiveReplacer selector in ImmigrationReplacerParameter.ValidValues.OfType<ISingleObjectiveReplacer>()) {
|
---|
415 | selector.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
416 | selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
417 | }
|
---|
418 | }
|
---|
419 | }
|
---|
420 | private void ParameterizeAnalyzers() {
|
---|
421 | islandQualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
422 | islandQualityAnalyzer.QualityParameter.Depth = 1;
|
---|
423 | qualityAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
424 | qualityAnalyzer.QualityParameter.Depth = 2;
|
---|
425 |
|
---|
426 | if (Problem != null) {
|
---|
427 | islandQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
428 | islandQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
429 | islandQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
430 | qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
|
---|
431 | qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
|
---|
432 | qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
|
---|
433 | }
|
---|
434 | }
|
---|
435 | private void ParameterizeIterationBasedOperators() {
|
---|
436 | if (Problem != null) {
|
---|
437 | foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
|
---|
438 | op.IterationsParameter.ActualName = "Generations";
|
---|
439 | op.MaximumIterationsParameter.ActualName = "MaximumGenerations";
|
---|
440 | }
|
---|
441 | }
|
---|
442 | }
|
---|
443 | private void UpdateCrossovers() {
|
---|
444 | ICrossover oldCrossover = CrossoverParameter.Value;
|
---|
445 | CrossoverParameter.ValidValues.Clear();
|
---|
446 | foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
|
---|
447 | CrossoverParameter.ValidValues.Add(crossover);
|
---|
448 | if (oldCrossover != null) {
|
---|
449 | ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
|
---|
450 | if (crossover != null) CrossoverParameter.Value = crossover;
|
---|
451 | }
|
---|
452 | }
|
---|
453 | private void UpdateMutators() {
|
---|
454 | IManipulator oldMutator = MutatorParameter.Value;
|
---|
455 | MutatorParameter.ValidValues.Clear();
|
---|
456 | foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name))
|
---|
457 | MutatorParameter.ValidValues.Add(mutator);
|
---|
458 | if (oldMutator != null) {
|
---|
459 | IManipulator mutator = MutatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMutator.GetType());
|
---|
460 | if (mutator != null) MutatorParameter.Value = mutator;
|
---|
461 | }
|
---|
462 | }
|
---|
463 | private void UpdateAnalyzers() {
|
---|
464 | IslandAnalyzer.Operators.Clear();
|
---|
465 | Analyzer.Operators.Clear();
|
---|
466 | IslandAnalyzer.Operators.Add(islandQualityAnalyzer);
|
---|
467 | if (Problem != null) {
|
---|
468 | foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
|
---|
469 | foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
|
---|
470 | param.Depth = 2;
|
---|
471 | Analyzer.Operators.Add(analyzer);
|
---|
472 | }
|
---|
473 | }
|
---|
474 | Analyzer.Operators.Add(qualityAnalyzer);
|
---|
475 | }
|
---|
476 | #endregion
|
---|
477 | }
|
---|
478 | }
|
---|