source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersEmigrator.cs @ 11586

Last change on this file since 11586 was 11586, checked in by pfleck, 5 years ago

#2269 Implemented LayerUpdator.

  • Added First/LastSubScopeProcessor.
  • Added two Calculators because ExpressionCalculator does not support required features yet.
  • Added some wiring.
  • Small bugfixes and refactorings.
File size: 4.6 KB
Line 
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
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Selection;
31
32namespace HeuristicLab.Algorithms.ALPS {
33  [Item("EldersEmigrator", "Moves Individuals which are too old for its current layer up to the next layer.")]
34  [StorableClass]
35  public sealed class EldersEmigrator : AlgorithmOperator {
36
37    public IValueLookupParameter<BoolValue> MaximizationParameter {
38      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
39    }
40    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
41      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
42    }
43
44    public SolutionsCreator SolutionsCreator {
45      get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
46    }
47
48    [StorableConstructor]
49    private EldersEmigrator(bool deserializing)
50      : base(deserializing) { }
51    private EldersEmigrator(EldersEmigrator original, Cloner cloner)
52      : base(original, cloner) { }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new EldersEmigrator(this, cloner);
55    }
56    public EldersEmigrator()
57      : base() {
58      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
60
61      var selectorProsessor = new UniformSubScopesProcessor();
62      var eldersSelector = new EldersSelector();
63      var shiftToRightMigrator = new ShiftToRightMigrator();
64      var mergingProsessor = new UniformSubScopesProcessor();
65      var mergingReducer = new MergingReducer();
66      var subScopesCounter = new SubScopesCounter();
67      // TODO: if expression calculator supports int, use expression calculator
68      var countCalculator = new MergingReducerCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
69      //var countCalculator = new ExpressionCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
70      var bestSelector = new BestSelector();
71      var rightReducer = new RightReducer();
72
73
74      OperatorGraph.InitialOperator = selectorProsessor;
75
76      selectorProsessor.Operator = eldersSelector;
77      selectorProsessor.Successor = shiftToRightMigrator;
78
79      eldersSelector.Successor = null;
80
81      shiftToRightMigrator.Successor = mergingProsessor;
82
83      mergingProsessor.Operator = mergingReducer;
84      mergingProsessor.Successor = null;
85
86      mergingReducer.Successor = subScopesCounter;
87
88      subScopesCounter.ValueParameter.ActualName = "NumSubScopes";
89      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
90      subScopesCounter.Successor = countCalculator;
91
92      //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
93      //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumSubScopes"));
94      //countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes PopulationSize < if");
95      //countCalculator.ExpressionResultParameter.ActualName = "NumSubScopes";
96      countCalculator.Successor = bestSelector;
97
98      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "NumSubScopes";
99      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
100      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
101      bestSelector.Successor = rightReducer;
102
103      rightReducer.Successor = null;
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.