Changeset 3787 for trunk/sources/HeuristicLab.Problems.TravelingSalesman
- Timestamp:
- 05/11/10 21:16:12 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/BestTSPSolutionAnalyzer.cs
r3692 r3787 37 37 [StorableClass] 38 38 public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 39 public LookupParameter<BoolValue> MaximizationParameter { 40 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 41 } 39 42 public LookupParameter<DoubleMatrix> CoordinatesParameter { 40 43 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } … … 52 55 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 53 56 } 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 } 54 63 55 64 public BestTSPSolutionAnalyzer() 56 65 : base() { 66 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem.")); 57 67 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 58 68 Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed.")); … … 60 70 Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution.")); 61 71 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.")); 62 74 } 63 75 … … 67 79 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 68 80 ResultCollection results = ResultsParameter.ActualValue; 81 bool max = MaximizationParameter.ActualValue.Value; 82 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 69 83 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 } 71 95 72 96 PathTSPTour tour = BestSolutionParameter.ActualValue; … … 76 100 results.Add(new Result("Best TSP Solution", tour)); 77 101 } 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) { 79 104 tour.Coordinates = coordinates; 80 105 tour.Permutation = (Permutation)permutations[i].Clone(); 81 106 tour.Quality.Value = qualities[i].Value; 82 results["Best TSP Solution"].Value = tour;83 107 } 84 108 }
Note: See TracChangeset
for help on using the changeset viewer.