Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4866


Ignore:
Timestamp:
11/20/10 00:35:05 (14 years ago)
Author:
swagner
Message:

Modified TSPAlleleFrequencyAnalyzer to use the distance matrix if available (#1234)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/TSPAlleleFrequencyAnalyzer.cs

    r4849 r4866  
    3939      get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    4040    }
     41    public LookupParameter<DistanceMatrix> DistanceMatrixParameter {
     42      get { return (LookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; }
     43    }
    4144
    4245    [StorableConstructor]
     
    4649      : base() {
    4750      Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-coordinates of the cities."));
     51      Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
    4852    }
    4953
     
    5559      Allele[] alleles = new Allele[solution.Length];
    5660      DoubleMatrix coords = CoordinatesParameter.ActualValue;
     61      DistanceMatrix dm = DistanceMatrixParameter.ActualValue;
     62      int source, target, h;
     63      double impact;
    5764
    58       for (int i = 0; i < solution.Length - 1; i++)
    59         alleles[i] = CreateAllele(solution[i], solution[i + 1], coords);
    60       alleles[alleles.Length - 1] = CreateAllele(solution[solution.Length - 1], solution[0], coords);
     65      for (int i = 0; i < solution.Length - 1; i++) {
     66        source = solution[i];
     67        target = solution[i + 1];
     68        if (source > target) { h = source; source = target; target = h; }
     69        impact = dm != null ? dm[source, target] : CalculateLength(coords[source, 0], coords[source, 1], coords[target, 0], coords[target, 1]);
     70        alleles[i] = new Allele(source.ToString() + "-" + target.ToString(), impact);
     71      }
     72      source = solution[solution.Length - 1];
     73      target = solution[0];
     74      if (source > target) { h = source; source = target; target = h; }
     75      impact = dm != null ? dm[source, target] : CalculateLength(coords[source, 0], coords[source, 1], coords[target, 0], coords[target, 1]);
     76      alleles[alleles.Length - 1] = new Allele(source.ToString() + "-" + target.ToString(), impact);
    6177
    6278      return alleles;
    63     }
    64 
    65     private Allele CreateAllele(int source, int target, DoubleMatrix coords) {
    66       if (source > target) {
    67         int h = source;
    68         source = target;
    69         target = h;
    70       }
    71 
    72       return new Allele(source.ToString() + "-" + target.ToString(),
    73                         CalculateLength(coords[source, 0], coords[source, 1], coords[target, 0], coords[target, 1]));
    7479    }
    7580
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r4825 r4866  
    351351        TSPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
    352352        TSPAlleleFrequencyAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     353        TSPAlleleFrequencyAnalyzer.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
    353354        TSPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    354355        TSPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
Note: See TracChangeset for help on using the changeset viewer.