Changeset 13412 for branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Analyzers
- Timestamp:
- 11/28/15 23:38:51 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Analyzers/BestPTSPSolutionAnalyzer.cs
r12799 r13412 32 32 namespace HeuristicLab.Problems.PTSP { 33 33 /// <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. 35 35 /// </summary> 36 36 [Item("BestPTSPSolutionAnalyzer", "An operator for analyzing the best solution of Probabilistic Traveling Salesman Problems given in path representation using city coordinates.")] … … 41 41 } 42 42 43 public LookupParameter<BoolValue> MaximizationParameter {44 get { return ( LookupParameter<BoolValue>)Parameters["Maximization"]; }43 public ILookupParameter<BoolValue> MaximizationParameter { 44 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 45 45 } 46 public LookupParameter<DoubleMatrix> CoordinatesParameter {47 get { return ( LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }46 public ILookupParameter<DoubleMatrix> CoordinatesParameter { 47 get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 48 48 } 49 public ScopeTreeLookupParameter<Permutation> PermutationParameter {50 get { return ( ScopeTreeLookupParameter<Permutation>)Parameters["Permutation"]; }49 public IScopeTreeLookupParameter<Permutation> PermutationParameter { 50 get { return (IScopeTreeLookupParameter<Permutation>)Parameters["Permutation"]; } 51 51 } 52 public ScopeTreeLookupParameter<DoubleValue> QualityParameter {53 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }52 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 53 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 54 54 } 55 public LookupParameter<DoubleArray> ProbabilityMatrixParameter {56 get { return ( LookupParameter<DoubleArray>)Parameters["ProbabilityMatrix"]; }55 public ILookupParameter<DoubleArray> ProbabilitiesParameter { 56 get { return (ILookupParameter<DoubleArray>)Parameters["Probabilities"]; } 57 57 } 58 public LookupParameter<PathPTSPTour> BestSolutionParameter {59 get { return ( LookupParameter<PathPTSPTour>)Parameters["BestSolution"]; }58 public ILookupParameter<PathPTSPTour> BestSolutionParameter { 59 get { return (ILookupParameter<PathPTSPTour>)Parameters["BestSolution"]; } 60 60 } 61 public ValueLookupParameter<ResultCollection> ResultsParameter {62 get { return ( ValueLookupParameter<ResultCollection>)Parameters["Results"]; }61 public IValueLookupParameter<ResultCollection> ResultsParameter { 62 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 63 63 } 64 public LookupParameter<DoubleValue> BestKnownQualityParameter {65 get { return ( LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }64 public ILookupParameter<DoubleValue> BestKnownQualityParameter { 65 get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 66 66 } 67 public LookupParameter<Permutation> BestKnownSolutionParameter {68 get { return ( LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }67 public ILookupParameter<Permutation> BestKnownSolutionParameter { 68 get { return (ILookupParameter<Permutation>)Parameters["BestKnownSolution"]; } 69 69 } 70 70 … … 81 81 Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The PTSP solutions given in path representation from which the best solution should be analyzed.")); 82 82 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the PTSP solutions which should be analyzed.")); 83 Parameters.Add(new LookupParameter<DoubleArray>("Probabilit yMatrix", "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.")); 84 84 Parameters.Add(new LookupParameter<PathPTSPTour>("BestSolution", "The best PTSP solution.")); 85 85 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best PTSP solution should be stored.")); 86 86 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this PTSP instance.")); 87 87 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;98 88 } 99 89 100 90 public override IOperation Apply() { 101 DoubleMatrixcoordinates = CoordinatesParameter.ActualValue;102 ItemArray<Permutation>permutations = PermutationParameter.ActualValue;103 ItemArray<DoubleValue>qualities = QualityParameter.ActualValue;104 DoubleArray probabilities = ProbabilityMatrixParameter.ActualValue;105 ResultCollectionresults = ResultsParameter.ActualValue;106 boolmax = MaximizationParameter.ActualValue.Value;107 DoubleValuebestKnownQuality = 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; 108 98 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; 113 101 114 102 if (bestKnownQuality == null || … … 119 107 } 120 108 121 PathPTSPTour tour = BestSolutionParameter.ActualValue;109 var tour = BestSolutionParameter.ActualValue; 122 110 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)); 124 112 BestSolutionParameter.ActualValue = tour; 125 113 results.Add(new Result("Best PTSP Solution", tour));
Note: See TracChangeset
for help on using the changeset viewer.