[3356] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3356] | 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 |
|
---|
[4722] | 22 | using HeuristicLab.Common;
|
---|
[3356] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Optimization;
|
---|
| 27 | using HeuristicLab.Optimization.Operators;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 | using HeuristicLab.Selection;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Algorithms.GeneticAlgorithm {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// An island genetic algorithm main loop operator.
|
---|
| 35 | /// </summary>
|
---|
| 36 | [Item("IslandGeneticAlgorithmMainLoop", "An island genetic algorithm main loop operator.")]
|
---|
| 37 | [StorableClass]
|
---|
| 38 | public sealed class IslandGeneticAlgorithmMainLoop : AlgorithmOperator {
|
---|
| 39 | #region Parameter Properties
|
---|
| 40 | public ValueLookupParameter<IRandom> RandomParameter {
|
---|
| 41 | get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
|
---|
| 42 | }
|
---|
| 43 | public ValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 44 | get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 45 | }
|
---|
[3659] | 46 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
[3356] | 48 | }
|
---|
| 49 | public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 50 | get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
| 51 | }
|
---|
| 52 | public ValueLookupParameter<IntValue> NumberOfIslandsParameter {
|
---|
| 53 | get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfIslands"]; }
|
---|
| 54 | }
|
---|
| 55 | public ValueLookupParameter<IntValue> MigrationIntervalParameter {
|
---|
| 56 | get { return (ValueLookupParameter<IntValue>)Parameters["MigrationInterval"]; }
|
---|
| 57 | }
|
---|
| 58 | public ValueLookupParameter<PercentValue> MigrationRateParameter {
|
---|
| 59 | get { return (ValueLookupParameter<PercentValue>)Parameters["MigrationRate"]; }
|
---|
| 60 | }
|
---|
| 61 | public ValueLookupParameter<IOperator> MigratorParameter {
|
---|
| 62 | get { return (ValueLookupParameter<IOperator>)Parameters["Migrator"]; }
|
---|
| 63 | }
|
---|
| 64 | public ValueLookupParameter<IOperator> EmigrantsSelectorParameter {
|
---|
| 65 | get { return (ValueLookupParameter<IOperator>)Parameters["EmigrantsSelector"]; }
|
---|
| 66 | }
|
---|
[3601] | 67 | public ValueLookupParameter<IOperator> ImmigrationReplacerParameter {
|
---|
| 68 | get { return (ValueLookupParameter<IOperator>)Parameters["ImmigrationReplacer"]; }
|
---|
[3356] | 69 | }
|
---|
| 70 | public ValueLookupParameter<IntValue> PopulationSizeParameter {
|
---|
| 71 | get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
| 72 | }
|
---|
[3609] | 73 | public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
|
---|
| 74 | get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
[3356] | 75 | }
|
---|
| 76 | public ValueLookupParameter<IOperator> SelectorParameter {
|
---|
| 77 | get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
|
---|
| 78 | }
|
---|
| 79 | public ValueLookupParameter<IOperator> CrossoverParameter {
|
---|
| 80 | get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
|
---|
| 81 | }
|
---|
| 82 | public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 83 | get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 84 | }
|
---|
| 85 | public ValueLookupParameter<IOperator> MutatorParameter {
|
---|
| 86 | get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
|
---|
| 87 | }
|
---|
| 88 | public ValueLookupParameter<IOperator> EvaluatorParameter {
|
---|
| 89 | get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
|
---|
| 90 | }
|
---|
| 91 | public ValueLookupParameter<IntValue> ElitesParameter {
|
---|
| 92 | get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 93 | }
|
---|
[9673] | 94 | public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
|
---|
| 95 | get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
| 96 | }
|
---|
[3356] | 97 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 98 | get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 99 | }
|
---|
[3616] | 100 | public ValueLookupParameter<IOperator> AnalyzerParameter {
|
---|
| 101 | get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
[3356] | 102 | }
|
---|
[3650] | 103 | public ValueLookupParameter<IOperator> IslandAnalyzerParameter {
|
---|
| 104 | get { return (ValueLookupParameter<IOperator>)Parameters["IslandAnalyzer"]; }
|
---|
| 105 | }
|
---|
[5351] | 106 | public LookupParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
| 107 | get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
|
---|
| 108 | }
|
---|
[7395] | 109 | public LookupParameter<IntValue> IslandGenerations {
|
---|
| 110 | get { return (LookupParameter<IntValue>)Parameters["IslandGenerations"]; }
|
---|
| 111 | }
|
---|
| 112 | public LookupParameter<IntValue> IslandEvaluatedSolutions {
|
---|
| 113 | get { return (LookupParameter<IntValue>)Parameters["IslandEvaluatedSolutions"]; }
|
---|
| 114 | }
|
---|
| 115 | public ValueLookupParameter<BoolValue> Migrate {
|
---|
| 116 | get { return (ValueLookupParameter<BoolValue>)Parameters["Migrate"]; }
|
---|
| 117 | }
|
---|
[3356] | 118 | #endregion
|
---|
| 119 |
|
---|
| 120 | [StorableConstructor]
|
---|
[4722] | 121 | private IslandGeneticAlgorithmMainLoop(bool deserializing) : base(deserializing) { }
|
---|
| 122 | private IslandGeneticAlgorithmMainLoop(IslandGeneticAlgorithmMainLoop original, Cloner cloner)
|
---|
| 123 | : base(original, cloner) {
|
---|
| 124 | }
|
---|
| 125 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 126 | return new IslandGeneticAlgorithmMainLoop(this, cloner);
|
---|
| 127 | }
|
---|
[3356] | 128 | public IslandGeneticAlgorithmMainLoop()
|
---|
| 129 | : base() {
|
---|
| 130 | #region Create parameters
|
---|
| 131 | Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
|
---|
| 132 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
[3659] | 133 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
[3356] | 134 | Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
|
---|
| 135 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfIslands", "The number of islands."));
|
---|
| 136 | Parameters.Add(new ValueLookupParameter<IntValue>("MigrationInterval", "The number of generations that should pass between migration phases."));
|
---|
| 137 | Parameters.Add(new ValueLookupParameter<PercentValue>("MigrationRate", "The proportion of individuals that should migrate between the islands."));
|
---|
| 138 | Parameters.Add(new ValueLookupParameter<IOperator>("Migrator", "The migration strategy."));
|
---|
| 139 | Parameters.Add(new ValueLookupParameter<IOperator>("EmigrantsSelector", "Selects the individuals that will be migrated."));
|
---|
[3601] | 140 | Parameters.Add(new ValueLookupParameter<IOperator>("ImmigrationReplacer", "Replaces some of the original population with the immigrants."));
|
---|
[3356] | 141 | Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
|
---|
[3609] | 142 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
|
---|
[3356] | 143 | Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 144 | Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
|
---|
| 145 | Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
|
---|
| 146 | Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
|
---|
[7395] | 147 | Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
|
---|
[3356] | 148 | Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
|
---|
[9673] | 149 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
[3356] | 150 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection to store the results."));
|
---|
[3650] | 151 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to the analyze the islands."));
|
---|
| 152 | Parameters.Add(new ValueLookupParameter<IOperator>("IslandAnalyzer", "The operator used to analyze each island."));
|
---|
[5351] | 153 | Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times a solution has been evaluated."));
|
---|
[7395] | 154 | Parameters.Add(new LookupParameter<IntValue>("IslandGenerations", "The number of generations calculated on one island."));
|
---|
| 155 | Parameters.Add(new LookupParameter<IntValue>("IslandEvaluatedSolutions", "The number of times a solution has been evaluated on one island."));
|
---|
| 156 | Parameters.Add(new ValueLookupParameter<BoolValue>("Migrate", "Migrate the island?"));
|
---|
[3356] | 157 | #endregion
|
---|
| 158 |
|
---|
| 159 | #region Create operators
|
---|
| 160 | VariableCreator variableCreator = new VariableCreator();
|
---|
[3609] | 161 | UniformSubScopesProcessor uniformSubScopesProcessor0 = new UniformSubScopesProcessor();
|
---|
| 162 | VariableCreator islandVariableCreator = new VariableCreator();
|
---|
[3616] | 163 | Placeholder islandAnalyzer1 = new Placeholder();
|
---|
[7395] | 164 | LocalRandomCreator localRandomCreator = new LocalRandomCreator();
|
---|
[3650] | 165 | Placeholder analyzer1 = new Placeholder();
|
---|
| 166 | ResultsCollector resultsCollector1 = new ResultsCollector();
|
---|
[3609] | 167 | UniformSubScopesProcessor uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
|
---|
[7395] | 168 | Assigner generationsAssigner = new Assigner();
|
---|
| 169 | Assigner evaluatedSolutionsAssigner = new Assigner();
|
---|
[3609] | 170 | Placeholder selector = new Placeholder();
|
---|
| 171 | SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
|
---|
| 172 | ChildrenCreator childrenCreator = new ChildrenCreator();
|
---|
| 173 | UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
|
---|
| 174 | Placeholder crossover = new Placeholder();
|
---|
| 175 | StochasticBranch stochasticBranch = new StochasticBranch();
|
---|
| 176 | Placeholder mutator = new Placeholder();
|
---|
[5208] | 177 | SubScopesRemover subScopesRemover = new SubScopesRemover();
|
---|
| 178 | UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
|
---|
[3609] | 179 | Placeholder evaluator = new Placeholder();
|
---|
[5356] | 180 | SubScopesCounter subScopesCounter = new SubScopesCounter();
|
---|
[3609] | 181 | SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
|
---|
| 182 | BestSelector bestSelector = new BestSelector();
|
---|
| 183 | RightReducer rightReducer = new RightReducer();
|
---|
| 184 | MergingReducer mergingReducer = new MergingReducer();
|
---|
[7395] | 185 | IntCounter islandGenerationsCounter = new IntCounter();
|
---|
| 186 | Comparator checkIslandGenerationsReachedMaximum = new Comparator();
|
---|
| 187 | ConditionalBranch checkContinueEvolution = new ConditionalBranch();
|
---|
| 188 | DataReducer generationsReducer = new DataReducer();
|
---|
| 189 | DataReducer evaluatedSolutionsReducer = new DataReducer();
|
---|
[3616] | 190 | Placeholder islandAnalyzer2 = new Placeholder();
|
---|
[5351] | 191 | UniformSubScopesProcessor uniformSubScopesProcessor5 = new UniformSubScopesProcessor();
|
---|
[3356] | 192 | Placeholder emigrantsSelector = new Placeholder();
|
---|
[7395] | 193 | IntCounter migrationsCounter = new IntCounter();
|
---|
[3356] | 194 | Placeholder migrator = new Placeholder();
|
---|
[5351] | 195 | UniformSubScopesProcessor uniformSubScopesProcessor6 = new UniformSubScopesProcessor();
|
---|
[3601] | 196 | Placeholder immigrationReplacer = new Placeholder();
|
---|
[3609] | 197 | Comparator generationsComparator = new Comparator();
|
---|
[3650] | 198 | Placeholder analyzer2 = new Placeholder();
|
---|
[3609] | 199 | ConditionalBranch generationsTerminationCondition = new ConditionalBranch();
|
---|
[9673] | 200 | ConditionalBranch reevaluateElitesBranch = new ConditionalBranch();
|
---|
[3356] | 201 |
|
---|
[7395] | 202 |
|
---|
[3356] | 203 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
|
---|
[3609] | 204 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
|
---|
[3750] | 205 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class IslandGeneticAlgorithm expects this to be called Generations
|
---|
[3356] | 206 |
|
---|
[3650] | 207 | islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection()));
|
---|
[7395] | 208 | islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandGenerations", new IntValue(0)));
|
---|
| 209 | islandVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("IslandEvaluatedSolutions", new IntValue(0)));
|
---|
[3356] | 210 |
|
---|
[3650] | 211 | islandAnalyzer1.Name = "Island Analyzer (placeholder)";
|
---|
| 212 | islandAnalyzer1.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
|
---|
[3609] | 213 |
|
---|
[3650] | 214 | analyzer1.Name = "Analyzer (placeholder)";
|
---|
| 215 | analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
[3609] | 216 |
|
---|
[3650] | 217 | resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Migrations"));
|
---|
| 218 | resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
[5351] | 219 | resultsCollector1.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("IslandResults", "Result set for each island", "Results"));
|
---|
[3650] | 220 | resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
|
---|
[3609] | 221 |
|
---|
[7395] | 222 | uniformSubScopesProcessor1.Parallel.Value = true;
|
---|
| 223 |
|
---|
| 224 | generationsAssigner.Name = "Initialize Island Generations";
|
---|
| 225 | generationsAssigner.LeftSideParameter.ActualName = IslandGenerations.Name;
|
---|
| 226 | generationsAssigner.RightSideParameter.Value = new IntValue(0);
|
---|
| 227 |
|
---|
| 228 | evaluatedSolutionsAssigner.Name = "Initialize Island evaluated solutions";
|
---|
| 229 | evaluatedSolutionsAssigner.LeftSideParameter.ActualName = IslandEvaluatedSolutions.Name;
|
---|
| 230 | evaluatedSolutionsAssigner.RightSideParameter.Value = new IntValue(0);
|
---|
| 231 |
|
---|
[3609] | 232 | selector.Name = "Selector (placeholder)";
|
---|
| 233 | selector.OperatorParameter.ActualName = SelectorParameter.Name;
|
---|
[3356] | 234 |
|
---|
[3609] | 235 | childrenCreator.ParentsPerChild = new IntValue(2);
|
---|
| 236 |
|
---|
| 237 | crossover.Name = "Crossover (placeholder)";
|
---|
| 238 | crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
|
---|
| 239 |
|
---|
| 240 | stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
|
---|
[7395] | 241 | //set it to the random number generator of the island
|
---|
| 242 | stochasticBranch.RandomParameter.ActualName = "LocalRandom";
|
---|
[3609] | 243 |
|
---|
| 244 | mutator.Name = "Mutator (placeholder)";
|
---|
| 245 | mutator.OperatorParameter.ActualName = MutatorParameter.Name;
|
---|
| 246 |
|
---|
[5208] | 247 | subScopesRemover.RemoveAllSubScopes = true;
|
---|
| 248 |
|
---|
[3609] | 249 | evaluator.Name = "Evaluator (placeholder)";
|
---|
| 250 | evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 251 |
|
---|
[5356] | 252 | subScopesCounter.Name = "Increment EvaluatedSolutions";
|
---|
[7395] | 253 | subScopesCounter.ValueParameter.ActualName = IslandEvaluatedSolutions.Name;
|
---|
[5356] | 254 |
|
---|
[3609] | 255 | bestSelector.CopySelected = new BoolValue(false);
|
---|
| 256 | bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 257 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
|
---|
| 258 | bestSelector.QualityParameter.ActualName = QualityParameter.Name;
|
---|
| 259 |
|
---|
[7395] | 260 | islandGenerationsCounter.Name = "Increment island generatrions";
|
---|
| 261 | islandGenerationsCounter.ValueParameter.ActualName = IslandGenerations.Name;
|
---|
| 262 | islandGenerationsCounter.Increment = new IntValue(1);
|
---|
[3609] | 263 |
|
---|
[7395] | 264 | checkIslandGenerationsReachedMaximum.LeftSideParameter.ActualName = IslandGenerations.Name;
|
---|
| 265 | checkIslandGenerationsReachedMaximum.RightSideParameter.ActualName = MigrationIntervalParameter.Name;
|
---|
| 266 | checkIslandGenerationsReachedMaximum.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 267 | checkIslandGenerationsReachedMaximum.ResultParameter.ActualName = Migrate.Name;
|
---|
[3611] | 268 |
|
---|
[7395] | 269 | checkContinueEvolution.Name = "Migrate?";
|
---|
| 270 | checkContinueEvolution.ConditionParameter.ActualName = Migrate.Name;
|
---|
| 271 | checkContinueEvolution.FalseBranch = selector;
|
---|
[3609] | 272 |
|
---|
[7395] | 273 | islandAnalyzer2.Name = "Island Analyzer (placeholder)";
|
---|
| 274 | islandAnalyzer2.OperatorParameter.ActualName = IslandAnalyzerParameter.Name;
|
---|
[3609] | 275 |
|
---|
[7395] | 276 | generationsReducer.Name = "Increment Generations";
|
---|
| 277 | generationsReducer.ParameterToReduce.ActualName = islandGenerationsCounter.ValueParameter.ActualName;
|
---|
| 278 | generationsReducer.TargetParameter.ActualName = "Generations";
|
---|
| 279 | generationsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Min);
|
---|
| 280 | generationsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
[3609] | 281 |
|
---|
[7395] | 282 | evaluatedSolutionsReducer.Name = "Increment Evaluated Solutions";
|
---|
| 283 | evaluatedSolutionsReducer.ParameterToReduce.ActualName = IslandEvaluatedSolutions.Name;
|
---|
| 284 | evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
| 285 | evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 286 | evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
[3609] | 287 |
|
---|
[3356] | 288 | emigrantsSelector.Name = "Emigrants Selector (placeholder)";
|
---|
| 289 | emigrantsSelector.OperatorParameter.ActualName = EmigrantsSelectorParameter.Name;
|
---|
| 290 |
|
---|
[7395] | 291 | migrationsCounter.Name = "Increment number of Migrations";
|
---|
| 292 | migrationsCounter.ValueParameter.ActualName = "Migrations";
|
---|
| 293 | migrationsCounter.Increment = new IntValue(1);
|
---|
| 294 |
|
---|
[3356] | 295 | migrator.Name = "Migrator (placeholder)";
|
---|
| 296 | migrator.OperatorParameter.ActualName = MigratorParameter.Name;
|
---|
| 297 |
|
---|
[3601] | 298 | immigrationReplacer.Name = "Immigration Replacer (placeholder)";
|
---|
| 299 | immigrationReplacer.OperatorParameter.ActualName = ImmigrationReplacerParameter.Name;
|
---|
[3356] | 300 |
|
---|
[3611] | 301 | generationsComparator.Name = "Generations >= MaximumGenerations ?";
|
---|
[3609] | 302 | generationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 303 | generationsComparator.LeftSideParameter.ActualName = "Generations";
|
---|
| 304 | generationsComparator.ResultParameter.ActualName = "TerminateGenerations";
|
---|
| 305 | generationsComparator.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
[3356] | 306 |
|
---|
[3650] | 307 | analyzer2.Name = "Analyzer (placeholder)";
|
---|
| 308 | analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
[3356] | 309 |
|
---|
[3611] | 310 | generationsTerminationCondition.Name = "Terminate?";
|
---|
[3609] | 311 | generationsTerminationCondition.ConditionParameter.ActualName = "TerminateGenerations";
|
---|
[9673] | 312 |
|
---|
| 313 | reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
|
---|
| 314 | reevaluateElitesBranch.Name = "Reevaluate elites ?";
|
---|
[3356] | 315 | #endregion
|
---|
| 316 |
|
---|
| 317 | #region Create operator graph
|
---|
| 318 | OperatorGraph.InitialOperator = variableCreator;
|
---|
[3609] | 319 | variableCreator.Successor = uniformSubScopesProcessor0;
|
---|
| 320 | uniformSubScopesProcessor0.Operator = islandVariableCreator;
|
---|
[3650] | 321 | uniformSubScopesProcessor0.Successor = analyzer1;
|
---|
| 322 | islandVariableCreator.Successor = islandAnalyzer1;
|
---|
[9039] | 323 | // BackwardsCompatibility3.3
|
---|
| 324 | //the local randoms are created by the island GA itself and are only here to ensure same algorithm results
|
---|
[9076] | 325 | #region Backwards compatible code, remove local random creator with 3.4 and rewire the operator graph
|
---|
[7395] | 326 | islandAnalyzer1.Successor = localRandomCreator;
|
---|
| 327 | localRandomCreator.Successor = null;
|
---|
[9039] | 328 | #endregion
|
---|
[3650] | 329 | analyzer1.Successor = resultsCollector1;
|
---|
[5351] | 330 | resultsCollector1.Successor = uniformSubScopesProcessor1;
|
---|
[7395] | 331 | uniformSubScopesProcessor1.Operator = generationsAssigner;
|
---|
| 332 | uniformSubScopesProcessor1.Successor = generationsReducer;
|
---|
| 333 | generationsReducer.Successor = evaluatedSolutionsReducer;
|
---|
| 334 | evaluatedSolutionsReducer.Successor = migrationsCounter;
|
---|
| 335 | migrationsCounter.Successor = uniformSubScopesProcessor5;
|
---|
| 336 | generationsAssigner.Successor = evaluatedSolutionsAssigner;
|
---|
| 337 | evaluatedSolutionsAssigner.Successor = selector;
|
---|
[3609] | 338 | selector.Successor = subScopesProcessor1;
|
---|
| 339 | subScopesProcessor1.Operators.Add(new EmptyOperator());
|
---|
| 340 | subScopesProcessor1.Operators.Add(childrenCreator);
|
---|
| 341 | subScopesProcessor1.Successor = subScopesProcessor2;
|
---|
| 342 | childrenCreator.Successor = uniformSubScopesProcessor2;
|
---|
| 343 | uniformSubScopesProcessor2.Operator = crossover;
|
---|
[5208] | 344 | uniformSubScopesProcessor2.Successor = uniformSubScopesProcessor3;
|
---|
[3609] | 345 | crossover.Successor = stochasticBranch;
|
---|
| 346 | stochasticBranch.FirstBranch = mutator;
|
---|
| 347 | stochasticBranch.SecondBranch = null;
|
---|
[5208] | 348 | stochasticBranch.Successor = subScopesRemover;
|
---|
[3609] | 349 | mutator.Successor = null;
|
---|
| 350 | subScopesRemover.Successor = null;
|
---|
[5208] | 351 | uniformSubScopesProcessor3.Operator = evaluator;
|
---|
[5351] | 352 | uniformSubScopesProcessor3.Successor = subScopesCounter;
|
---|
[5208] | 353 | evaluator.Successor = null;
|
---|
[5351] | 354 | subScopesCounter.Successor = null;
|
---|
[3609] | 355 | subScopesProcessor2.Operators.Add(bestSelector);
|
---|
| 356 | subScopesProcessor2.Operators.Add(new EmptyOperator());
|
---|
| 357 | subScopesProcessor2.Successor = mergingReducer;
|
---|
[7395] | 358 | mergingReducer.Successor = islandAnalyzer2;
|
---|
[3609] | 359 | bestSelector.Successor = rightReducer;
|
---|
[9673] | 360 | rightReducer.Successor = reevaluateElitesBranch;
|
---|
| 361 | reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor3;
|
---|
| 362 | reevaluateElitesBranch.FalseBranch = null;
|
---|
| 363 | reevaluateElitesBranch.Successor = null;
|
---|
[7395] | 364 | islandAnalyzer2.Successor = islandGenerationsCounter;
|
---|
| 365 | islandGenerationsCounter.Successor = checkIslandGenerationsReachedMaximum;
|
---|
| 366 | checkIslandGenerationsReachedMaximum.Successor = checkContinueEvolution;
|
---|
[5351] | 367 | uniformSubScopesProcessor5.Operator = emigrantsSelector;
|
---|
[7395] | 368 | emigrantsSelector.Successor = null;
|
---|
[5351] | 369 | uniformSubScopesProcessor5.Successor = migrator;
|
---|
| 370 | migrator.Successor = uniformSubScopesProcessor6;
|
---|
| 371 | uniformSubScopesProcessor6.Operator = immigrationReplacer;
|
---|
[7395] | 372 | uniformSubScopesProcessor6.Successor = generationsComparator;
|
---|
[3650] | 373 | generationsComparator.Successor = analyzer2;
|
---|
[5356] | 374 | analyzer2.Successor = generationsTerminationCondition;
|
---|
[3609] | 375 | generationsTerminationCondition.TrueBranch = null;
|
---|
| 376 | generationsTerminationCondition.FalseBranch = uniformSubScopesProcessor1;
|
---|
| 377 | generationsTerminationCondition.Successor = null;
|
---|
[3356] | 378 | #endregion
|
---|
| 379 | }
|
---|
[3715] | 380 |
|
---|
[9673] | 381 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 382 | private void AfterDeserialization() {
|
---|
| 383 | // BackwardsCompatibility3.3
|
---|
| 384 | #region Backwards compatible code, remove with 3.4
|
---|
| 385 | if (!Parameters.ContainsKey("ReevaluateElites")) {
|
---|
| 386 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
| 387 | }
|
---|
| 388 | #endregion
|
---|
| 389 | }
|
---|
| 390 |
|
---|
[3715] | 391 | public override IOperation Apply() {
|
---|
| 392 | if (CrossoverParameter.ActualValue == null)
|
---|
| 393 | return null;
|
---|
| 394 | return base.Apply();
|
---|
| 395 | }
|
---|
[3356] | 396 | }
|
---|
| 397 | }
|
---|