- Timestamp:
- 05/05/10 00:48:18 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers
- Files:
-
- 1 deleted
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/BestTSPSolutionAnalyzer.cs
r3612 r3616 32 32 namespace HeuristicLab.Problems.TravelingSalesman { 33 33 /// <summary> 34 /// An operator for visualizing the best tourof Traveling Salesman Problems given in path representation using city coordinates.34 /// An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates. 35 35 /// </summary> 36 [Item("Best PathTSPTourVisualizer", "An operator for visualizing the best tourof Traveling Salesman Problems given in path representation using city coordinates.")]36 [Item("BestTSPSolutionAnalyzer", "An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")] 37 37 [StorableClass] 38 public sealed class Best PathTSPTourVisualizer : SingleSuccessorOperator, IPathCoordinatesTSPSolutionsVisualizer {39 public ILookupParameter<DoubleMatrix> CoordinatesParameter {40 get { return ( ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }38 public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 39 public LookupParameter<DoubleMatrix> CoordinatesParameter { 40 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 41 41 } 42 public ILookupParameter<ItemArray<Permutation>> PermutationParameter {43 get { return ( ILookupParameter<ItemArray<Permutation>>)Parameters["Permutation"]; }42 public SubScopesLookupParameter<Permutation> PermutationParameter { 43 get { return (SubScopesLookupParameter<Permutation>)Parameters["Permutation"]; } 44 44 } 45 public ILookupParameter<ItemArray<DoubleValue>> QualityParameter {46 get { return ( ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; }45 public SubScopesLookupParameter<DoubleValue> QualityParameter { 46 get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } 47 47 } 48 public ILookupParameter<PathTSPTour> PathTSPTourParameter {49 get { return ( ILookupParameter<PathTSPTour>)Parameters["PathTSPTour"]; }48 public LookupParameter<PathTSPTour> BestSolutionParameter { 49 get { return (LookupParameter<PathTSPTour>)Parameters["BestSolution"]; } 50 50 } 51 ILookupParameter ISolutionsVisualizer.VisualizationParameter {52 get { return PathTSPTourParameter; }51 public ValueLookupParameter<ResultCollection> ResultsParameter { 52 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 53 53 } 54 54 55 public Best PathTSPTourVisualizer()55 public BestTSPSolutionAnalyzer() 56 56 : base() { 57 57 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 visualized.")); 59 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be visualized.")); 60 Parameters.Add(new LookupParameter<PathTSPTour>("PathTSPTour", "The visual representation of the best TSP solution.")); 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.")); 60 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 62 } 62 63 … … 65 66 ItemArray<Permutation> permutations = PermutationParameter.ActualValue; 66 67 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 68 ResultCollection results = ResultsParameter.ActualValue; 67 69 68 70 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 69 71 70 PathTSPTour tour = PathTSPTourParameter.ActualValue; 71 if (tour == null) PathTSPTourParameter.ActualValue = new PathTSPTour(coordinates, permutations[i]); 72 else { 73 tour.Coordinates = coordinates; 74 tour.Permutation = permutations[i]; 72 PathTSPTour tour = BestSolutionParameter.ActualValue; 73 if (tour == null) { 74 tour = new PathTSPTour(coordinates, permutations[i], qualities[i]); 75 BestSolutionParameter.ActualValue = tour; 76 results.Add(new Result("Best TSP Solution", tour)); 77 } else { 78 if (tour.Quality.Value > qualities[i].Value) { 79 tour.Coordinates = coordinates; 80 tour.Permutation = permutations[i]; 81 tour.Quality = qualities[i]; 82 results["Best TSP Solution"].Value = tour; 83 } 75 84 } 85 76 86 return base.Apply(); 77 87 }
Note: See TracChangeset
for help on using the changeset viewer.