Changeset 11637
- Timestamp:
- 12/03/14 16:16:05 (10 years ago)
- Location:
- branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r11636 r11637 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 using System.Text;26 using System.Threading.Tasks;27 24 using HeuristicLab.Common; 28 25 using HeuristicLab.Core; … … 68 65 public static double ImproveToLocalOptimum(BinaryVectorProblem problem, bool[] solution, double fitness, IRandom rand) { 69 66 var tried = new HashSet<int>(); 70 71 double newFitness=fitness;72 67 do { 73 68 var options = Enumerable.Range(0, solution.Length).Shuffle(rand); 74 69 foreach (var option in options) { 75 70 solution[option] = !solution[option]; 76 newFitness = problem.Evaluate(solution);71 double newFitness = problem.Evaluate(solution); 77 72 if ((problem.Maximization && fitness < newFitness) || (!problem.Maximization && fitness > newFitness)) { 78 73 fitness = newFitness; … … 85 80 } while (tried.Count != solution.Length); 86 81 return fitness; 87 } 82 } 88 83 } 89 84 } -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/OneMaxProblem.cs
r11636 r11637 21 21 22 22 using System; 23 using System.Linq;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 43 42 public override double Evaluate(bool[] individual) { 44 43 if (individual.Length != Length) throw new ArgumentException("The individual has not the correct length."); 45 return individual.Count(x => x); 44 //return individual.Count(x => x); 45 double quality = 0; 46 for (int i = 0; i < individual.Length; i++) 47 if (individual[i]) quality++; 48 return quality; 46 49 } 47 50 }
Note: See TracChangeset
for help on using the changeset viewer.