[11669] | 1 | #region License Information
|
---|
[11956] | 2 |
|
---|
[11669] | 3 | /* HeuristicLab
|
---|
[15584] | 4 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11669] | 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 | */
|
---|
[11956] | 21 |
|
---|
[11669] | 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
[11987] | 27 | using HeuristicLab.Encodings.BinaryVectorEncoding;
|
---|
[11669] | 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
[11987] | 31 | namespace HeuristicLab.Problems.Binary {
|
---|
[11669] | 32 | [Item("Deceptive Step Trap Problem", "Genome encodes completely separable blocks, where each block deceptive with fitness plateaus.")]
|
---|
| 33 | [StorableClass]
|
---|
[12708] | 34 | [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 230)]
|
---|
[11669] | 35 | public class DeceptiveStepTrapProblem : DeceptiveTrapProblem {
|
---|
| 36 | [StorableConstructor]
|
---|
| 37 | protected DeceptiveStepTrapProblem(bool deserializing) : base(deserializing) { }
|
---|
| 38 | protected DeceptiveStepTrapProblem(DeceptiveStepTrapProblem original, Cloner cloner)
|
---|
| 39 | : base(original, cloner) {
|
---|
[11674] | 40 | RegisterParameterEvents();
|
---|
[11669] | 41 | }
|
---|
| 42 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 43 | return new DeceptiveStepTrapProblem(this, cloner);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | private const string StepSizeParameterName = "Step Size";
|
---|
| 47 |
|
---|
| 48 | public IFixedValueParameter<IntValue> StepSizeParameter {
|
---|
| 49 | get { return (IFixedValueParameter<IntValue>)Parameters[StepSizeParameterName]; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public int StepSize {
|
---|
| 53 | get { return StepSizeParameter.Value.Value; }
|
---|
| 54 | set { StepSizeParameter.Value.Value = value; }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public DeceptiveStepTrapProblem()
|
---|
| 58 | : base() {
|
---|
| 59 | Parameters.Add(new FixedValueParameter<IntValue>(StepSizeParameterName, "", new IntValue(2)));
|
---|
[11674] | 60 | RegisterParameterEvents();
|
---|
[11669] | 61 | }
|
---|
| 62 |
|
---|
[11674] | 63 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 64 | private void AfterDeserialization() {
|
---|
| 65 | RegisterParameterEvents();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private void RegisterParameterEvents() {
|
---|
| 69 | TrapSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
|
---|
| 70 | StepSizeParameter.Value.ValueChanged += (o, e) => { offset = -1; };
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | private int offset = -1;
|
---|
[11669] | 75 | private int Offset {
|
---|
[11674] | 76 | get {
|
---|
| 77 | if (offset == -1) offset = (TrapSize - StepSize) % StepSize;
|
---|
| 78 | return offset;
|
---|
| 79 | }
|
---|
[11669] | 80 | }
|
---|
| 81 |
|
---|
| 82 | protected override int TrapMaximum {
|
---|
| 83 | get { return (Offset + TrapSize) / StepSize; }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[11987] | 86 | protected override int Score(BinaryVector individual, int trapIndex, int trapSize) {
|
---|
[11674] | 87 | int partial = base.Score(individual, trapIndex, trapSize);
|
---|
[11669] | 88 | // introduce plateaus using integer division
|
---|
| 89 | return (Offset + partial) / StepSize;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|