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