Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveStepTrapProblem.cs @ 17546

Last change on this file since 17546 was 17546, checked in by abeham, 4 years ago

#2521: Introduce class to make parameter change handling easier, fix bug in SingleObjectiveProblem regarding MaximizationChanged

File size: 3.2 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 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 HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.BinaryVectorEncoding;
29using HeuristicLab.Parameters;
30
31namespace HeuristicLab.Problems.Binary {
32  [Item("Deceptive Step Trap Problem", "Genome encodes completely separable blocks, where each block deceptive with fitness plateaus.")]
33  [StorableType("89777145-7979-4B7B-B798-5F7C7E892A21")]
34  [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 230)]
35  public class DeceptiveStepTrapProblem : DeceptiveTrapProblem {
36    [Storable] private int offset = -1;
37    [Storable] public IFixedValueParameter<IntValue> StepSizeParameter { get; private set; }
38
39    public int StepSize {
40      get { return StepSizeParameter.Value.Value; }
41      set { StepSizeParameter.Value.Value = value; }
42    }
43
44    public DeceptiveStepTrapProblem() : base() {
45      Parameters.Add(StepSizeParameter = new FixedValueParameter<IntValue>("Step Size", "", new IntValue(2)));
46      CalculateOffset();
47
48      RegisterParameterEvents();
49    }
50
51    protected override int TrapMaximum {
52      get { return (offset + TrapSize) / StepSize; }
53    }
54
55    protected override int Score(BinaryVector individual, int trapIndex, int trapSize) {
56      int partial = base.Score(individual, trapIndex, trapSize);
57      // introduce plateaus using integer division
58      return (offset + partial) / StepSize;
59    }
60
61    [StorableConstructor]
62    protected DeceptiveStepTrapProblem(StorableConstructorFlag _) : base(_) { }
63
64    [StorableHook(HookType.AfterDeserialization)]
65    private void AfterDeserialization() {
66      RegisterParameterEvents();
67    }
68    protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner)
69      : base(original, cloner) {
70      offset = original.offset;
71      StepSizeParameter = cloner.Clone(original.StepSizeParameter);
72
73      RegisterParameterEvents();
74    }
75    public override IDeepCloneable Clone(Cloner cloner) {
76      return new DeceptiveStepTrapProblem(this, cloner);
77    }
78
79    private void RegisterParameterEvents() {
80      IntValueParameterChangeHandler.Create(StepSizeParameter, CalculateOffset);
81    }
82
83    protected override void TrapSizeOnChanged() {
84      base.TrapSizeOnChanged();
85      CalculateOffset();
86    }
87
88    private void CalculateOffset() {
89      offset = (TrapSize - StepSize) % StepSize;
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.