Changeset 8319 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs
- Timestamp:
- 07/24/12 15:04:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs
r8304 r8319 30 30 /// An operator that performs similarity calculation between two knapsack solutions. 31 31 /// </summary> 32 /// <remarks> 33 /// The operator calculates the similarity based on the number of elements the two solutions have in common. 34 /// </remarks> 32 35 [Item("KnapsackSimilarityCalculator", "An operator that performs similarity calculation between two knapsack solutions.")] 33 public sealed class KnapsackSimilarityCalculator : Si milarityCalculator {36 public sealed class KnapsackSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 34 37 private KnapsackSimilarityCalculator(bool deserializing) : base(deserializing) { } 35 38 private KnapsackSimilarityCalculator(KnapsackSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 43 46 if (left == null || right == null) 44 47 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."); 45 50 if (left == right) return 1.0; 46 51 … … 51 56 } 52 57 53 public override double Calculate IndividualSimilarity(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; 56 61 57 62 return CalculateSimilarity(sol1, sol2);
Note: See TracChangeset
for help on using the changeset viewer.