- Timestamp:
- 07/12/17 21:02:01 (7 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14412,14475-14476,14659-14660,14663,14912,15050,15067,15069,15079,15162,15166,15172-15173
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.QuadraticAssignment
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.QuadraticAssignment merged: 15069,15166
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPSimilarityCalculator.cs
r14186 r15217 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Optimization.Operators; 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 28 30 namespace HeuristicLab.Problems.QuadraticAssignment { … … 34 36 /// </remarks> 35 37 [Item("QAPSimilarityCalculator", "An operator that performs similarity calculation between two quadratic assignment solutions. The operator calculates the similarity based on the number of edges the two solutions have in common.")] 38 [StorableClass] 36 39 public sealed class QAPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 37 40 protected override bool IsCommutative { get { return true; } } 38 41 42 [Storable] 43 public DoubleMatrix Weights { get; set; } 44 [Storable] 45 public DoubleMatrix Distances { get; set; } 46 39 47 private QAPSimilarityCalculator(bool deserializing) : base(deserializing) { } 40 private QAPSimilarityCalculator(QAPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 48 private QAPSimilarityCalculator(QAPSimilarityCalculator original, Cloner cloner) 49 : base(original, cloner) { 50 Weights = cloner.Clone(original.Weights); 51 Distances = cloner.Clone(original.Distances); 52 } 41 53 public QAPSimilarityCalculator() : base() { } 42 54 … … 45 57 } 46 58 47 public static double CalculateSimilarity(Permutation left, Permutation right ) {59 public static double CalculateSimilarity(Permutation left, Permutation right, DoubleMatrix weights, DoubleMatrix distances) { 48 60 if (left == null || right == null) 49 61 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 50 62 if (left.Length != right.Length) 51 63 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths."); 52 if (object.ReferenceEquals(left, right)) return 1.0; 64 if (left.Length == 0) 65 throw new ArgumentException("Cannot calculate similarity because solutions are of length 0."); 66 if (ReferenceEquals(left, right)) return 1.0; 53 67 54 return QAPPermutationProximityCalculator.Calculate GenotypeSimilarity(left, right);68 return QAPPermutationProximityCalculator.CalculatePhenotypeSimilarity(left, right, weights, distances); 55 69 } 56 70 … … 59 73 var sol2 = rightSolution.Variables[SolutionVariableName].Value as Permutation; 60 74 61 return CalculateSimilarity(sol1, sol2 );75 return CalculateSimilarity(sol1, sol2, Weights, Distances); 62 76 } 63 77 }
Note: See TracChangeset
for help on using the changeset viewer.