- Timestamp:
- 05/06/13 12:30:18 (12 years ago)
- Location:
- branches/HivePerformance/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HivePerformance/sources
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 9376,9379,9388,9390,9396,9402-9410,9413,9417,9426-9429,9432-9433,9435-9439,9441-9443
- Property svn:mergeinfo changed
-
branches/HivePerformance/sources/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs
r9030 r9444 73 73 74 74 private static double CalculateRelativeDirected(Permutation left, Permutation right) { 75 int[] edges = new int[right.Length]; 76 for (int i = 0; i < right.Length; i++) 77 edges[right[i]] = right[(i + 1) % right.Length]; 75 int[] edgesR = CalculateEdgesVector(right); 76 int[] edgesL = CalculateEdgesVector(left); 78 77 79 78 double similarity = 0.0; 80 for (int i = 0; i < left.Length; i++) 81 if (left[(i + 1) % left.Length] == edges[left[i]]) similarity++; 79 for (int i = 0; i < left.Length; i++) { 80 if (edgesL[i] == edgesR[i]) similarity++; 81 } 82 82 83 83 return similarity / left.Length; … … 85 85 86 86 private static double CalculateRelativeUndirected(Permutation left, Permutation right) { 87 int[,] edges = new int[right.Length, 2]; 88 for (int i = 0; i < right.Length; i++) { 89 edges[right[i], 0] = right[(i + 1) % right.Length]; 90 edges[right[i], 1] = right[(i - 1 + right.Length) % right.Length]; 91 } 87 int[] edgesR = CalculateEdgesVector(right); 88 int[] edgesL = CalculateEdgesVector(left); 92 89 93 90 double similarity = 0.0; 94 91 for (int i = 0; i < left.Length; i++) { 95 int targetCity = left[(i + 1) % left.Length]; 96 if (targetCity == edges[left[i], 0] || targetCity == edges[left[i], 1]) 92 if ((edgesL[i] == edgesR[i]) || (edgesL[edgesR[i]] == i)) 97 93 similarity++; 98 94 } 99 95 100 96 return similarity / left.Length; 97 } 98 99 private static int[] CalculateEdgesVector(Permutation permutation) { 100 // transform path representation into adjacency representation 101 int[] edgesVector = new int[permutation.Length]; 102 for (int i = 0; i < permutation.Length - 1; i++) 103 edgesVector[permutation[i]] = permutation[i + 1]; 104 edgesVector[permutation[permutation.Length - 1]] = permutation[0]; 105 return edgesVector; 101 106 } 102 107
Note: See TracChangeset
for help on using the changeset viewer.