[11585] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2014 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;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using HeuristicLab.Selection;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
| 31 | [Item("EldersEmigrator", "Moves Individuals which are too old for its current layer up to the next layer.")]
|
---|
| 32 | [StorableClass]
|
---|
[11586] | 33 | public sealed class EldersEmigrator : AlgorithmOperator {
|
---|
[11585] | 34 |
|
---|
[11586] | 35 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
| 36 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
| 37 | }
|
---|
| 38 | public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 39 | get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[11585] | 42 | [StorableConstructor]
|
---|
| 43 | private EldersEmigrator(bool deserializing)
|
---|
| 44 | : base(deserializing) { }
|
---|
| 45 | private EldersEmigrator(EldersEmigrator original, Cloner cloner)
|
---|
| 46 | : base(original, cloner) { }
|
---|
| 47 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 48 | return new EldersEmigrator(this, cloner);
|
---|
| 49 | }
|
---|
| 50 | public EldersEmigrator()
|
---|
| 51 | : base() {
|
---|
[11586] | 52 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
| 53 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
|
---|
| 54 |
|
---|
[11585] | 55 | var selectorProsessor = new UniformSubScopesProcessor();
|
---|
| 56 | var eldersSelector = new EldersSelector();
|
---|
| 57 | var shiftToRightMigrator = new ShiftToRightMigrator();
|
---|
| 58 | var mergingProsessor = new UniformSubScopesProcessor();
|
---|
| 59 | var mergingReducer = new MergingReducer();
|
---|
| 60 | var subScopesCounter = new SubScopesCounter();
|
---|
[11586] | 61 | // TODO: if expression calculator supports int, use expression calculator
|
---|
[11676] | 62 | var countCalculator = new MergingReducerCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" };
|
---|
[11586] | 63 | //var countCalculator = new ExpressionCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
|
---|
[11585] | 64 | var bestSelector = new BestSelector();
|
---|
| 65 | var rightReducer = new RightReducer();
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | OperatorGraph.InitialOperator = selectorProsessor;
|
---|
| 69 |
|
---|
| 70 | selectorProsessor.Operator = eldersSelector;
|
---|
| 71 | selectorProsessor.Successor = shiftToRightMigrator;
|
---|
| 72 |
|
---|
[11590] | 73 | eldersSelector.CopySelected = new BoolValue(false);
|
---|
[11585] | 74 | eldersSelector.Successor = null;
|
---|
| 75 |
|
---|
| 76 | shiftToRightMigrator.Successor = mergingProsessor;
|
---|
| 77 |
|
---|
| 78 | mergingProsessor.Operator = mergingReducer;
|
---|
| 79 | mergingProsessor.Successor = null;
|
---|
| 80 |
|
---|
| 81 | mergingReducer.Successor = subScopesCounter;
|
---|
| 82 |
|
---|
[11676] | 83 | subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize";
|
---|
[11585] | 84 | subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
|
---|
| 85 | subScopesCounter.Successor = countCalculator;
|
---|
| 86 |
|
---|
[11586] | 87 | //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
|
---|
| 88 | //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumSubScopes"));
|
---|
| 89 | //countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes PopulationSize < if");
|
---|
| 90 | //countCalculator.ExpressionResultParameter.ActualName = "NumSubScopes";
|
---|
[11585] | 91 | countCalculator.Successor = bestSelector;
|
---|
| 92 |
|
---|
[11676] | 93 | bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";
|
---|
[11586] | 94 | bestSelector.QualityParameter.ActualName = QualityParameter.Name;
|
---|
| 95 | bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
|
---|
[11590] | 96 | bestSelector.CopySelected = new BoolValue(false);
|
---|
[11585] | 97 | bestSelector.Successor = rightReducer;
|
---|
| 98 |
|
---|
| 99 | rightReducer.Successor = null;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | } |
---|