- Timestamp:
- 08/04/11 08:27:35 (13 years ago)
- Location:
- branches/QAPAlgorithms
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAPAlgorithms
- Property svn:mergeinfo changed
/trunk/sources merged: 6612-6614
- Property svn:mergeinfo changed
-
branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPPermutationProximityCalculator.cs
r6416 r6627 44 44 45 45 public static double CalculatePhenotypeDistance(Permutation a, Permutation b, DoubleMatrix weights, DoubleMatrix distances) { 46 Dictionary<string, int> alleles = new Dictionary<string, int>(); 47 int distance = 0; 48 for (int x = 0; x < a.Length; x++) { 49 for (int y = 0; y < a.Length; y++) { 50 string alleleA = weights[x, y].ToString() + ">" + distances[a[x], a[y]].ToString(); 51 string alleleB = weights[x, y].ToString() + ">" + distances[b[x], b[y]].ToString(); 52 if (alleleA == alleleB) continue; 46 Dictionary<double, Dictionary<double, int>> alleles = new Dictionary<double, Dictionary<double, int>>(); 47 int distance = 0, len = a.Length; 48 for (int x = 0; x < len; x++) { 49 for (int y = 0; y < len; y++) { 50 // there's a limited universe of double values as they're all drawn from the same matrix 51 double dA = distances[a[x], a[y]], dB = distances[b[x], b[y]]; 52 if (dA == dB) continue; 53 54 Dictionary<double, int> dAlleles; 55 if (!alleles.ContainsKey(weights[x, y])) { 56 dAlleles = new Dictionary<double, int>(); 57 alleles.Add(weights[x, y], dAlleles); 58 } else dAlleles = alleles[weights[x, y]]; 53 59 54 60 int countA = 1, countB = -1; 55 if (alleles.ContainsKey(alleleA)) countA += alleles[alleleA]; 56 if (alleles.ContainsKey(alleleB)) countB += alleles[alleleB]; 61 62 if (dAlleles.ContainsKey(dA)) countA += dAlleles[dA]; 63 if (dAlleles.ContainsKey(dB)) countB += dAlleles[dB]; 57 64 58 65 if (countA <= 0) distance--; // we've found in A an allele that was present in B 59 66 else distance++; // we've found in A a new allele 60 alleles[alleleA] = countA;67 dAlleles[dA] = countA; 61 68 62 69 if (countB >= 0) distance--; // we've found in B an allele that was present in A 63 70 else distance++; // we've found in B a new allele 64 alleles[alleleB] = countB;71 dAlleles[dB] = countB; 65 72 } 66 73 } 67 return distance / (double)(2 * a.Length * a.Length);74 return distance / (double)(2 * len * len); 68 75 } 69 76 }
Note: See TracChangeset
for help on using the changeset viewer.