[8313] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16057] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8313] | 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 HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
[8379] | 26 | using HeuristicLab.Optimization;
|
---|
[8313] | 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.RAPGA {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// An operator which represents the main loop of a relevant alleles preserving genetic algorithm.
|
---|
| 35 | /// </summary>
|
---|
| 36 | [Item("RAPGAMainLoop", "An operator which represents the main loop of a relevant alleles preserving genetic algorithm.")]
|
---|
| 37 | [StorableClass]
|
---|
| 38 | public sealed class RAPGAMainLoop : 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 | }
|
---|
| 46 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 47 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 48 | }
|
---|
| 49 | public ValueLookupParameter<IOperator> SelectorParameter {
|
---|
| 50 | get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
|
---|
| 51 | }
|
---|
| 52 | public ValueLookupParameter<IOperator> CrossoverParameter {
|
---|
| 53 | get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; }
|
---|
| 54 | }
|
---|
| 55 | public ValueLookupParameter<PercentValue> MutationProbabilityParameter {
|
---|
| 56 | get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
|
---|
| 57 | }
|
---|
| 58 | public ValueLookupParameter<IOperator> MutatorParameter {
|
---|
| 59 | get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; }
|
---|
| 60 | }
|
---|
| 61 | public ValueLookupParameter<IOperator> EvaluatorParameter {
|
---|
| 62 | get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
|
---|
| 63 | }
|
---|
| 64 | public ValueLookupParameter<IntValue> ElitesParameter {
|
---|
| 65 | get { return (ValueLookupParameter<IntValue>)Parameters["Elites"]; }
|
---|
| 66 | }
|
---|
[9569] | 67 | public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
|
---|
| 68 | get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
|
---|
| 69 | }
|
---|
[8313] | 70 | public ValueLookupParameter<IntValue> MaximumGenerationsParameter {
|
---|
| 71 | get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
| 72 | }
|
---|
| 73 | public ValueLookupParameter<VariableCollection> ResultsParameter {
|
---|
| 74 | get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
| 75 | }
|
---|
| 76 | public ValueLookupParameter<IOperator> AnalyzerParameter {
|
---|
| 77 | get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
| 78 | }
|
---|
| 79 | public ValueLookupParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
| 80 | get { return (ValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
|
---|
| 81 | }
|
---|
| 82 | public ValueLookupParameter<IntValue> PopulationSizeParameter {
|
---|
| 83 | get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
| 84 | }
|
---|
[8330] | 85 | public IValueLookupParameter<IntValue> MinimumPopulationSizeParameter {
|
---|
| 86 | get { return (IValueLookupParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
|
---|
| 87 | }
|
---|
| 88 | public IValueLookupParameter<IntValue> MaximumPopulationSizeParameter {
|
---|
| 89 | get { return (IValueLookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
|
---|
| 90 | }
|
---|
| 91 | public IValueLookupParameter<DoubleValue> ComparisonFactorParameter {
|
---|
| 92 | get { return (IValueLookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
|
---|
| 93 | }
|
---|
| 94 | public IValueLookupParameter<IntValue> EffortParameter {
|
---|
| 95 | get { return (IValueLookupParameter<IntValue>)Parameters["Effort"]; }
|
---|
| 96 | }
|
---|
[8379] | 97 | public IValueLookupParameter<IntValue> BatchSizeParameter {
|
---|
| 98 | get { return (IValueLookupParameter<IntValue>)Parameters["BatchSize"]; }
|
---|
| 99 | }
|
---|
| 100 | public IValueLookupParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
| 101 | get { return (IValueLookupParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
| 102 | }
|
---|
[8313] | 103 | private ScopeParameter CurrentScopeParameter {
|
---|
| 104 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | public IScope CurrentScope {
|
---|
| 108 | get { return CurrentScopeParameter.ActualValue; }
|
---|
| 109 | }
|
---|
| 110 | #endregion
|
---|
| 111 |
|
---|
| 112 | [StorableConstructor]
|
---|
| 113 | private RAPGAMainLoop(bool deserializing) : base(deserializing) { }
|
---|
| 114 | private RAPGAMainLoop(RAPGAMainLoop original, Cloner cloner) : base(original, cloner) { }
|
---|
| 115 | public RAPGAMainLoop()
|
---|
| 116 | : base() {
|
---|
| 117 | Initialize();
|
---|
| 118 | }
|
---|
| 119 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 120 | return new RAPGAMainLoop(this, cloner);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[9591] | 123 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 124 | private void AfterDeserialization() {
|
---|
[9592] | 125 | // BackwardsCompatibility3.3
|
---|
[9591] | 126 | #region Backwards compatible code, remove with 3.4
|
---|
| 127 | if (!Parameters.ContainsKey("ReevaluateElites")) {
|
---|
| 128 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
| 129 | }
|
---|
| 130 | #endregion
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[8313] | 133 | private void Initialize() {
|
---|
| 134 | #region Create parameters
|
---|
| 135 | Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
|
---|
| 136 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
| 137 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
| 138 | Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
|
---|
| 139 | Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
|
---|
| 140 | Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
|
---|
| 141 | Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
|
---|
| 142 | Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
|
---|
| 143 | Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
|
---|
[9569] | 144 | Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
|
---|
[8313] | 145 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed."));
|
---|
| 146 | Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
|
---|
| 147 | Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
|
---|
| 148 | Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
|
---|
| 149 | Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
|
---|
[8330] | 150 | Parameters.Add(new ValueLookupParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions."));
|
---|
| 151 | Parameters.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions."));
|
---|
| 152 | Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor."));
|
---|
| 153 | Parameters.Add(new ValueLookupParameter<IntValue>("Effort", "The maximum number of offspring created in each generation."));
|
---|
[8400] | 154 | Parameters.Add(new ValueLookupParameter<IntValue>("BatchSize", "The number of children that should be created during one iteration of the offspring creation process."));
|
---|
[8379] | 155 | Parameters.Add(new ValueLookupParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
|
---|
[8313] | 156 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
|
---|
| 157 | #endregion
|
---|
| 158 |
|
---|
| 159 | #region Create operators
|
---|
| 160 | VariableCreator variableCreator = new VariableCreator();
|
---|
[8377] | 161 | Assigner assigner1 = new Assigner();
|
---|
[8359] | 162 | ResultsCollector resultsCollector = new ResultsCollector();
|
---|
[8313] | 163 | Placeholder analyzer1 = new Placeholder();
|
---|
| 164 | Placeholder selector = new Placeholder();
|
---|
| 165 | SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor();
|
---|
| 166 | ChildrenCreator childrenCreator = new ChildrenCreator();
|
---|
[8377] | 167 | UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor();
|
---|
[8313] | 168 | Placeholder crossover = new Placeholder();
|
---|
| 169 | StochasticBranch stochasticBranch = new StochasticBranch();
|
---|
| 170 | Placeholder mutator = new Placeholder();
|
---|
| 171 | Placeholder evaluator = new Placeholder();
|
---|
[8377] | 172 | WeightedParentsQualityComparator weightedParentsQualityComparator = new WeightedParentsQualityComparator();
|
---|
| 173 | SubScopesRemover subScopesRemover = new SubScopesRemover();
|
---|
| 174 | IntCounter intCounter1 = new IntCounter();
|
---|
[8385] | 175 | IntCounter intCounter2 = new IntCounter();
|
---|
[8330] | 176 | ConditionalSelector conditionalSelector = new ConditionalSelector();
|
---|
| 177 | RightReducer rightReducer1 = new RightReducer();
|
---|
[8377] | 178 | DuplicatesSelector duplicateSelector = new DuplicatesSelector();
|
---|
| 179 | LeftReducer leftReducer1 = new LeftReducer();
|
---|
| 180 | ProgressiveOffspringPreserver progressiveOffspringSelector = new ProgressiveOffspringPreserver();
|
---|
[8359] | 181 | SubScopesCounter subScopesCounter2 = new SubScopesCounter();
|
---|
[8642] | 182 | ExpressionCalculator calculator1 = new ExpressionCalculator();
|
---|
[8622] | 183 | ConditionalBranch conditionalBranch1 = new ConditionalBranch();
|
---|
[8377] | 184 | Comparator comparator1 = new Comparator();
|
---|
| 185 | ConditionalBranch conditionalBranch2 = new ConditionalBranch();
|
---|
| 186 | LeftReducer leftReducer2 = new LeftReducer();
|
---|
| 187 | SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
|
---|
| 188 | BestSelector bestSelector = new BestSelector();
|
---|
[8330] | 189 | RightReducer rightReducer2 = new RightReducer();
|
---|
[8377] | 190 | ScopeCleaner scopeCleaner = new ScopeCleaner();
|
---|
[8622] | 191 | ScopeRestorer scopeRestorer = new ScopeRestorer();
|
---|
[8313] | 192 | MergingReducer mergingReducer = new MergingReducer();
|
---|
[8385] | 193 | IntCounter intCounter3 = new IntCounter();
|
---|
[8377] | 194 | SubScopesCounter subScopesCounter3 = new SubScopesCounter();
|
---|
[8642] | 195 | ExpressionCalculator calculator2 = new ExpressionCalculator();
|
---|
[8622] | 196 | Comparator comparator2 = new Comparator();
|
---|
| 197 | ConditionalBranch conditionalBranch3 = new ConditionalBranch();
|
---|
[8385] | 198 | Placeholder analyzer2 = new Placeholder();
|
---|
[8330] | 199 | Comparator comparator3 = new Comparator();
|
---|
[8622] | 200 | ConditionalBranch conditionalBranch4 = new ConditionalBranch();
|
---|
[8330] | 201 | Comparator comparator4 = new Comparator();
|
---|
[8622] | 202 | ConditionalBranch conditionalBranch5 = new ConditionalBranch();
|
---|
[8377] | 203 | Assigner assigner3 = new Assigner();
|
---|
| 204 | Assigner assigner4 = new Assigner();
|
---|
[8385] | 205 | Assigner assigner5 = new Assigner();
|
---|
[9569] | 206 | ConditionalBranch reevaluateElitesBranch = new ConditionalBranch();
|
---|
| 207 | UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
|
---|
| 208 | Placeholder evaluator2 = new Placeholder();
|
---|
| 209 | SubScopesCounter subScopesCounter4 = new SubScopesCounter();
|
---|
[8313] | 210 |
|
---|
[8359] | 211 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class RAPGA expects this to be called Generations
|
---|
[8330] | 212 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentPopulationSize", new IntValue(0)));
|
---|
[8377] | 213 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NumberOfCreatedOffspring", new IntValue(0)));
|
---|
| 214 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NumberOfSuccessfulOffspring", new IntValue(0)));
|
---|
| 215 | variableCreator.CollectedValues.Add(new ValueParameter<ScopeList>("OffspringList", new ScopeList()));
|
---|
[8313] | 216 |
|
---|
[8377] | 217 | assigner1.Name = "Initialize CurrentPopulationSize";
|
---|
| 218 | assigner1.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
| 219 | assigner1.RightSideParameter.ActualName = PopulationSizeParameter.Name;
|
---|
[8330] | 220 |
|
---|
[8359] | 221 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
| 222 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentPopulationSize"));
|
---|
| 223 | resultsCollector.ResultsParameter.ActualName = "Results";
|
---|
[8313] | 224 |
|
---|
| 225 | analyzer1.Name = "Analyzer";
|
---|
| 226 | analyzer1.OperatorParameter.ActualName = "Analyzer";
|
---|
| 227 |
|
---|
| 228 | selector.Name = "Selector";
|
---|
| 229 | selector.OperatorParameter.ActualName = "Selector";
|
---|
| 230 |
|
---|
| 231 | childrenCreator.ParentsPerChild = new IntValue(2);
|
---|
| 232 |
|
---|
[8377] | 233 | uniformSubScopesProcessor.Parallel.Value = true;
|
---|
| 234 |
|
---|
[8313] | 235 | crossover.Name = "Crossover";
|
---|
| 236 | crossover.OperatorParameter.ActualName = "Crossover";
|
---|
| 237 |
|
---|
| 238 | stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability";
|
---|
| 239 | stochasticBranch.RandomParameter.ActualName = "Random";
|
---|
| 240 |
|
---|
| 241 | mutator.Name = "Mutator";
|
---|
| 242 | mutator.OperatorParameter.ActualName = "Mutator";
|
---|
| 243 |
|
---|
| 244 | evaluator.Name = "Evaluator";
|
---|
| 245 | evaluator.OperatorParameter.ActualName = "Evaluator";
|
---|
| 246 |
|
---|
[8377] | 247 | weightedParentsQualityComparator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
|
---|
| 248 | weightedParentsQualityComparator.LeftSideParameter.ActualName = QualityParameter.Name;
|
---|
| 249 | weightedParentsQualityComparator.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 250 | weightedParentsQualityComparator.RightSideParameter.ActualName = QualityParameter.Name;
|
---|
| 251 | weightedParentsQualityComparator.ResultParameter.ActualName = "SuccessfulOffspring";
|
---|
[8313] | 252 |
|
---|
[8377] | 253 | subScopesRemover.RemoveAllSubScopes = true;
|
---|
[8359] | 254 |
|
---|
[8385] | 255 | intCounter1.Name = "Increment NumberOfCreatedOffspring";
|
---|
| 256 | intCounter1.ValueParameter.ActualName = "NumberOfCreatedOffspring";
|
---|
[8377] | 257 | intCounter1.Increment = null;
|
---|
[8385] | 258 | intCounter1.IncrementParameter.ActualName = BatchSizeParameter.Name;
|
---|
[8377] | 259 |
|
---|
[8385] | 260 | intCounter2.Name = "Increment EvaluatedSolutions";
|
---|
| 261 | intCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
| 262 | intCounter2.Increment = null;
|
---|
| 263 | intCounter2.IncrementParameter.ActualName = BatchSizeParameter.Name;
|
---|
| 264 |
|
---|
[8330] | 265 | conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring";
|
---|
| 266 | conditionalSelector.ConditionParameter.Depth = 1;
|
---|
| 267 | conditionalSelector.CopySelected.Value = false;
|
---|
[8313] | 268 |
|
---|
[8349] | 269 | duplicateSelector.CopySelected.Value = false;
|
---|
| 270 |
|
---|
[8377] | 271 | progressiveOffspringSelector.OffspringListParameter.ActualName = "OffspringList";
|
---|
| 272 | progressiveOffspringSelector.ElitesParameter.ActualName = ElitesParameter.Name;
|
---|
| 273 | progressiveOffspringSelector.MaximumPopulationSizeParameter.ActualName = MaximumPopulationSizeParameter.Name;
|
---|
[8349] | 274 |
|
---|
[8359] | 275 | subScopesCounter2.Name = "Count Successful Offspring";
|
---|
| 276 | subScopesCounter2.ValueParameter.ActualName = "NumberOfSuccessfulOffspring";
|
---|
[8313] | 277 |
|
---|
[8622] | 278 | calculator1.Name = "NumberOfSuccessfulOffspring == MaximumPopulationSize - Elites";
|
---|
| 279 | calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("NumberOfSuccessfulOffspring"));
|
---|
| 280 | calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize"));
|
---|
| 281 | calculator1.CollectedValues.Add(new ValueLookupParameter<IntValue>("Elites"));
|
---|
| 282 | calculator1.ExpressionParameter.Value = new StringValue("NumberOfSuccessfulOffspring MaximumPopulationSize Elites - ==");
|
---|
| 283 | calculator1.ExpressionResultParameter.ActualName = "Break";
|
---|
[8330] | 284 |
|
---|
[8377] | 285 | conditionalBranch1.Name = "Break?";
|
---|
| 286 | conditionalBranch1.ConditionParameter.ActualName = "Break";
|
---|
[8330] | 287 |
|
---|
[8622] | 288 | comparator1.Name = "NumberOfCreatedOffspring >= Effort";
|
---|
| 289 | comparator1.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 290 | comparator1.LeftSideParameter.ActualName = "NumberOfCreatedOffspring";
|
---|
| 291 | comparator1.RightSideParameter.ActualName = EffortParameter.Name;
|
---|
| 292 | comparator1.ResultParameter.ActualName = "Break";
|
---|
[8330] | 293 |
|
---|
[8377] | 294 | conditionalBranch2.Name = "Break?";
|
---|
| 295 | conditionalBranch2.ConditionParameter.ActualName = "Break";
|
---|
[8330] | 296 |
|
---|
[8377] | 297 | bestSelector.CopySelected = new BoolValue(false);
|
---|
| 298 | bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
| 299 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
|
---|
| 300 | bestSelector.QualityParameter.ActualName = QualityParameter.Name;
|
---|
[8330] | 301 |
|
---|
[8385] | 302 | intCounter3.Name = "Increment Generations";
|
---|
| 303 | intCounter3.Increment = new IntValue(1);
|
---|
| 304 | intCounter3.ValueParameter.ActualName = "Generations";
|
---|
| 305 |
|
---|
| 306 | subScopesCounter3.Name = "Update CurrentPopulationSize";
|
---|
[8377] | 307 | subScopesCounter3.ValueParameter.ActualName = "CurrentPopulationSize";
|
---|
| 308 | subScopesCounter3.AccumulateParameter.Value = new BoolValue(false);
|
---|
| 309 |
|
---|
[8622] | 310 | calculator2.Name = "Evaluate ActualSelectionPressure";
|
---|
| 311 | calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("NumberOfCreatedOffspring"));
|
---|
| 312 | calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("Elites"));
|
---|
| 313 | calculator2.CollectedValues.Add(new ValueLookupParameter<IntValue>("CurrentPopulationSize"));
|
---|
| 314 | calculator2.ExpressionParameter.Value = new StringValue("NumberOfCreatedOffspring Elites + CurrentPopulationSize /");
|
---|
| 315 | calculator2.ExpressionResultParameter.ActualName = "ActualSelectionPressure";
|
---|
[8385] | 316 |
|
---|
[8622] | 317 | comparator2.Name = "CurrentPopulationSize < 1";
|
---|
| 318 | comparator2.Comparison = new Comparison(ComparisonType.Less);
|
---|
| 319 | comparator2.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
| 320 | comparator2.RightSideParameter.Value = new IntValue(1);
|
---|
| 321 | comparator2.ResultParameter.ActualName = "Terminate";
|
---|
| 322 |
|
---|
| 323 | conditionalBranch3.Name = "Terminate?";
|
---|
| 324 | conditionalBranch3.ConditionParameter.ActualName = "Terminate";
|
---|
| 325 |
|
---|
[8385] | 326 | analyzer2.Name = "Analyzer";
|
---|
| 327 | analyzer2.OperatorParameter.ActualName = "Analyzer";
|
---|
| 328 |
|
---|
[8377] | 329 | comparator3.Name = "Generations >= MaximumGenerations";
|
---|
[8330] | 330 | comparator3.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 331 | comparator3.LeftSideParameter.ActualName = "Generations";
|
---|
| 332 | comparator3.ResultParameter.ActualName = "Terminate";
|
---|
| 333 | comparator3.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
|
---|
| 334 |
|
---|
[8622] | 335 | conditionalBranch4.Name = "Terminate?";
|
---|
| 336 | conditionalBranch4.ConditionParameter.ActualName = "Terminate";
|
---|
[8330] | 337 |
|
---|
[8377] | 338 | comparator4.Name = "CurrentPopulationSize < MinimumPopulationSize";
|
---|
[8330] | 339 | comparator4.Comparison = new Comparison(ComparisonType.Less);
|
---|
| 340 | comparator4.LeftSideParameter.ActualName = "CurrentPopulationSize";
|
---|
| 341 | comparator4.RightSideParameter.ActualName = MinimumPopulationSizeParameter.Name;
|
---|
| 342 | comparator4.ResultParameter.ActualName = "Terminate";
|
---|
| 343 |
|
---|
[8622] | 344 | conditionalBranch5.Name = "Terminate?";
|
---|
| 345 | conditionalBranch5.ConditionParameter.ActualName = "Terminate";
|
---|
[8377] | 346 |
|
---|
[8385] | 347 | assigner3.Name = "Reset NumberOfCreatedOffspring";
|
---|
| 348 | assigner3.LeftSideParameter.ActualName = "NumberOfCreatedOffspring";
|
---|
[8377] | 349 | assigner3.RightSideParameter.Value = new IntValue(0);
|
---|
| 350 |
|
---|
[8385] | 351 | assigner4.Name = "Reset NumberOfSuccessfulOffspring";
|
---|
| 352 | assigner4.LeftSideParameter.ActualName = "NumberOfSuccessfulOffspring";
|
---|
| 353 | assigner4.RightSideParameter.Value = new IntValue(0);
|
---|
| 354 |
|
---|
| 355 | assigner5.Name = "Reset OffspringList";
|
---|
| 356 | assigner5.LeftSideParameter.ActualName = "OffspringList";
|
---|
| 357 | assigner5.RightSideParameter.Value = new ScopeList();
|
---|
[9569] | 358 |
|
---|
| 359 | reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites";
|
---|
| 360 | reevaluateElitesBranch.Name = "Reevaluate elites ?";
|
---|
| 361 |
|
---|
| 362 | uniformSubScopesProcessor2.Parallel.Value = true;
|
---|
| 363 |
|
---|
| 364 | evaluator2.Name = "Evaluator (placeholder)";
|
---|
| 365 | evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;
|
---|
| 366 |
|
---|
| 367 | subScopesCounter4.Name = "Increment EvaluatedSolutions";
|
---|
| 368 | subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
|
---|
[8313] | 369 | #endregion
|
---|
| 370 |
|
---|
| 371 | #region Create operator graph
|
---|
| 372 | OperatorGraph.InitialOperator = variableCreator;
|
---|
[8377] | 373 | variableCreator.Successor = assigner1;
|
---|
| 374 | assigner1.Successor = resultsCollector;
|
---|
[8359] | 375 | resultsCollector.Successor = analyzer1;
|
---|
[8313] | 376 | analyzer1.Successor = selector;
|
---|
| 377 | selector.Successor = subScopesProcessor1;
|
---|
| 378 | subScopesProcessor1.Operators.Add(new EmptyOperator());
|
---|
| 379 | subScopesProcessor1.Operators.Add(childrenCreator);
|
---|
[8622] | 380 | subScopesProcessor1.Successor = calculator1;
|
---|
[8377] | 381 | childrenCreator.Successor = uniformSubScopesProcessor;
|
---|
| 382 | uniformSubScopesProcessor.Operator = crossover;
|
---|
[8385] | 383 | uniformSubScopesProcessor.Successor = intCounter1;
|
---|
[8313] | 384 | crossover.Successor = stochasticBranch;
|
---|
| 385 | stochasticBranch.FirstBranch = mutator;
|
---|
| 386 | stochasticBranch.SecondBranch = null;
|
---|
| 387 | mutator.Successor = null;
|
---|
[8377] | 388 | stochasticBranch.Successor = evaluator;
|
---|
| 389 | evaluator.Successor = weightedParentsQualityComparator;
|
---|
| 390 | weightedParentsQualityComparator.Successor = subScopesRemover;
|
---|
[8385] | 391 | intCounter1.Successor = intCounter2;
|
---|
| 392 | intCounter2.Successor = conditionalSelector;
|
---|
[8330] | 393 | conditionalSelector.Successor = rightReducer1;
|
---|
[8377] | 394 | rightReducer1.Successor = duplicateSelector;
|
---|
| 395 | duplicateSelector.Successor = leftReducer1;
|
---|
| 396 | leftReducer1.Successor = progressiveOffspringSelector;
|
---|
| 397 | progressiveOffspringSelector.Successor = subScopesCounter2;
|
---|
[8622] | 398 | calculator1.Successor = conditionalBranch1;
|
---|
| 399 | conditionalBranch1.FalseBranch = comparator1;
|
---|
[8377] | 400 | conditionalBranch1.TrueBranch = subScopesProcessor2;
|
---|
[8622] | 401 | comparator1.Successor = conditionalBranch2;
|
---|
[8377] | 402 | conditionalBranch2.FalseBranch = leftReducer2;
|
---|
| 403 | conditionalBranch2.TrueBranch = subScopesProcessor2;
|
---|
| 404 | leftReducer2.Successor = selector;
|
---|
| 405 | subScopesProcessor2.Operators.Add(bestSelector);
|
---|
| 406 | subScopesProcessor2.Operators.Add(scopeCleaner);
|
---|
[8313] | 407 | subScopesProcessor2.Successor = mergingReducer;
|
---|
[8377] | 408 | bestSelector.Successor = rightReducer2;
|
---|
[9569] | 409 | rightReducer2.Successor = reevaluateElitesBranch;
|
---|
| 410 | reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2;
|
---|
| 411 | uniformSubScopesProcessor2.Operator = evaluator2;
|
---|
| 412 | uniformSubScopesProcessor2.Successor = subScopesCounter4;
|
---|
| 413 | evaluator2.Successor = null;
|
---|
| 414 | subScopesCounter4.Successor = null;
|
---|
| 415 | reevaluateElitesBranch.FalseBranch = null;
|
---|
| 416 | reevaluateElitesBranch.Successor = null;
|
---|
[8622] | 417 | scopeCleaner.Successor = scopeRestorer;
|
---|
| 418 | mergingReducer.Successor = intCounter3;
|
---|
[8385] | 419 | intCounter3.Successor = subScopesCounter3;
|
---|
[8622] | 420 | subScopesCounter3.Successor = calculator2;
|
---|
| 421 | calculator2.Successor = comparator2;
|
---|
| 422 | comparator2.Successor = conditionalBranch3;
|
---|
| 423 | conditionalBranch3.FalseBranch = analyzer2;
|
---|
| 424 | conditionalBranch3.TrueBranch = null;
|
---|
[8377] | 425 | analyzer2.Successor = comparator3;
|
---|
[8622] | 426 | comparator3.Successor = conditionalBranch4;
|
---|
| 427 | conditionalBranch4.FalseBranch = comparator4;
|
---|
[8377] | 428 | conditionalBranch4.TrueBranch = null;
|
---|
| 429 | conditionalBranch4.Successor = null;
|
---|
[8622] | 430 | comparator4.Successor = conditionalBranch5;
|
---|
| 431 | conditionalBranch5.FalseBranch = assigner3;
|
---|
| 432 | conditionalBranch5.TrueBranch = null;
|
---|
| 433 | conditionalBranch5.Successor = null;
|
---|
[8377] | 434 | assigner3.Successor = assigner4;
|
---|
[8385] | 435 | assigner4.Successor = assigner5;
|
---|
| 436 | assigner5.Successor = selector;
|
---|
[8377] | 437 |
|
---|
[8313] | 438 | #endregion
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | public override IOperation Apply() {
|
---|
| 442 | if (CrossoverParameter.ActualName == null)
|
---|
| 443 | return null;
|
---|
| 444 | return base.Apply();
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | }
|
---|