Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSPSolution.cs @ 17533

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

#2521: Unified architecture

File size: 3.5 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;
29using HeuristicLab.Problems.TravelingSalesman;
30
31namespace HeuristicLab.Problems.PTSP {
32  [StorableType("596f52b5-b2c8-45a0-a7bd-e5b9c787c960")]
33  public interface IProbabilisticTSPSolution : ITSPSolution {
34    PercentArray Probabilities { get; }
35  }
36
37  /// <summary>
38  /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.
39  /// </summary>
40  [Item("pTSP Solution", "Represents a tour of a Probabilistic Traveling Salesman Problem given in path representation which can be visualized in the GUI.")]
41  [StorableType("ea784622-41e5-493e-a1f3-4c38fed99216")]
42  public sealed class ProbabilisticTSPSolution : Item, IProbabilisticTSPSolution {
43    public static new Image StaticItemImage {
44      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
45    }
46
47    [Storable]
48    private ITSPSolution tspSolution;
49    public ITSPSolution TSPSolution {
50      get { return tspSolution; }
51      set {
52        if (tspSolution == value) return;
53        tspSolution = value;
54        OnPropertyChanged(nameof(TSPSolution));
55      }
56    }
57
58    [Storable]
59    private PercentArray probabilities;
60    public PercentArray Probabilities {
61      get { return probabilities; }
62      set {
63        if (probabilities == value) return;
64        probabilities = value;
65        OnPropertyChanged(nameof(Probabilities));
66      }
67    }
68
69    ITSPData ITSPSolution.Data => tspSolution.Data;
70
71    Permutation ITSPSolution.Tour => tspSolution.Tour;
72
73    DoubleValue ITSPSolution.TourLength => tspSolution.TourLength;
74
75    [StorableConstructor]
76    private ProbabilisticTSPSolution(StorableConstructorFlag _) : base(_) { }
77    private ProbabilisticTSPSolution(ProbabilisticTSPSolution original, Cloner cloner)
78      : base(original, cloner) {
79      this.tspSolution = cloner.Clone(original.tspSolution);
80      this.probabilities = cloner.Clone(original.probabilities);
81    }
82    public ProbabilisticTSPSolution() : base() { }
83    public ProbabilisticTSPSolution(ITSPSolution tspSolution, PercentArray probabilities)
84      : base() {
85      this.tspSolution = tspSolution;
86      this.probabilities = probabilities;
87    }
88
89    public override IDeepCloneable Clone(Cloner cloner) {
90      return new ProbabilisticTSPSolution(this, cloner);
91    }
92
93    public event PropertyChangedEventHandler PropertyChanged;
94    private void OnPropertyChanged(string property) {
95      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.