1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.TSP {
|
---|
32 | /// <summary>
|
---|
33 | /// An operator for visualizing the best tour of Traveling Salesman Problems given in path representation using city coordinates.
|
---|
34 | /// </summary>
|
---|
35 | [Item("BestPathTSPTourVisualizer", "An operator for visualizing the best tour of Traveling Salesman Problems given in path representation using city coordinates.")]
|
---|
36 | [StorableClass]
|
---|
37 | public sealed class BestPathTSPTourVisualizer : SingleSuccessorOperator, IPathCoordinatesTSPSolutionsVisualizer {
|
---|
38 | public ILookupParameter<DoubleMatrix> CoordinatesParameter {
|
---|
39 | get { return (ILookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
|
---|
40 | }
|
---|
41 | public ILookupParameter<ItemArray<Permutation>> PermutationParameter {
|
---|
42 | get { return (ILookupParameter<ItemArray<Permutation>>)Parameters["Permutation"]; }
|
---|
43 | }
|
---|
44 | public ILookupParameter<ItemArray<DoubleValue>> QualityParameter {
|
---|
45 | get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; }
|
---|
46 | }
|
---|
47 | public ILookupParameter<PathTSPTour> PathTSPTourParameter {
|
---|
48 | get { return (ILookupParameter<PathTSPTour>)Parameters["PathTSPTour"]; }
|
---|
49 | }
|
---|
50 | ILookupParameter ISolutionsVisualizer.VisualizationParameter {
|
---|
51 | get { return PathTSPTourParameter; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public BestPathTSPTourVisualizer()
|
---|
55 | : base() {
|
---|
56 | Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
|
---|
57 | Parameters.Add(new SubScopesLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be visualized."));
|
---|
58 | Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be visualized."));
|
---|
59 | Parameters.Add(new LookupParameter<PathTSPTour>("PathTSPTour", "The visual representation of the best TSP solution."));
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override IOperation Apply() {
|
---|
63 | DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
|
---|
64 | ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
|
---|
65 | ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
|
---|
66 |
|
---|
67 | int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
|
---|
68 |
|
---|
69 | PathTSPTour tour = PathTSPTourParameter.ActualValue;
|
---|
70 | if (tour == null) PathTSPTourParameter.ActualValue = new PathTSPTour(coordinates, permutations[i]);
|
---|
71 | else {
|
---|
72 | tour.Coordinates = coordinates;
|
---|
73 | tour.Permutation = permutations[i];
|
---|
74 | }
|
---|
75 | return base.Apply();
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|