Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/DeceptiveStepTrapProblem.cs @ 11838

Last change on this file since 11838 was 11838, checked in by bgoldman, 9 years ago

#2282: Added BEACON to the copyright on P3 files and included comments referring to the publication

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 * and the BEACON Center for the Study of Evolution in Action.
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21#endregion
22
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
30  // This code is based off the publication
31  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
32  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
33  [Item("Deceptive Step Trap Problem", "Genome encodes completely separable blocks, where each block deceptive with fitness plateaus.")]
34  [StorableClass]
35  [Creatable("Parameterless Population Pyramid")]
36  // In the GECCO paper, Section 4.1
37  public class DeceptiveStepTrapProblem : DeceptiveTrapProblem {
38    [StorableConstructor]
39    protected DeceptiveStepTrapProblem(bool deserializing) : base(deserializing) { }
40    protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner)
41      : base(original, cloner) {
42      RegisterParameterEvents();
43    }
44    public override IDeepCloneable Clone(Cloner cloner) {
45      return new DeceptiveStepTrapProblem(this, cloner);
46    }
47
48    private const string StepSizeParameterName = "Step Size";
49
50    public IFixedValueParameter<IntValue> StepSizeParameter {
51      get { return (IFixedValueParameter<IntValue>)Parameters[StepSizeParameterName]; }
52    }
53
54    public int StepSize {
55      get { return StepSizeParameter.Value.Value; }
56      set { StepSizeParameter.Value.Value = value; }
57    }
58
59    public DeceptiveStepTrapProblem()
60      : base() {
61      Parameters.Add(new FixedValueParameter<IntValue>(StepSizeParameterName, "", new IntValue(2)));
62      RegisterParameterEvents();
63    }
64
65    [StorableHook(HookType.AfterDeserialization)]
66    private void AfterDeserialization() {
67      RegisterParameterEvents();
68    }
69
70    private void RegisterParameterEvents() {
71      TrapSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
72      StepSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
73    }
74
75
76    private int offset = -1;
77    private int Offset {
78      get {
79        if (offset == -1) offset = (TrapSize - StepSize) % StepSize;
80        return offset;
81      }
82    }
83
84    protected override int TrapMaximum {
85      get { return (Offset + TrapSize) / StepSize; }
86    }
87
88    protected override int Score(bool[] individual, int trapIndex, int trapSize) {
89      int partial = base.Score(individual, trapIndex, trapSize);
90      // introduce plateaus using integer division
91      return (Offset + partial) / StepSize;
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.