Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.BinaryVector/3.3/DeceptiveStepTrapProblem.cs @ 11956

Last change on this file since 11956 was 11956, checked in by mkommend, 9 years ago

#2282: Created plugin for binary vector problems.

File size: 3.5 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22#endregion
23
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.BinaryVector {
31  // This code is based off the publication
32  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
33  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
34  [Item("Deceptive Step Trap Problem", "Genome encodes completely separable blocks, where each block deceptive with fitness plateaus.")]
35  [StorableClass]
36  [Creatable("Parameterless Population Pyramid")]
37  // In the GECCO paper, Section 4.1
38  public class DeceptiveStepTrapProblem : DeceptiveTrapProblem {
39    [StorableConstructor]
40    protected DeceptiveStepTrapProblem(bool deserializing) : base(deserializing) { }
41    protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner)
42      : base(original, cloner) {
43      RegisterParameterEvents();
44    }
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new DeceptiveStepTrapProblem(this, cloner);
47    }
48
49    private const string StepSizeParameterName = "Step Size";
50
51    public IFixedValueParameter<IntValue> StepSizeParameter {
52      get { return (IFixedValueParameter<IntValue>)Parameters[StepSizeParameterName]; }
53    }
54
55    public int StepSize {
56      get { return StepSizeParameter.Value.Value; }
57      set { StepSizeParameter.Value.Value = value; }
58    }
59
60    public DeceptiveStepTrapProblem()
61      : base() {
62      Parameters.Add(new FixedValueParameter<IntValue>(StepSizeParameterName, "", new IntValue(2)));
63      RegisterParameterEvents();
64    }
65
66    [StorableHook(HookType.AfterDeserialization)]
67    private void AfterDeserialization() {
68      RegisterParameterEvents();
69    }
70
71    private void RegisterParameterEvents() {
72      TrapSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
73      StepSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
74    }
75
76
77    private int offset = -1;
78    private int Offset {
79      get {
80        if (offset == -1) offset = (TrapSize - StepSize) % StepSize;
81        return offset;
82      }
83    }
84
85    protected override int TrapMaximum {
86      get { return (Offset + TrapSize) / StepSize; }
87    }
88
89    protected override int Score(bool[] individual, int trapIndex, int trapSize) {
90      int partial = base.Score(individual, trapIndex, trapSize);
91      // introduce plateaus using integer division
92      return (Offset + partial) / StepSize;
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.