Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 12018 was 12018, checked in by pfleck, 9 years ago

#2269

  • merged trunk after 3.3.11 release
  • updated copyright and plugin version in ALPS plugin
  • removed old ALPS samples based on an userdefined alg
File size: 4.5 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Selection;
29
30namespace HeuristicLab.Algorithms.ALPS {
31  [Item("EldersEmigrator", "Moves Individuals which are too old for its current layer up to the next layer.")]
32  [StorableClass]
33  public sealed class EldersEmigrator : AlgorithmOperator {
34
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
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() {
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
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();
61      // TODO: if expression calculator supports int, use expression calculator
62      var countCalculator = new MergingReducerCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" };
63      //var countCalculator = new ExpressionCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
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
73      eldersSelector.CopySelected = new BoolValue(false);
74      eldersSelector.Successor = null;
75
76      shiftToRightMigrator.Successor = mergingProsessor;
77
78      mergingProsessor.Operator = mergingReducer;
79      mergingProsessor.Successor = null;
80
81      mergingReducer.Successor = subScopesCounter;
82
83      subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize";
84      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
85      subScopesCounter.Successor = countCalculator;
86
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";
91      countCalculator.Successor = bestSelector;
92
93      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";
94      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
95      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
96      bestSelector.CopySelected = new BoolValue(false);
97      bestSelector.Successor = rightReducer;
98
99      rightReducer.Successor = null;
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.