[11580] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12018] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11580] | 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 |
|
---|
[11583] | 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
[11580] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Optimization.Operators;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
| 34 |
|
---|
| 35 | [Item("AlpsGeneticAlgorithmMainLoop", "An ALPS genetic algorithm main loop operator.")]
|
---|
[11585] | 36 | [StorableClass]
|
---|
[11583] | 37 | public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
|
---|
[11580] | 38 | #region Parameter Properties
|
---|
[12045] | 39 | public ValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 40 | get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 41 | }
|
---|
| 42 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 43 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 44 | }
|
---|
[11580] | 45 | public ILookupParameter<IntValue> MaximumGenerationsParameter {
|
---|
| 46 | get { return (ILookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
|
---|
| 47 | }
|
---|
| 48 | public ILookupParameter<IOperator> AnalyzerParameter {
|
---|
| 49 | get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; }
|
---|
| 50 | }
|
---|
| 51 | public ILookupParameter<IOperator> LayerAnalyzerParameter {
|
---|
| 52 | get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
|
---|
| 53 | }
|
---|
| 54 | #endregion
|
---|
| 55 |
|
---|
[11583] | 56 | public GeneticAlgorithmMainLoop MainOperator {
|
---|
| 57 | get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); }
|
---|
| 58 | }
|
---|
[11586] | 59 | public EldersEmigrator EldersEmigrator {
|
---|
| 60 | get { return OperatorGraph.Iterate().OfType<EldersEmigrator>().First(); }
|
---|
| 61 | }
|
---|
[11583] | 62 |
|
---|
[11580] | 63 | [StorableConstructor]
|
---|
| 64 | private AlpsGeneticAlgorithmMainLoop(bool deserializing)
|
---|
| 65 | : base(deserializing) { }
|
---|
| 66 | private AlpsGeneticAlgorithmMainLoop(AlpsGeneticAlgorithmMainLoop original, Cloner cloner)
|
---|
| 67 | : base(original, cloner) { }
|
---|
| 68 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 69 | return new AlpsGeneticAlgorithmMainLoop(this, cloner);
|
---|
| 70 | }
|
---|
| 71 | public AlpsGeneticAlgorithmMainLoop()
|
---|
| 72 | : base() {
|
---|
[12997] | 73 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.") { Hidden = true });
|
---|
[12045] | 74 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
[11580] | 75 | Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
|
---|
| 76 | Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals."));
|
---|
| 77 | Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
|
---|
| 78 |
|
---|
| 79 | var variableCreator = new VariableCreator() { Name = "Initialize" };
|
---|
| 80 | var initLayerAnalyzerProcessor = new SubScopesProcessor();
|
---|
[11590] | 81 | var layerVariableCreator = new VariableCreator() { Name = "Initialize Layer" };
|
---|
[11580] | 82 | var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[11609] | 83 | var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
| 84 | var resultsCollector = new ResultsCollector();
|
---|
[11583] | 85 | var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
|
---|
[12992] | 86 | var matingPoolProcessor = new UniformSubScopesProcessor();
|
---|
[11590] | 87 | var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
|
---|
[13095] | 88 | var mainOperator = AlpsGeneticAlgorithmMainOperator.Create();
|
---|
[11583] | 89 | var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
|
---|
| 90 | var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
|
---|
[11585] | 91 | var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" };
|
---|
[13095] | 92 | var layerOpener = new LayerOpener() { Name = "Open new Layer" };
|
---|
| 93 | var layerReseeder = new LayerReseeder() { Name = "Reseed Layer Zero" };
|
---|
[12992] | 94 | var layerAnalyzerProcessor = new UniformSubScopesProcessor();
|
---|
[12197] | 95 | var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
|
---|
[11580] | 96 | var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
|
---|
[12531] | 97 | var termination = new TerminationOperator();
|
---|
[11580] | 98 |
|
---|
| 99 | OperatorGraph.InitialOperator = variableCreator;
|
---|
| 100 |
|
---|
| 101 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
|
---|
| 102 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastRefresh", new IntValue(0)));
|
---|
[11586] | 103 | variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
|
---|
[11609] | 104 | variableCreator.Successor = initLayerAnalyzerProcessor;
|
---|
[11580] | 105 |
|
---|
[11590] | 106 | initLayerAnalyzerProcessor.Operators.Add(layerVariableCreator);
|
---|
[11609] | 107 | initLayerAnalyzerProcessor.Successor = initAnalyzerPlaceholder;
|
---|
[11580] | 108 |
|
---|
[11590] | 109 | layerVariableCreator.CollectedValues.Add(new ValueParameter<IntValue>("LayerEvaluatedSolutions"));
|
---|
[12071] | 110 | layerVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("LayerResults"));
|
---|
[11590] | 111 | layerVariableCreator.Successor = initLayerAnalyzerPlaceholder;
|
---|
| 112 |
|
---|
[11580] | 113 | initLayerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
| 114 | initLayerAnalyzerPlaceholder.Successor = null;
|
---|
| 115 |
|
---|
[11609] | 116 | initAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
| 117 | initAnalyzerPlaceholder.Successor = resultsCollector;
|
---|
| 118 |
|
---|
| 119 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
|
---|
[12071] | 120 | resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
|
---|
[11609] | 121 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
|
---|
| 122 | resultsCollector.CopyValue = new BoolValue(false);
|
---|
[13031] | 123 | resultsCollector.Successor = matingPoolCreator;
|
---|
[11609] | 124 |
|
---|
[11580] | 125 | matingPoolCreator.Successor = matingPoolProcessor;
|
---|
| 126 |
|
---|
| 127 | matingPoolProcessor.Parallel.Value = true;
|
---|
[11590] | 128 | matingPoolProcessor.Operator = initializeLayer;
|
---|
[11583] | 129 | matingPoolProcessor.Successor = generationsIcrementor;
|
---|
[11580] | 130 |
|
---|
[11590] | 131 | initializeLayer.LeftSideParameter.ActualName = "LayerEvaluatedSolutions";
|
---|
| 132 | initializeLayer.RightSideParameter.Value = new IntValue(0);
|
---|
| 133 | initializeLayer.Successor = mainOperator;
|
---|
| 134 |
|
---|
[11583] | 135 | generationsIcrementor.ValueParameter.ActualName = "Generations";
|
---|
| 136 | generationsIcrementor.Increment = new IntValue(1);
|
---|
| 137 | generationsIcrementor.Successor = evaluatedSolutionsReducer;
|
---|
| 138 |
|
---|
[11676] | 139 | evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
|
---|
[11583] | 140 | evaluatedSolutionsReducer.TargetParameter.ActualName = "EvaluatedSolutions";
|
---|
| 141 | evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 142 | evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
|
---|
| 143 | evaluatedSolutionsReducer.Successor = eldersEmigrator;
|
---|
| 144 |
|
---|
[13095] | 145 | eldersEmigrator.Successor = layerOpener;
|
---|
[11580] | 146 |
|
---|
[13095] | 147 | layerOpener.Successor = layerReseeder;
|
---|
[11580] | 148 |
|
---|
[13095] | 149 | layerReseeder.Successor = layerAnalyzerProcessor;
|
---|
| 150 |
|
---|
[12197] | 151 | layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder;
|
---|
| 152 | layerAnalyzerProcessor.Successor = analyzerPlaceholder;
|
---|
[11580] | 153 |
|
---|
[12197] | 154 | layerAnalyzerPlaceholder.OperatorParameter.ActualName = LayerAnalyzerParameter.Name;
|
---|
[11580] | 155 |
|
---|
| 156 | analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
|
---|
[12531] | 157 | analyzerPlaceholder.Successor = termination;
|
---|
[11580] | 158 |
|
---|
[13031] | 159 | termination.ContinueBranch = matingPoolCreator;
|
---|
[11583] | 160 | }
|
---|
[11580] | 161 | }
|
---|
| 162 | } |
---|