Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/Knapsack/DiversityCalculator.cs @ 7740

Last change on this file since 7740 was 7740, checked in by jkarder, 12 years ago

#1331:

  • added custom crossover operator (NChildCrossover)
  • added parameters and adjusted types
  • replaced SolutionCombinationMethod with a placeholder
  • adjusted event handling
  • changed access levels
  • minor code improvements
File size: 544 bytes
Line 
1using HeuristicLab.Core;
2using HeuristicLab.Encodings.BinaryVectorEncoding;
3
4namespace HeuristicLab.Algorithms.ScatterSearch.Knapsack {
5  public sealed class DiversityCalculator {
6    public static int CalculateDiversity(IItem p, IItem r) {
7      BinaryVector pSol = p as BinaryVector;
8      BinaryVector rSol = r as BinaryVector;
9      int diversity = 0;
10      if (pSol != null && rSol != null)
11        for (int i = 0; i < pSol.Length; i++)
12          if (pSol[i] != rSol[i]) diversity++;
13      return diversity;
14    }
15  }
16}
Note: See TracBrowser for help on using the repository browser.