[12120] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 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 HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[12136] | 24 | using HeuristicLab.Data;
|
---|
[12120] | 25 | using HeuristicLab.Operators;
|
---|
[12138] | 26 | using HeuristicLab.Optimization;
|
---|
[12136] | 27 | using HeuristicLab.Optimization.Operators;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
[12120] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Algorithms.ALPS.SteadyState {
|
---|
| 32 | [Item("AlpsSsGeneticAlgorithmMainLoop", "An ALPS steady-state genetic algorithm main loop operator.")]
|
---|
| 33 | [StorableClass]
|
---|
[12571] | 34 | public sealed class AlpsSsGeneticAlgorithmMainLoop : AlgorithmOperator {
|
---|
[12136] | 35 | #region Parameter Properties
|
---|
| 36 | public ValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 37 | get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 38 | }
|
---|
| 39 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 40 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 41 | }
|
---|
| 42 | public ILookupParameter<IntValue> MaximumIterationsParameter {
|
---|
| 43 | get { return (ILookupParameter<IntValue>)Parameters["MaximumIterations"]; }
|
---|
| 44 | }
|
---|
| 45 | public ILookupParameter<IOperator> AnalyzerParameter {
|
---|
| 46 | get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
| 47 | }
|
---|
| 48 | public ILookupParameter<IOperator> LayerAnalyzerParameter {
|
---|
| 49 | get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
|
---|
| 50 | }
|
---|
| 51 | #endregion
|
---|
| 52 |
|
---|
[12120] | 53 | [StorableConstructor]
|
---|
| 54 | private AlpsSsGeneticAlgorithmMainLoop(bool deserializing)
|
---|
| 55 | : base(deserializing) { }
|
---|
| 56 | private AlpsSsGeneticAlgorithmMainLoop(AlpsSsGeneticAlgorithmMainLoop original, Cloner cloner)
|
---|
| 57 | : base(original, cloner) { }
|
---|
| 58 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 59 | return new AlpsSsGeneticAlgorithmMainLoop(this, cloner);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public AlpsSsGeneticAlgorithmMainLoop()
|
---|
| 63 | : base() {
|
---|
[12136] | 64 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
| 65 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
| 66 | Parameters.Add(new LookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations that the algorithm should process."));
|
---|
| 67 | Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals."));
|
---|
| 68 | Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
|
---|
| 69 |
|
---|
| 70 | var variableCreator = new VariableCreator() { Name = "Initialize" };
|
---|
[12192] | 71 | var resultsColletor = new ResultsCollector();
|
---|
[12159] | 72 | var layersProcessor = new NamedSubScopeProcessor() { Name = "Process Layers" };
|
---|
[12192] | 73 | var initializeBatchIteration = new Assigner() { Name = "Initialize BatchIterations" };
|
---|
| 74 | var randomLayerProcessor = new RandomLayerProcessor() { Name = "Select a layer" };
|
---|
[12136] | 75 | var isLayerZeroComperator = new Comparator() { Name = "IsLayerZero = Layer == 0" };
|
---|
| 76 | var isLayerZeroBranch = new ConditionalBranch() { Name = "IsLayerZero?" };
|
---|
| 77 | var isDoInitBranch = new ConditionalBranch() { Name = "DoInit?" };
|
---|
| 78 | var setTargetIndedxToNextInit = new Assigner() { Name = "TargetIndex = NextInit" };
|
---|
| 79 | var incrementNextInit = new IntCounter() { Name = "Incr. NextInit" };
|
---|
[12223] | 80 | var checkInitFinished = new Comparator() { Name = "DoInit = NextInit < LayerSize" };
|
---|
[12171] | 81 | var workingScopeProcessor = new NamedSubScopeProcessor() { Name = "WorkingScope Processor" };
|
---|
[12136] | 82 | var createRandomIndividual = new SolutionsCreator() { Name = "Create random Individual" };
|
---|
| 83 | var initializeAgeProcessor = new UniformSubScopesProcessor();
|
---|
| 84 | var initializeAge = new Assigner() { Name = "Initialize Age" };
|
---|
[12171] | 85 | var removeEmptySubscope = new SubScopesRemover() { Name = "Remove empty subscope (from solutioncreator)" };
|
---|
[12220] | 86 | var layerSorter = new SubScopesSorter() { Name = "Sort Layer" };
|
---|
[12136] | 87 | var selectRandomTargetIndex = new RandomIntAssigner();
|
---|
| 88 | var matingPoolCreator = new SteadyStateMatingPoolCreator() { Name = "Create MatingPool" };
|
---|
[12159] | 89 | var matingPoolProcessor = new NamedSubScopeProcessor() { Name = "Process MatingPool" };
|
---|
[12136] | 90 | var matingPoolSize = new SubScopesCounter() { Name = "MatingPoolSize" };
|
---|
| 91 | var matingPoolSizeMin2 = new Comparator() { Name = "ValidParents = MatingPoolSize >= 2" };
|
---|
| 92 | var validParentsBranch = new ConditionalBranch() { Name = "ValidParents?" };
|
---|
[12138] | 93 | var mainOperator = new AlpsSsGeneticAlgorithmMainOperator();
|
---|
[12136] | 94 | var reactivateInit = new Assigner() { Name = "DoInit = true" };
|
---|
[12171] | 95 | var resetNextInit = new Assigner() { Name = "NextInit = 1" };
|
---|
[12223] | 96 | var resetTargetIndex = new Assigner() { Name = "TargetIndex = MatingPoolSize" };
|
---|
[12142] | 97 | var tryMoveUp = new AlpsSsMover() { Name = "Try Move Up" };
|
---|
[12270] | 98 | var incrementLocalEvaluations = new IntCounter() { Name = "Incr. local EvaluatedSolutions" };
|
---|
[12192] | 99 | var incrementBatchIterations = new IntCounter() { Name = "Incr. BatchIterations" };
|
---|
| 100 | var batchFinishedComperator = new Comparator() { Name = "BatchFinished = BatchIterations >= BatchSize" };
|
---|
| 101 | var batchFinishedBranch = new ConditionalBranch() { Name = "BatchFinished?" };
|
---|
[12138] | 102 | var incrIterations = new IntCounter() { Name = "Incr. Iterations" };
|
---|
[12270] | 103 | var updateEvaluatedSolutions = new IntCounter() { Name = "Update EvaluatedSolutions" };
|
---|
[12142] | 104 | var layerAnalyzerProcessor = new UniformSubScopesProcessor();
|
---|
| 105 | var layerAnalyzer = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[12138] | 106 | var analyzer = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
[12534] | 107 | var termination = new TerminationOperator();
|
---|
[12136] | 108 |
|
---|
| 109 |
|
---|
| 110 | OperatorGraph.InitialOperator = variableCreator;
|
---|
| 111 |
|
---|
| 112 | variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("DoInit", new BoolValue(false)));
|
---|
| 113 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NextInit", new IntValue(0)));
|
---|
| 114 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
|
---|
| 115 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TargetIndex", new IntValue(0)));
|
---|
[12142] | 116 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
|
---|
| 117 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("MatingPoolSize", new IntValue(0)));
|
---|
| 118 | variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("ValidParents", new BoolValue(false)));
|
---|
[12159] | 119 | variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("IsLayerZero", new BoolValue(false)));
|
---|
[12192] | 120 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("BatchIterations", new IntValue(0)));
|
---|
| 121 | variableCreator.Successor = resultsColletor;
|
---|
[12136] | 122 |
|
---|
[12192] | 123 | resultsColletor.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
|
---|
| 124 | resultsColletor.Successor = layersProcessor;
|
---|
| 125 |
|
---|
[12220] | 126 | layersProcessor.TargetScopeParameter.ActualName = "LayersScope";
|
---|
[12192] | 127 | layersProcessor.Operator = initializeBatchIteration;
|
---|
[12159] | 128 |
|
---|
[12192] | 129 | initializeBatchIteration.LeftSideParameter.ActualName = "BatchIterations";
|
---|
| 130 | initializeBatchIteration.RightSideParameter.Value = new IntValue(0);
|
---|
| 131 | initializeBatchIteration.Successor = randomLayerProcessor;
|
---|
[12136] | 132 |
|
---|
[12192] | 133 | randomLayerProcessor.Operator = isLayerZeroComperator;
|
---|
| 134 | randomLayerProcessor.Successor = incrementBatchIterations;
|
---|
| 135 |
|
---|
[12136] | 136 | isLayerZeroComperator.LeftSideParameter.ActualName = "Layer";
|
---|
| 137 | isLayerZeroComperator.RightSideParameter.Value = new IntValue(0);
|
---|
| 138 | isLayerZeroComperator.ResultParameter.ActualName = "IsLayerZero";
|
---|
| 139 | isLayerZeroComperator.Comparison = new Comparison(ComparisonType.Equal);
|
---|
| 140 | isLayerZeroComperator.Successor = isLayerZeroBranch;
|
---|
| 141 |
|
---|
| 142 | isLayerZeroBranch.ConditionParameter.ActualName = "IsLayerZero";
|
---|
| 143 | isLayerZeroBranch.TrueBranch = isDoInitBranch;
|
---|
[12220] | 144 | isLayerZeroBranch.FalseBranch = layerSorter;
|
---|
[12136] | 145 | isLayerZeroBranch.Successor = tryMoveUp;
|
---|
| 146 |
|
---|
| 147 | isDoInitBranch.ConditionParameter.ActualName = "DoInit";
|
---|
| 148 | isDoInitBranch.TrueBranch = setTargetIndedxToNextInit;
|
---|
[12220] | 149 | isDoInitBranch.FalseBranch = layerSorter;
|
---|
[12136] | 150 |
|
---|
| 151 | setTargetIndedxToNextInit.LeftSideParameter.ActualName = "TargetIndex";
|
---|
| 152 | setTargetIndedxToNextInit.RightSideParameter.ActualName = "NextInit";
|
---|
| 153 | setTargetIndedxToNextInit.Successor = incrementNextInit;
|
---|
| 154 |
|
---|
| 155 | incrementNextInit.ValueParameter.ActualName = "NextInit";
|
---|
| 156 | incrementNextInit.Increment = new IntValue(1);
|
---|
| 157 | incrementNextInit.Successor = checkInitFinished;
|
---|
| 158 |
|
---|
| 159 | checkInitFinished.LeftSideParameter.ActualName = "NextInit";
|
---|
[12223] | 160 | checkInitFinished.RightSideParameter.ActualName = "LayerSize";
|
---|
| 161 | checkInitFinished.Comparison = new Comparison(ComparisonType.Less);
|
---|
[12136] | 162 | checkInitFinished.ResultParameter.ActualName = "DoInit";
|
---|
[12171] | 163 | checkInitFinished.Successor = workingScopeProcessor;
|
---|
[12136] | 164 |
|
---|
[12171] | 165 | workingScopeProcessor.Operator = createRandomIndividual;
|
---|
| 166 | workingScopeProcessor.TargetScopeParameter.ActualName = "WorkingScope";
|
---|
[12136] | 167 |
|
---|
| 168 | createRandomIndividual.NumberOfSolutions = new IntValue(1);
|
---|
| 169 | createRandomIndividual.Successor = initializeAgeProcessor;
|
---|
| 170 |
|
---|
| 171 | initializeAgeProcessor.Operator = initializeAge;
|
---|
[12171] | 172 | initializeAgeProcessor.Successor = removeEmptySubscope;
|
---|
[12136] | 173 |
|
---|
| 174 | initializeAge.LeftSideParameter.ActualName = "EvalsCreated";
|
---|
[12270] | 175 | initializeAge.RightSideParameter.ActualName = "LocalEvaluatedSolutions";
|
---|
[12136] | 176 |
|
---|
[12220] | 177 | layerSorter.ValueParameter.ActualName = "Quality";
|
---|
| 178 | layerSorter.DescendingParameter.ActualName = "Maximization";
|
---|
| 179 | layerSorter.Successor = selectRandomTargetIndex;
|
---|
| 180 |
|
---|
[12136] | 181 | selectRandomTargetIndex.LeftSideParameter.ActualName = "TargetIndex";
|
---|
[12220] | 182 | selectRandomTargetIndex.MinimumParameter.ActualName = "Elites";
|
---|
| 183 | selectRandomTargetIndex.MinimumParameter.Value = null;
|
---|
[12159] | 184 | selectRandomTargetIndex.MaximumParameter.ActualName = "LayerSize";
|
---|
[12142] | 185 | selectRandomTargetIndex.MaximumParameter.Value = null;
|
---|
[12159] | 186 | selectRandomTargetIndex.Successor = matingPoolCreator;
|
---|
[12136] | 187 |
|
---|
[12159] | 188 | matingPoolCreator.Successor = matingPoolProcessor;
|
---|
[12136] | 189 |
|
---|
[12159] | 190 | matingPoolProcessor.Operator = matingPoolSize;
|
---|
| 191 | matingPoolProcessor.TargetScopeParameter.ActualName = "WorkingScope";
|
---|
[12136] | 192 |
|
---|
| 193 | matingPoolSize.ValueParameter.ActualName = "MatingPoolSize";
|
---|
[12150] | 194 | matingPoolSize.AccumulateParameter.Value = new BoolValue(false);
|
---|
[12136] | 195 | matingPoolSize.Successor = matingPoolSizeMin2;
|
---|
| 196 |
|
---|
| 197 | matingPoolSizeMin2.LeftSideParameter.ActualName = "MatingPoolSize";
|
---|
| 198 | matingPoolSizeMin2.RightSideParameter.Value = new IntValue(2);
|
---|
| 199 | matingPoolSizeMin2.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
|
---|
| 200 | matingPoolSizeMin2.ResultParameter.ActualName = "ValidParents";
|
---|
| 201 | matingPoolSizeMin2.Successor = validParentsBranch;
|
---|
| 202 |
|
---|
[12138] | 203 | validParentsBranch.ConditionParameter.ActualName = "ValidParents";
|
---|
[12136] | 204 | validParentsBranch.TrueBranch = mainOperator;
|
---|
| 205 | validParentsBranch.FalseBranch = reactivateInit;
|
---|
| 206 |
|
---|
[12171] | 207 | reactivateInit.Successor = resetNextInit;
|
---|
[12136] | 208 | reactivateInit.LeftSideParameter.ActualName = "DoInit";
|
---|
| 209 | reactivateInit.RightSideParameter.Value = new BoolValue(true);
|
---|
| 210 |
|
---|
[12171] | 211 | resetNextInit.Successor = resetTargetIndex;
|
---|
| 212 | resetNextInit.LeftSideParameter.ActualName = "NextInit";
|
---|
| 213 | resetNextInit.RightSideParameter.Value = new IntValue(1);
|
---|
[12136] | 214 |
|
---|
| 215 | resetTargetIndex.LeftSideParameter.ActualName = "TargetIndex";
|
---|
[12223] | 216 | resetTargetIndex.RightSideParameter.ActualName = "MatingPoolSize";
|
---|
[12171] | 217 | resetTargetIndex.Successor = createRandomIndividual;
|
---|
[12136] | 218 |
|
---|
[12270] | 219 | tryMoveUp.Successor = incrementLocalEvaluations;
|
---|
[12136] | 220 |
|
---|
[12270] | 221 | incrementLocalEvaluations.ValueParameter.ActualName = "LocalEvaluatedSolutions";
|
---|
| 222 | incrementLocalEvaluations.Increment = new IntValue(1);
|
---|
[12150] | 223 |
|
---|
[12192] | 224 | incrementBatchIterations.ValueParameter.ActualName = "BatchIterations";
|
---|
| 225 | incrementBatchIterations.Increment = new IntValue(1);
|
---|
| 226 | incrementBatchIterations.Successor = batchFinishedComperator;
|
---|
| 227 |
|
---|
| 228 | batchFinishedComperator.LeftSideParameter.ActualName = "BatchIterations";
|
---|
| 229 | batchFinishedComperator.RightSideParameter.ActualName = "BatchSize";
|
---|
| 230 | batchFinishedComperator.ResultParameter.ActualName = "BatchFinished";
|
---|
| 231 | batchFinishedComperator.Successor = batchFinishedBranch;
|
---|
| 232 |
|
---|
| 233 | batchFinishedBranch.ConditionParameter.ActualName = "BatchFinished";
|
---|
| 234 | batchFinishedBranch.TrueBranch = incrIterations;
|
---|
| 235 | batchFinishedBranch.FalseBranch = randomLayerProcessor;
|
---|
| 236 |
|
---|
[12138] | 237 | incrIterations.ValueParameter.ActualName = "Iterations";
|
---|
| 238 | incrIterations.Increment = new IntValue(1);
|
---|
[12270] | 239 | incrIterations.Successor = updateEvaluatedSolutions;
|
---|
[12138] | 240 |
|
---|
[12270] | 241 | updateEvaluatedSolutions.ValueParameter.ActualName = "EvaluatedSolutions";
|
---|
| 242 | updateEvaluatedSolutions.IncrementParameter.ActualName = "BatchSize";
|
---|
| 243 | updateEvaluatedSolutions.IncrementParameter.Value = null;
|
---|
| 244 | updateEvaluatedSolutions.Successor = layerAnalyzerProcessor;
|
---|
[12192] | 245 |
|
---|
[12142] | 246 | layerAnalyzerProcessor.Operator = layerAnalyzer;
|
---|
| 247 | layerAnalyzerProcessor.Successor = analyzer;
|
---|
| 248 |
|
---|
| 249 | layerAnalyzer.OperatorParameter.ActualName = "LayerAnalyzer";
|
---|
| 250 |
|
---|
[12138] | 251 | analyzer.OperatorParameter.ActualName = "Analyzer";
|
---|
[12534] | 252 | analyzer.Successor = termination;
|
---|
[12138] | 253 |
|
---|
[12534] | 254 | termination.ContinueBranch = initializeBatchIteration;
|
---|
[12120] | 255 | }
|
---|
| 256 | }
|
---|
| 257 | } |
---|