Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11637


Ignore:
Timestamp:
12/03/14 16:16:05 (9 years ago)
Author:
mkommend
Message:

#2282: Implemented fitness for OneMaxProblem without lambdas.

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  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    2724using HeuristicLab.Common;
    2825using HeuristicLab.Core;
     
    6865    public static double ImproveToLocalOptimum(BinaryVectorProblem problem, bool[] solution, double fitness, IRandom rand) {
    6966      var tried = new HashSet<int>();
    70      
    71       double newFitness=fitness;
    7267      do {
    7368        var options = Enumerable.Range(0, solution.Length).Shuffle(rand);
    7469        foreach (var option in options) {
    7570          solution[option] = !solution[option];
    76           newFitness = problem.Evaluate(solution);
     71          double newFitness = problem.Evaluate(solution);
    7772          if ((problem.Maximization && fitness < newFitness) || (!problem.Maximization && fitness > newFitness)) {
    7873            fitness = newFitness;
     
    8580      } while (tried.Count != solution.Length);
    8681      return fitness;
    87     }     
     82    }
    8883  }
    8984}
  • branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Problems/OneMaxProblem.cs

    r11636 r11637  
    2121
    2222using System;
    23 using System.Linq;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    4342    public override double Evaluate(bool[] individual) {
    4443      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;
    4649    }
    4750  }
Note: See TracChangeset for help on using the changeset viewer.