Changeset 3634 for trunk/sources/HeuristicLab.Problems.TravelingSalesman
- Timestamp:
- 05/05/10 14:28:22 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3
- Files:
-
- 2 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/BestTSPSolutionAnalyzer.cs
r3618 r3634 36 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 BestTSPSolutionAnalyzer : SingleSuccessorOperator, I PopulationAnalyzer {38 public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, ISolutionAnalyzer { 39 39 public LookupParameter<DoubleMatrix> CoordinatesParameter { 40 40 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 41 41 } 42 public SubScopesLookupParameter<Permutation> PermutationParameter {43 get { return ( SubScopesLookupParameter<Permutation>)Parameters["Permutation"]; }42 public LookupParameter<Permutation> PermutationParameter { 43 get { return (LookupParameter<Permutation>)Parameters["Permutation"]; } 44 44 } 45 public SubScopesLookupParameter<DoubleValue> QualityParameter {46 get { return ( SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }45 public LookupParameter<DoubleValue> QualityParameter { 46 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 47 47 } 48 48 public LookupParameter<PathTSPTour> BestSolutionParameter { … … 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 solutionshould be analyzed."));59 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutionswhich should be analyzed."));58 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The TSP solution given in path representation which should be analyzed.")); 59 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the TSP solution which should be analyzed.")); 60 60 Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution.")); 61 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the bestTSP solution should be stored."));61 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the TSP solution should be stored.")); 62 62 } 63 63 64 64 public override IOperation Apply() { 65 65 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 66 ItemArray<Permutation> permutations= PermutationParameter.ActualValue;67 ItemArray<DoubleValue> qualities= QualityParameter.ActualValue;66 Permutation permutation = PermutationParameter.ActualValue; 67 DoubleValue quality = QualityParameter.ActualValue; 68 68 ResultCollection results = ResultsParameter.ActualValue; 69 70 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;71 69 72 70 PathTSPTour tour = BestSolutionParameter.ActualValue; 73 71 if (tour == null) { 74 tour = new PathTSPTour(coordinates, permutation s[i], qualities[i]);72 tour = new PathTSPTour(coordinates, permutation, quality); 75 73 BestSolutionParameter.ActualValue = tour; 76 74 results.Add(new Result("Best TSP Solution", tour)); 77 75 } else { 78 if (tour.Quality.Value > qualit ies[i].Value) {76 if (tour.Quality.Value > quality.Value) { 79 77 tour.Coordinates = coordinates; 80 tour.Permutation = permutation s[i];81 tour.Quality = qualit ies[i];78 tour.Permutation = permutation; 79 tour.Quality = quality; 82 80 results["Best TSP Solution"].Value = tour; 83 81 } -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/MultiPopulationBestTSPSolutionAnalyzer.cs
r3626 r3634 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; … … 29 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using System.Collections.Generic; 31 33 32 34 namespace HeuristicLab.Problems.TravelingSalesman { … … 34 36 /// An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates. 35 37 /// </summary> 36 [Item(" BestTSPSolutionAnalyzer", "An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]38 [Item("MultiPopulationBestTSPSolutionAnalyzer", "An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")] 37 39 [StorableClass] 38 public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IPopulationAnalyzer {40 public sealed class MultiPopulationBestTSPSolutionAnalyzer : SingleSuccessorOperator, IMultiPopulationAnalyzer { 39 41 public LookupParameter<DoubleMatrix> CoordinatesParameter { 40 42 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 41 43 } 42 public SubScopes LookupParameter<Permutation> PermutationParameter {43 get { return (SubScopes LookupParameter<Permutation>)Parameters["Permutation"]; }44 public SubScopesSubScopesLookupParameter<Permutation> PermutationParameter { 45 get { return (SubScopesSubScopesLookupParameter<Permutation>)Parameters["Permutation"]; } 44 46 } 45 public SubScopes LookupParameter<DoubleValue> QualityParameter {46 get { return (SubScopes LookupParameter<DoubleValue>)Parameters["Quality"]; }47 public SubScopesSubScopesLookupParameter<DoubleValue> QualityParameter { 48 get { return (SubScopesSubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; } 47 49 } 48 50 public LookupParameter<PathTSPTour> BestSolutionParameter { … … 53 55 } 54 56 55 public BestTSPSolutionAnalyzer()57 public MultiPopulationBestTSPSolutionAnalyzer() 56 58 : base() { 57 59 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); 58 Parameters.Add(new SubScopes LookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed."));59 Parameters.Add(new SubScopes LookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be analyzed."));60 Parameters.Add(new SubScopesSubScopesLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed.")); 61 Parameters.Add(new SubScopesSubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be analyzed.")); 60 62 Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution.")); 61 63 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best TSP solution should be stored.")); … … 64 66 public override IOperation Apply() { 65 67 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 66 ItemArray< Permutation> permutations = PermutationParameter.ActualValue;67 ItemArray< DoubleValue> qualities = QualityParameter.ActualValue;68 ItemArray<ItemArray<Permutation>> permutations = PermutationParameter.ActualValue; 69 ItemArray<ItemArray<DoubleValue>> qualities = QualityParameter.ActualValue; 68 70 ResultCollection results = ResultsParameter.ActualValue; 69 71 70 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 72 DoubleValue bestQuality = new DoubleValue(double.MaxValue); 73 Permutation bestPermutation = null; 74 75 for (int i = 0; i < qualities.Length; i++) { 76 for (int j = 0; j < qualities[i].Length; j++) { 77 if (qualities[i][j].Value < bestQuality.Value) { 78 bestQuality = qualities[i][j]; 79 bestPermutation = permutations[i][j]; 80 } 81 } 82 } 71 83 72 84 PathTSPTour tour = BestSolutionParameter.ActualValue; 73 85 if (tour == null) { 74 tour = new PathTSPTour(coordinates, permutations[i], qualities[i]);86 tour = new PathTSPTour(coordinates, bestPermutation, bestQuality); 75 87 BestSolutionParameter.ActualValue = tour; 76 88 results.Add(new Result("Best TSP Solution", tour)); 77 89 } else { 78 if (tour.Quality.Value > qualities[i].Value) {90 if (tour.Quality.Value > bestQuality.Value) { 79 91 tour.Coordinates = coordinates; 80 tour.Permutation = permutations[i];81 tour.Quality = qualities[i];92 tour.Permutation = bestPermutation; 93 tour.Quality = bestQuality; 82 94 results["Best TSP Solution"].Value = tour; 83 95 } -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/PopulationBestTSPSolutionAnalyzer.cs
r3626 r3634 34 34 /// An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates. 35 35 /// </summary> 36 [Item(" BestTSPSolutionAnalyzer", "An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]36 [Item("PopulationBestTSPSolutionAnalyzer", "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 BestTSPSolutionAnalyzer : SingleSuccessorOperator, IPopulationAnalyzer {38 public sealed class PopulationBestTSPSolutionAnalyzer : SingleSuccessorOperator, IPopulationAnalyzer { 39 39 public LookupParameter<DoubleMatrix> CoordinatesParameter { 40 40 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } … … 53 53 } 54 54 55 public BestTSPSolutionAnalyzer()55 public PopulationBestTSPSolutionAnalyzer() 56 56 : base() { 57 57 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.")); -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/HeuristicLab.Problems.TravelingSalesman-3.3.csproj
r3616 r3634 84 84 </ItemGroup> 85 85 <ItemGroup> 86 <Compile Include="Analyzers\MultiPopulationBestTSPSolutionAnalyzer.cs" /> 87 <Compile Include="Analyzers\PopulationBestTSPSolutionAnalyzer.cs" /> 86 88 <Compile Include="Analyzers\BestTSPSolutionAnalyzer.cs" /> 87 89 <Compile Include="Evaluators\TSPEuclideanPathEvaluator.cs" />
Note: See TracChangeset
for help on using the changeset viewer.