Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 14:28:22 (14 years ago)
Author:
swagner
Message:

Worked on best solution analysis for the TSP (#999)

File:
1 edited

Legend:

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

    r3618 r3634  
    3636  [Item("BestTSPSolutionAnalyzer", "An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
    3737  [StorableClass]
    38   public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IPopulationAnalyzer {
     38  public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, ISolutionAnalyzer {
    3939    public LookupParameter<DoubleMatrix> CoordinatesParameter {
    4040      get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    4141    }
    42     public SubScopesLookupParameter<Permutation> PermutationParameter {
    43       get { return (SubScopesLookupParameter<Permutation>)Parameters["Permutation"]; }
     42    public LookupParameter<Permutation> PermutationParameter {
     43      get { return (LookupParameter<Permutation>)Parameters["Permutation"]; }
    4444    }
    45     public SubScopesLookupParameter<DoubleValue> QualityParameter {
    46       get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }
     45    public LookupParameter<DoubleValue> QualityParameter {
     46      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    4747    }
    4848    public LookupParameter<PathTSPTour> BestSolutionParameter {
     
    5656      : base() {
    5757      Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
    58       Parameters.Add(new SubScopesLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed."));
    59       Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be analyzed."));
     58      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be analyzed."));
     59      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the TSP solution which should be analyzed."));
    6060      Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution."));
    61       Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best TSP solution should be stored."));
     61      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the TSP solution should be stored."));
    6262    }
    6363
    6464    public override IOperation Apply() {
    6565      DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
    66       ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
    67       ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     66      Permutation permutation = PermutationParameter.ActualValue;
     67      DoubleValue quality = QualityParameter.ActualValue;
    6868      ResultCollection results = ResultsParameter.ActualValue;
    69 
    70       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    7169
    7270      PathTSPTour tour = BestSolutionParameter.ActualValue;
    7371      if (tour == null) {
    74         tour = new PathTSPTour(coordinates, permutations[i], qualities[i]);
     72        tour = new PathTSPTour(coordinates, permutation, quality);
    7573        BestSolutionParameter.ActualValue = tour;
    7674        results.Add(new Result("Best TSP Solution", tour));
    7775      } else {
    78         if (tour.Quality.Value > qualities[i].Value) {
     76        if (tour.Quality.Value > quality.Value) {
    7977          tour.Coordinates = coordinates;
    80           tour.Permutation = permutations[i];
    81           tour.Quality = qualities[i];
     78          tour.Permutation = permutation;
     79          tour.Quality = quality;
    8280          results["Best TSP Solution"].Value = tour;
    8381        }
Note: See TracChangeset for help on using the changeset viewer.