Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/04/11 08:27:35 (13 years ago)
Author:
abeham
Message:

#1541

  • updated from trunk
Location:
branches/QAPAlgorithms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/QAPAlgorithms

  • branches/QAPAlgorithms/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPPermutationProximityCalculator.cs

    r6416 r6627  
    4444
    4545    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]];
    5359
    5460          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];
    5764
    5865          if (countA <= 0) distance--; // we've found in A an allele that was present in B
    5966          else distance++; // we've found in A a new allele
    60           alleles[alleleA] = countA;
     67          dAlleles[dA] = countA;
    6168
    6269          if (countB >= 0) distance--; // we've found in B an allele that was present in A
    6370          else distance++; // we've found in B a new allele
    64           alleles[alleleB] = countB;
     71          dAlleles[dB] = countB;
    6572        }
    6673      }
    67       return distance / (double)(2 * a.Length * a.Length);
     74      return distance / (double)(2 * len * len);
    6875    }
    6976  }
Note: See TracChangeset for help on using the changeset viewer.