Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSPSolution.cs @ 17260

Last change on this file since 17260 was 17260, checked in by abeham, 5 years ago

#2521: Worked on PTSP refactoring

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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
22using System.ComponentModel;
23using System.Drawing;
24using HEAL.Attic;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.PermutationEncoding;
29
30namespace HeuristicLab.Problems.TravelingSalesman {
31  [StorableType("f08a63d9-0b83-4944-9251-42925baeb872")]
32  public interface ITSPSolution : IItem, INotifyPropertyChanged {
33    DoubleMatrix Coordinates { get; }
34    Permutation Tour { get; }
35    DoubleValue TourLength { get; }
36  }
37
38  /// <summary>
39  /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.
40  /// </summary>
41  [Item("TSP Solution", "Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.")]
42  [StorableType("38d1aac3-3047-40d9-bcf9-4b3ca0b9f95c")]
43  public class TSPSolution : Item, ITSPSolution {
44    public static new Image StaticItemImage {
45      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
46    }
47
48    [Storable]
49    private DoubleMatrix coordinates;
50    public DoubleMatrix Coordinates {
51      get { return coordinates; }
52      set {
53        if (coordinates == value) return;
54        coordinates = value;
55        OnPropertyChanged(nameof(Coordinates));
56      }
57    }
58
59    [Storable]
60    private Permutation tour;
61    public Permutation Tour {
62      get { return tour; }
63      set {
64        if (tour == value) return;
65        tour = value;
66        OnPropertyChanged(nameof(Tour));
67      }
68    }
69    [Storable]
70    private DoubleValue tourLength;
71    public DoubleValue TourLength {
72      get { return tourLength; }
73      set {
74        if (tourLength == value) return;
75        tourLength = value;
76        OnPropertyChanged(nameof(TourLength));
77      }
78    }
79
80    [StorableConstructor]
81    protected TSPSolution(StorableConstructorFlag _) : base(_) { }
82    protected TSPSolution(TSPSolution original, Cloner cloner)
83      : base(original, cloner) {
84      this.coordinates = cloner.Clone(original.coordinates);
85      this.tour = cloner.Clone(original.tour);
86      this.tourLength = cloner.Clone(original.tourLength);
87    }
88    public TSPSolution() : base() { }
89    public TSPSolution(DoubleMatrix coordinates)
90      : base() {
91      this.coordinates = coordinates;
92    }
93    public TSPSolution(DoubleMatrix coordinates, Permutation permutation)
94      : base() {
95      this.coordinates = coordinates;
96      this.tour = permutation;
97    }
98    public TSPSolution(DoubleMatrix coordinates, Permutation permutation, DoubleValue quality)
99      : base() {
100      this.coordinates = coordinates;
101      this.tour = permutation;
102      this.tourLength = quality;
103    }
104
105    public override IDeepCloneable Clone(Cloner cloner) {
106      return new TSPSolution(this, cloner);
107    }
108
109    public event PropertyChangedEventHandler PropertyChanged;
110    protected void OnPropertyChanged(string property) {
111      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.