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