Changeset 11669 for branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems
- Timestamp:
- 12/07/14 17:25:50 (10 years ago)
- 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 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 using System.Text;26 using System.Threading.Tasks;27 24 using HeuristicLab.Common; 28 25 using HeuristicLab.Core; … … 59 56 set { TrapSizeParameter.Value.Value = value; } 60 57 } 58 59 protected virtual int TrapMaximum { 60 get { return TrapSize; } 61 } 62 61 63 public DeceptiveTrapProblem() 62 64 : 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; 64 80 } 65 81 … … 68 84 int total = 0; 69 85 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); 80 87 } 81 return total;88 return (double)(total * TrapSize) / (TrapMaximum * individual.Length); 82 89 } 83 90 } -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/EvaluationTracker.cs
r11666 r11669 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 using System.Text;26 using System.Threading.Tasks;27 24 28 25 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { 29 26 public class EvaluationTracker : IBinaryVectorProblem { 30 27 private readonly IBinaryVectorProblem problem; 28 31 29 private int maxEvaluations; 32 30 33 private double bestQuality = double.NaN;31 #region Properties 34 32 public double BestQuality { 35 get { return bestQuality; } 33 get; 34 private set; 36 35 } 37 36 38 private int evaluations = 0;39 37 public int Evaluations { 40 get { return evaluations; } 38 get; 39 private set; 41 40 } 42 41 43 private int bestFoundOnEvaluation = 0;44 42 public int BestFoundOnEvaluation { 45 get { return bestFoundOnEvaluation; } 43 get; 44 private set; 46 45 } 47 46 48 47 public bool[] BestSolution { 49 get; private set; 48 get; 49 private set; 50 50 } 51 #endregion 51 52 52 53 public EvaluationTracker(IBinaryVectorProblem problem, int maxEvaluations) { … … 54 55 this.maxEvaluations = maxEvaluations; 55 56 BestSolution = new bool[0]; 57 BestQuality = double.NaN; 58 Evaluations = 0; 59 BestFoundOnEvaluation = 0; 56 60 } 57 61 58 62 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++; 61 65 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; 64 68 BestSolution = (bool[])individual.Clone(); 65 bestFoundOnEvaluation = evaluations;69 BestFoundOnEvaluation = Evaluations; 66 70 } 67 71 return fitness; 68 72 } 69 73 70 74 #region ForwardedInteraface 71 75 public int Length { 72 76 get { return problem.Length; } … … 77 81 public bool IsBetter(double quality, double bestQuality) { 78 82 return problem.IsBetter(quality, bestQuality); 79 } 83 } 84 #endregion 80 85 } 81 86 } -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/HIFFProblem.cs
r11666 r11669 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 using System.Text;26 using System.Threading.Tasks;27 24 using HeuristicLab.Common; 28 25 using HeuristicLab.Core; … … 48 45 49 46 public HIFFProblem() : base() { 50 Length = 32;47 Length = 64; 51 48 } 52 49 -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/IBinaryVectorProblem.cs
r11666 r11669 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using System.Threading.Tasks;27 28 22 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { 29 23 public interface IBinaryVectorProblem {
Note: See TracChangeset
for help on using the changeset viewer.