Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 00:48:18 (14 years ago)
Author:
swagner
Message:

Worked on refactoring of algorithm analysis and tracing (#999)

  • adapted GA and TSP
  • removed stuff related to visualizers
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  
    3232namespace HeuristicLab.Problems.TravelingSalesman {
    3333  /// <summary>
    34   /// An operator for visualizing the best tour of 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.
    3535  /// </summary>
    36   [Item("BestPathTSPTourVisualizer", "An operator for visualizing the best tour of 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.")]
    3737  [StorableClass]
    38   public sealed class BestPathTSPTourVisualizer : 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"]; }
    4141    }
    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"]; }
    4444    }
    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"]; }
    4747    }
    48     public ILookupParameter<PathTSPTour> PathTSPTourParameter {
    49       get { return (ILookupParameter<PathTSPTour>)Parameters["PathTSPTour"]; }
     48    public LookupParameter<PathTSPTour> BestSolutionParameter {
     49      get { return (LookupParameter<PathTSPTour>)Parameters["BestSolution"]; }
    5050    }
    51     ILookupParameter ISolutionsVisualizer.VisualizationParameter {
    52       get { return PathTSPTourParameter; }
     51    public ValueLookupParameter<ResultCollection> ResultsParameter {
     52      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    5353    }
    5454
    55     public BestPathTSPTourVisualizer()
     55    public BestTSPSolutionAnalyzer()
    5656      : base() {
    5757      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."));
    6162    }
    6263
     
    6566      ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
    6667      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     68      ResultCollection results = ResultsParameter.ActualValue;
    6769
    6870      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    6971
    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        }
    7584      }
     85
    7686      return base.Apply();
    7787    }
Note: See TracChangeset for help on using the changeset viewer.