Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/11/10 21:16:12 (15 years ago)
Author:
abeham
Message:

#893

  • Removed best known quality tracking from BestAverageWorstQualityAnalyzer
  • Added best known quality / solution tracking to problem specific analyzers
File:
1 edited

Legend:

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

    r3692 r3787  
    3737  [StorableClass]
    3838  public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     39    public LookupParameter<BoolValue> MaximizationParameter {
     40      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     41    }
    3942    public LookupParameter<DoubleMatrix> CoordinatesParameter {
    4043      get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
     
    5255      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    5356    }
     57    public LookupParameter<DoubleValue> BestKnownQualityParameter {
     58      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     59    }
     60    public LookupParameter<Permutation> BestKnownSolutionParameter {
     61      get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }
     62    }
    5463
    5564    public BestTSPSolutionAnalyzer()
    5665      : base() {
     66      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    5767      Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
    5868      Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed."));
     
    6070      Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution."));
    6171      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best TSP solution should be stored."));
     72      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
     73      Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance."));
    6274    }
    6375
     
    6779      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    6880      ResultCollection results = ResultsParameter.ActualValue;
     81      bool max = MaximizationParameter.ActualValue.Value;
     82      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    6983
    70       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     84      int i = -1;
     85      if (!max)
     86        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     87      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     88     
     89      if (bestKnownQuality == null ||
     90          max && qualities[i].Value > bestKnownQuality.Value ||
     91          !max && qualities[i].Value < bestKnownQuality.Value) {
     92        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     93        BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone();
     94      }
    7195
    7296      PathTSPTour tour = BestSolutionParameter.ActualValue;
     
    76100        results.Add(new Result("Best TSP Solution", tour));
    77101      } else {
    78         if (tour.Quality.Value > qualities[i].Value) {
     102        if (max && tour.Quality.Value < qualities[i].Value ||
     103          !max && tour.Quality.Value > qualities[i].Value) {
    79104          tour.Coordinates = coordinates;
    80105          tour.Permutation = (Permutation)permutations[i].Clone();
    81106          tour.Quality.Value = qualities[i].Value;
    82           results["Best TSP Solution"].Value = tour;
    83107        }
    84108      }
Note: See TracChangeset for help on using the changeset viewer.