Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2521: Refactored pTSP to use compositional pattern

File size: 3.3 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.Problems.TravelingSalesman;
29
30namespace HeuristicLab.Problems.PTSP {
31  [StorableType("596f52b5-b2c8-45a0-a7bd-e5b9c787c960")]
32  public interface IProbabilisticTSPSolution : IItem, INotifyPropertyChanged {
33    ITSPSolution TSPSolution { get; }
34    DoubleArray 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 DoubleArray probabilities;
60    public DoubleArray Probabilities {
61      get { return probabilities; }
62      set {
63        if (probabilities == value) return;
64        probabilities = value;
65        OnPropertyChanged(nameof(Probabilities));
66      }
67    }
68
69    [StorableConstructor]
70    private ProbabilisticTSPSolution(StorableConstructorFlag _) : base(_) { }
71    private ProbabilisticTSPSolution(ProbabilisticTSPSolution original, Cloner cloner)
72      : base(original, cloner) {
73      this.tspSolution = cloner.Clone(original.tspSolution);
74      this.probabilities = cloner.Clone(original.probabilities);
75    }
76    public ProbabilisticTSPSolution() : base() { }
77    public ProbabilisticTSPSolution(ITSPSolution tspSolution, PercentArray probabilities)
78      : base() {
79      this.tspSolution = tspSolution;
80      this.probabilities = probabilities;
81    }
82
83    public override IDeepCloneable Clone(Cloner cloner) {
84      return new ProbabilisticTSPSolution(this, cloner);
85    }
86
87    public event PropertyChangedEventHandler PropertyChanged;
88    private void OnPropertyChanged(string property) {
89      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.