Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/HIFFProblem.cs @ 11838

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

#2282: Added BEACON to the copyright on P3 files and included comments referring to the publication

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 * and the BEACON Center for the Study of Evolution in Action.
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#endregion
22
23using System;
24using System.Collections.Generic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
30  // This code is based off the publication
31  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
32  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
33  [Item("Hierararchical If and only If problem", "Genome evaluated in nested subsets to see if each subset contains either all 0s or all 1s.")]
34  [StorableClass]
35  [Creatable("Parameterless Population Pyramid")]
36  public class HIFFProblem : BinaryVectorProblem {
37    [StorableConstructor]
38    protected HIFFProblem(bool deserializing) : base(deserializing) { }
39    protected HIFFProblem(HIFFProblem original, Cloner cloner)
40      : base(original, cloner) {
41    }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new HIFFProblem(this, cloner);
44    }
45
46    public override bool Maximization {
47      get { return true; }
48    }
49
50    public HIFFProblem() : base() {
51      Length = 64;
52    }
53    // In the GECCO paper, Section 4.1
54    public override double Evaluate(bool[] individual) {
55      int[] level = new int[individual.Length];
56      int levelLength = individual.Length;
57
58      // Initialize the level to the current solution
59      for (int i = 0; i < levelLength; i++) {
60        level[i] = Convert.ToInt32(individual[i]);
61      }
62      int power = 1;
63      int nextLength = levelLength / 2;
64      int total = 0;
65      int maximum = 0;
66
67      // Keep going while the next level actual has bits in it
68      while (nextLength > 0) {
69        int[] nextLevel = new int[nextLength];
70        // Construct the next level using the current level
71        for (int i = 0; i + 1 < levelLength; i += 2) {
72          if (level[i] == level[i + 1] && level[i] != -1) {
73            // Score points for a correct setting at this level
74            total += power;
75            nextLevel[i / 2] = level[i];
76          } else {
77            nextLevel[i / 2] = -1;
78          }
79          // Keep track of the maximum possible score
80          maximum += power;
81        }
82        level = nextLevel;
83        levelLength = nextLength;
84        nextLength = levelLength / 2;
85        power *= 2;
86      }
87
88      // Convert to percentage of total
89      return (double)total / maximum;
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.