Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/07/14 17:25:50 (10 years ago)
Author:
bgoldman
Message:

#2282 Code cleanup, added Deceptive Step Trap problem.

Location:
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/DeceptiveTrapProblem.cs

    r11666 r11669  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    2724using HeuristicLab.Common;
    2825using HeuristicLab.Core;
     
    5956      set { TrapSizeParameter.Value.Value = value; }
    6057    }
     58
     59    protected virtual int TrapMaximum {
     60      get { return TrapSize;  }
     61    }
     62
    6163    public DeceptiveTrapProblem()
    6264      : base() {
    63       Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(5)));
     65      Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7)));
     66      Length = 49;
     67    }
     68
     69    protected virtual int Score(bool[] individual, int trapIndex) {
     70      int result = 0;
     71      for (int index = trapIndex; index < trapIndex + TrapSize; index++) {
     72        if (individual[index]) result++;
     73      }
     74
     75      // Make it deceptive
     76      if (result < TrapSize) {
     77        result = TrapSize - result - 1;
     78      }
     79      return result;
    6480    }
    6581
     
    6884      int total = 0;
    6985      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;
     86        total += Score(individual, i);
    8087      }
    81       return total;
     88      return (double)(total * TrapSize) / (TrapMaximum * individual.Length);
    8289    }
    8390  }
  • branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/EvaluationTracker.cs

    r11666 r11669  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    2724
    2825namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
    2926  public class EvaluationTracker : IBinaryVectorProblem {
    3027    private readonly IBinaryVectorProblem problem;
     28
    3129    private int maxEvaluations;
    3230
    33     private double bestQuality = double.NaN;
     31    #region Properties
    3432    public double BestQuality {
    35       get { return bestQuality; }
     33      get;
     34      private set;
    3635    }
    3736
    38     private int evaluations = 0;
    3937    public int Evaluations {
    40       get { return evaluations; }
     38      get;
     39      private set;
    4140    }
    4241
    43     private int bestFoundOnEvaluation = 0;
    4442    public int BestFoundOnEvaluation {
    45       get { return bestFoundOnEvaluation; }
     43      get;
     44      private set;
    4645    }
    4746
    4847    public bool[] BestSolution {
    49       get; private set;
     48      get;
     49      private set;
    5050    }
     51    #endregion
    5152
    5253    public EvaluationTracker(IBinaryVectorProblem problem, int maxEvaluations) {
     
    5455      this.maxEvaluations = maxEvaluations;
    5556      BestSolution = new bool[0];
     57      BestQuality = double.NaN;
     58      Evaluations = 0;
     59      BestFoundOnEvaluation = 0;
    5660    }
    5761
    5862    public double Evaluate(bool[] individual) {
    59       if (evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    60       evaluations++;
     63      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
     64      Evaluations++;
    6165      double fitness = problem.Evaluate(individual);
    62       if (double.IsNaN(bestQuality) || problem.IsBetter(fitness, bestQuality)) {
    63         bestQuality = fitness;
     66      if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) {
     67        BestQuality = fitness;
    6468        BestSolution = (bool[])individual.Clone();
    65         bestFoundOnEvaluation = evaluations;
     69        BestFoundOnEvaluation = Evaluations;
    6670      }
    6771      return fitness;
    6872    }
    6973
    70 
     74    #region ForwardedInteraface
    7175    public int Length {
    7276      get { return problem.Length; }
     
    7781    public bool IsBetter(double quality, double bestQuality) {
    7882      return problem.IsBetter(quality, bestQuality);
    79     }   
     83    }
     84    #endregion
    8085  }
    8186}
  • branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/HIFFProblem.cs

    r11666 r11669  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    2724using HeuristicLab.Common;
    2825using HeuristicLab.Core;
     
    4845
    4946    public HIFFProblem() : base() {
    50       Length = 32;
     47      Length = 64;
    5148    }
    5249
  • branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/IBinaryVectorProblem.cs

    r11666 r11669  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    27 
    2822namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
    2923  public interface IBinaryVectorProblem {
Note: See TracChangeset for help on using the changeset viewer.