Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/DeceptiveTrapProblem.cs @ 11656

Last change on this file since 11656 was 11656, checked in by bgoldman, 9 years ago

#2282 Test Case Creation and first draft of clustering completed.

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Threading.Tasks;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
34  [Item("Deceptive Trap Problem", "Genome encodes completely separable blocks, where each block is fully deceptive.")]
35  [StorableClass]
36  [Creatable("Parameterless Population Pyramid")]
37  public class DeceptiveTrapProblem : BinaryVectorProblem {
38    [StorableConstructor]
39    protected DeceptiveTrapProblem(bool deserializing) : base(deserializing) { }
40    protected DeceptiveTrapProblem(DeceptiveTrapProblem original, Cloner cloner)
41      : base(original, cloner) {
42    }
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new DeceptiveTrapProblem(this, cloner);
45    }
46
47    public override bool Maximization {
48      get { return true; }
49    }
50
51    private const string TrapSizeParameterName = "Trap Size";
52
53    public IFixedValueParameter<IntValue> TrapSizeParameter {
54      get { return (IFixedValueParameter<IntValue>)Parameters[TrapSizeParameterName]; }
55    }
56
57    public int TrapSize {
58      get { return TrapSizeParameter.Value.Value; }
59      set { TrapSizeParameter.Value.Value = value; }
60    }
61    public DeceptiveTrapProblem()
62      : base() {
63      Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(5)));
64    }
65
66    public override double Evaluate(bool[] individual) {
67      if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length.");
68      int total = 0;
69      for (int i = 0; i < individual.Length; i += TrapSize) {
70        int partial = 0;
71        for (int index = i; index < i + TrapSize; index++) {
72          if (individual[index]) partial++;
73        }
74
75        // Make it deceptive
76        if (partial < TrapSize) {
77          partial = TrapSize - partial - 1;
78        }
79        total += partial;
80      }
81      return total;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.