Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/24/12 15:04:37 (12 years ago)
Author:
jkarder
Message:

#1331:

  • applied some of the changes suggested by ascheibe in comment:32:ticket:1331
  • restructured path relinking and improvement operators and similarity calculators
  • fixed bug in TSPMultipleGuidesPathRelinker
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs

    r8304 r8319  
    3030  /// An operator that performs similarity calculation between two knapsack solutions.
    3131  /// </summary>
     32  /// <remarks>
     33  /// The operator calculates the similarity based on the number of elements the two solutions have in common.
     34  /// </remarks>
    3235  [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions.")]
    33   public sealed class KnapsackSimilarityCalculator : SimilarityCalculator {
     36  public sealed class KnapsackSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3437    private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3538    private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     
    4346      if (left == null || right == null)
    4447        throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes is null.");
     48      if (left.Length != right.Length)
     49        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
    4550      if (left == right) return 1.0;
    4651
     
    5156    }
    5257
    53     public override double CalculateIndividualSimilarity(IScope left, IScope right) {
    54       var sol1 = left.Variables[Target].Value as BinaryVector;
    55       var sol2 = right.Variables[Target].Value as BinaryVector;
     58    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     59      var sol1 = leftSolution.Variables[SolutionVariableName].Value as BinaryVector;
     60      var sol2 = rightSolution.Variables[SolutionVariableName].Value as BinaryVector;
    5661
    5762      return CalculateSimilarity(sol1, sol2);
Note: See TracChangeset for help on using the changeset viewer.