[11666] | 1 | #region License Information
|
---|
[11956] | 2 |
|
---|
[11666] | 3 | /* HeuristicLab
|
---|
[11956] | 4 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 5 | *
|
---|
[11666] | 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 |
|
---|
[11666] | 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
[11956] | 31 | namespace HeuristicLab.Problems.BinaryVector {
|
---|
[11666] | 32 | [Item("Deceptive Trap Problem", "Genome encodes completely separable blocks, where each block is fully deceptive.")]
|
---|
| 33 | [StorableClass]
|
---|
[11960] | 34 | [Creatable("Problems")]
|
---|
[11666] | 35 | public class DeceptiveTrapProblem : BinaryVectorProblem {
|
---|
| 36 | [StorableConstructor]
|
---|
| 37 | protected DeceptiveTrapProblem(bool deserializing) : base(deserializing) { }
|
---|
| 38 | protected DeceptiveTrapProblem(DeceptiveTrapProblem original, Cloner cloner)
|
---|
| 39 | : base(original, cloner) {
|
---|
| 40 | }
|
---|
| 41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 42 | return new DeceptiveTrapProblem(this, cloner);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public override bool Maximization {
|
---|
| 46 | get { return true; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | private const string TrapSizeParameterName = "Trap Size";
|
---|
| 50 |
|
---|
| 51 | public IFixedValueParameter<IntValue> TrapSizeParameter {
|
---|
| 52 | get { return (IFixedValueParameter<IntValue>)Parameters[TrapSizeParameterName]; }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public int TrapSize {
|
---|
| 56 | get { return TrapSizeParameter.Value.Value; }
|
---|
| 57 | set { TrapSizeParameter.Value.Value = value; }
|
---|
| 58 | }
|
---|
[11669] | 59 |
|
---|
| 60 | protected virtual int TrapMaximum {
|
---|
[11674] | 61 | get { return TrapSize; }
|
---|
[11669] | 62 | }
|
---|
| 63 |
|
---|
[11666] | 64 | public DeceptiveTrapProblem()
|
---|
| 65 | : base() {
|
---|
[11669] | 66 | Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7)));
|
---|
| 67 | Length = 49;
|
---|
[11666] | 68 | }
|
---|
| 69 |
|
---|
[11672] | 70 | // In the GECCO paper, calculates Equation 3
|
---|
[11674] | 71 | protected virtual int Score(bool[] individual, int trapIndex, int trapSize) {
|
---|
[11669] | 72 | int result = 0;
|
---|
[11672] | 73 | // count number of bits in trap set to 1
|
---|
[11674] | 74 | for (int index = trapIndex; index < trapIndex + trapSize; index++) {
|
---|
[11669] | 75 | if (individual[index]) result++;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | // Make it deceptive
|
---|
[11674] | 79 | if (result < trapSize) {
|
---|
| 80 | result = trapSize - result - 1;
|
---|
[11669] | 81 | }
|
---|
| 82 | return result;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[11666] | 85 | public override double Evaluate(bool[] individual) {
|
---|
| 86 | if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length.");
|
---|
| 87 | int total = 0;
|
---|
[11674] | 88 | var trapSize = TrapSize;
|
---|
| 89 | for (int i = 0; i < individual.Length; i += trapSize) {
|
---|
| 90 | total += Score(individual, i, trapSize);
|
---|
[11666] | 91 | }
|
---|
[11674] | 92 | return (double)(total * trapSize) / (TrapMaximum * individual.Length);
|
---|
[11666] | 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|