Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17356 was 17356, checked in by abeham, 4 years ago

#2521: fixed some problems in Samples.Create unit tests and updated samples

File size: 3.7 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    ITSPData TSPData { 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 sealed class TSPSolution : Item, ITSPSolution {
44    public static new Image StaticItemImage {
45      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
46    }
47
48    [Storable] private ITSPData tspData;
49    public ITSPData TSPData {
50      get { return tspData; }
51      set {
52        if (tspData == value) return;
53        tspData = value;
54        OnPropertyChanged(nameof(TSPData));
55      }
56    }
57
58    [Storable] private Permutation tour;
59    public Permutation Tour {
60      get { return tour; }
61      set {
62        if (tour == value) return;
63        tour = value;
64        OnPropertyChanged(nameof(Tour));
65      }
66    }
67    [Storable] private DoubleValue tourLength;
68    public DoubleValue TourLength {
69      get { return tourLength; }
70      set {
71        if (tourLength == value) return;
72        tourLength = value;
73        OnPropertyChanged(nameof(TourLength));
74      }
75    }
76
77    [StorableConstructor]
78    private TSPSolution(StorableConstructorFlag _) : base(_) { }
79    private TSPSolution(TSPSolution original, Cloner cloner)
80      : base(original, cloner) {
81      this.tspData = cloner.Clone(original.tspData);
82      this.tour = cloner.Clone(original.tour);
83      this.tourLength = cloner.Clone(original.tourLength);
84    }
85    public TSPSolution() : base() { }
86    public TSPSolution(ITSPData data)
87      : base() {
88      this.tspData = data;
89    }
90    public TSPSolution(ITSPData data, Permutation permutation)
91      : base() {
92      this.tspData = data;
93      this.tour = permutation;
94    }
95    public TSPSolution(ITSPData data, Permutation permutation, DoubleValue quality)
96      : base() {
97      this.tspData = data;
98      this.tour = permutation;
99      this.tourLength = quality;
100    }
101
102    public override IDeepCloneable Clone(Cloner cloner) {
103      return new TSPSolution(this, cloner);
104    }
105
106    public event PropertyChangedEventHandler PropertyChanged;
107    private void OnPropertyChanged(string property) {
108      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.