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 System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Algorithms.ALPS.SteadyState {
|
---|
31 | [Item("SteadyStateMatingPoolCreator", "")]
|
---|
32 | [StorableClass]
|
---|
33 | public class SteadyStateMatingPoolCreator : SingleSuccessorOperator {
|
---|
34 | private ILookupParameter<IScope> WorkingScopeParameter {
|
---|
35 | get { return (ILookupParameter<IScope>)Parameters["WorkingScope"]; }
|
---|
36 | }
|
---|
37 | private ILookupParameter<IScope> LayersParameter {
|
---|
38 | get { return (ILookupParameter<IScope>)Parameters["Layers"]; }
|
---|
39 | }
|
---|
40 | private ILookupParameter<IntValue> LayerParameter {
|
---|
41 | get { return (ILookupParameter<IntValue>)Parameters["Layer"]; }
|
---|
42 | }
|
---|
43 | private ILookupParameter<IntArray> AgeLimitsParameter {
|
---|
44 | get { return (ILookupParameter<IntArray>)Parameters["AgeLimits"]; }
|
---|
45 | }
|
---|
46 | private ILookupParameter<IntValue> NumberOfLayersParameter {
|
---|
47 | get { return (ILookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
|
---|
48 | }
|
---|
49 | private ILookupParameter<IntValue> EvaluatedSolutionsParameter {
|
---|
50 | get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
|
---|
51 | }
|
---|
52 | private ILookupParameter<IntValue> PopulationSizeParameter {
|
---|
53 | get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; }
|
---|
54 | }
|
---|
55 |
|
---|
56 | [StorableConstructor]
|
---|
57 | private SteadyStateMatingPoolCreator(bool deserializing)
|
---|
58 | : base(deserializing) { }
|
---|
59 | private SteadyStateMatingPoolCreator(SteadyStateMatingPoolCreator original, Cloner cloner)
|
---|
60 | : base(original, cloner) { }
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
62 | return new SteadyStateMatingPoolCreator(this, cloner);
|
---|
63 | }
|
---|
64 | public SteadyStateMatingPoolCreator()
|
---|
65 | : base() {
|
---|
66 | Parameters.Add(new LookupParameter<IScope>("WorkingScope"));
|
---|
67 | Parameters.Add(new LookupParameter<IScope>("Layers"));
|
---|
68 | Parameters.Add(new LookupParameter<IntValue>("Layer"));
|
---|
69 | Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
|
---|
70 | Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers"));
|
---|
71 | Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
|
---|
72 | Parameters.Add(new LookupParameter<IntValue>("PopulationSize"));
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override IOperation Apply() {
|
---|
77 | int layerNumber = LayerParameter.ActualValue.Value;
|
---|
78 | var workingScope = WorkingScopeParameter.ActualValue;
|
---|
79 | var layers = LayersParameter.ActualValue;
|
---|
80 | var ageLimits = AgeLimitsParameter.ActualValue;
|
---|
81 | int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
|
---|
82 | int evaluations = EvaluatedSolutionsParameter.ActualValue.Value;
|
---|
83 | int popSize = PopulationSizeParameter.ActualValue.Value;
|
---|
84 |
|
---|
85 | var currentLayer = layers.SubScopes[layerNumber].SubScopes;
|
---|
86 | var prevLayer = layerNumber > 0 ? layers.SubScopes[layerNumber - 1].SubScopes : Enumerable.Empty<IScope>();
|
---|
87 |
|
---|
88 | var ageLimit = layerNumber < numberOfLayers - 1 ? ageLimits[layerNumber] : int.MaxValue;
|
---|
89 |
|
---|
90 | var matingPool =
|
---|
91 | from individual in currentLayer.Union(prevLayer)
|
---|
92 | let evalsCreated = ((IntValue)individual.Variables["EvalsCreated"].Value).Value
|
---|
93 | let age = (evaluations - evalsCreated) / popSize
|
---|
94 | where age < ageLimit
|
---|
95 | select (IScope)individual/*.Clone()*/;
|
---|
96 |
|
---|
97 | foreach (var individual in matingPool) {
|
---|
98 | workingScope.SubScopes.Add(individual);
|
---|
99 | }
|
---|
100 | return base.Apply();
|
---|
101 | }
|
---|
102 | }
|
---|
103 | } |
---|