Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/15 23:38:51 (9 years ago)
Author:
abeham
Message:

#2221:

  • Completely refactored PTSP branch
    • Added two sets of problem instances based on TSPLIB: homogeneous and heterogeneous
    • Implemented missing EvaluateByCoordinates for 1-shift moves
    • Made it clear that move evaluators are for estimated PTSP only
    • Changed parameter realization from a rather strange list of list of ints to a list of bool arrays
    • Reusing code of the 2-opt and 1-shift move evaluators in 2.5 move evaluator
    • Introducing distance calculators to properly handle the case when no distance matrix is given (previous code only worked with distance matrix and without only with euclidean distance in some settings)
    • Fixed several smaller code issues: protected, static, method parameters, copy & paste, interfaces, naming, parameters, serialization hooks, license headers, doc comments, data types
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Analyzers/BestPTSPSolutionAnalyzer.cs

    r12799 r13412  
    3232namespace HeuristicLab.Problems.PTSP {
    3333  /// <summary>
    34   /// An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.
     34  /// An operator for analyzing the best solution of probabilistic traveling salesman problems given in path representation.
    3535  /// </summary>
    3636  [Item("BestPTSPSolutionAnalyzer", "An operator for analyzing the best solution of Probabilistic Traveling Salesman Problems given in path representation using city coordinates.")]
     
    4141    }
    4242
    43     public LookupParameter<BoolValue> MaximizationParameter {
    44       get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     43    public ILookupParameter<BoolValue> MaximizationParameter {
     44      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    4545    }
    46     public LookupParameter<DoubleMatrix> CoordinatesParameter {
    47       get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
     46    public ILookupParameter<DoubleMatrix> CoordinatesParameter {
     47      get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    4848    }
    49     public ScopeTreeLookupParameter<Permutation> PermutationParameter {
    50       get { return (ScopeTreeLookupParameter<Permutation>)Parameters["Permutation"]; }
     49    public IScopeTreeLookupParameter<Permutation> PermutationParameter {
     50      get { return (IScopeTreeLookupParameter<Permutation>)Parameters["Permutation"]; }
    5151    }
    52     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    53       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     52    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     53      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    5454    }
    55     public LookupParameter<DoubleArray> ProbabilityMatrixParameter {
    56       get { return (LookupParameter<DoubleArray>)Parameters["ProbabilityMatrix"]; }
     55    public ILookupParameter<DoubleArray> ProbabilitiesParameter {
     56      get { return (ILookupParameter<DoubleArray>)Parameters["Probabilities"]; }
    5757    }
    58     public LookupParameter<PathPTSPTour> BestSolutionParameter {
    59       get { return (LookupParameter<PathPTSPTour>)Parameters["BestSolution"]; }
     58    public ILookupParameter<PathPTSPTour> BestSolutionParameter {
     59      get { return (ILookupParameter<PathPTSPTour>)Parameters["BestSolution"]; }
    6060    }
    61     public ValueLookupParameter<ResultCollection> ResultsParameter {
    62       get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     61    public IValueLookupParameter<ResultCollection> ResultsParameter {
     62      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    6363    }
    64     public LookupParameter<DoubleValue> BestKnownQualityParameter {
    65       get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     64    public ILookupParameter<DoubleValue> BestKnownQualityParameter {
     65      get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    6666    }
    67     public LookupParameter<Permutation> BestKnownSolutionParameter {
    68       get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }
     67    public ILookupParameter<Permutation> BestKnownSolutionParameter {
     68      get { return (ILookupParameter<Permutation>)Parameters["BestKnownSolution"]; }
    6969    }
    7070
     
    8181      Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The PTSP solutions given in path representation from which the best solution should be analyzed."));
    8282      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the PTSP solutions which should be analyzed."));
    83       Parameters.Add(new LookupParameter<DoubleArray>("ProbabilityMatrix", "The matrix which contains the probabilities of each of the cities."));
     83      Parameters.Add(new LookupParameter<DoubleArray>("Probabilities", "This list describes for each city the probability of appearing in a realized instance."));
    8484      Parameters.Add(new LookupParameter<PathPTSPTour>("BestSolution", "The best PTSP solution."));
    8585      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best PTSP solution should be stored."));
    8686      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this PTSP instance."));
    8787      Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this PTSP instance."));
    88 
    89       MaximizationParameter.Hidden = true;
    90       CoordinatesParameter.Hidden = true;
    91       PermutationParameter.Hidden = true;
    92       QualityParameter.Hidden = true;
    93       ProbabilityMatrixParameter.Hidden = true;
    94       BestSolutionParameter.Hidden = true;
    95       ResultsParameter.Hidden = true;
    96       BestKnownQualityParameter.Hidden = true;
    97       BestKnownSolutionParameter.Hidden = true;
    9888    }
    9989
    10090    public override IOperation Apply() {
    101       DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
    102       ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
    103       ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    104       DoubleArray probabilities = ProbabilityMatrixParameter.ActualValue;
    105       ResultCollection results = ResultsParameter.ActualValue;
    106       bool max = MaximizationParameter.ActualValue.Value;
    107       DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
     91      var coordinates = CoordinatesParameter.ActualValue;
     92      var permutations = PermutationParameter.ActualValue;
     93      var qualities = QualityParameter.ActualValue;
     94      var probabilities = ProbabilitiesParameter.ActualValue;
     95      var results = ResultsParameter.ActualValue;
     96      var max = MaximizationParameter.ActualValue.Value;
     97      var bestKnownQuality = BestKnownQualityParameter.ActualValue;
    10898
    109       int i = -1;
    110       if (!max)
    111         i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    112       else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     99      var i = !max ? qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index
     100                   : qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
    113101
    114102      if (bestKnownQuality == null ||
     
    119107      }
    120108
    121       PathPTSPTour tour = BestSolutionParameter.ActualValue;
     109      var tour = BestSolutionParameter.ActualValue;
    122110      if (tour == null) {
    123         tour = new PathPTSPTour(coordinates,probabilities, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
     111        tour = new PathPTSPTour(coordinates, probabilities, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
    124112        BestSolutionParameter.ActualValue = tour;
    125113        results.Add(new Result("Best PTSP Solution", tour));
Note: See TracChangeset for help on using the changeset viewer.