1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Problems.Orienteering {
|
---|
10 | [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
|
---|
11 | [StorableClass]
|
---|
12 | public class OrienteeringSolution : Item {
|
---|
13 | public static new Image StaticItemImage {
|
---|
14 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
|
---|
15 | }
|
---|
16 |
|
---|
17 | [Storable]
|
---|
18 | private IntegerVector integerVector;
|
---|
19 | public IntegerVector IntegerVector {
|
---|
20 | get { return integerVector; }
|
---|
21 | set {
|
---|
22 | if (integerVector != value) {
|
---|
23 | if (integerVector != null) DeregisterIntegerVectorEvents();
|
---|
24 | integerVector = value;
|
---|
25 | if (integerVector != null) RegisterIntegerVectorEvents();
|
---|
26 | OnIntegerVectorChanged();
|
---|
27 | }
|
---|
28 | }
|
---|
29 | }
|
---|
30 | [Storable]
|
---|
31 | private DoubleMatrix coordinates;
|
---|
32 | public DoubleMatrix Coordinates {
|
---|
33 | get { return coordinates; }
|
---|
34 | set {
|
---|
35 | if (coordinates != value) {
|
---|
36 | if (coordinates != null) DeregisterCoordinatesEvents();
|
---|
37 | coordinates = value;
|
---|
38 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
39 | OnCoordinatesChanged();
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 | [Storable]
|
---|
44 | private DoubleValue quality;
|
---|
45 | public DoubleValue Quality {
|
---|
46 | get { return quality; }
|
---|
47 | set {
|
---|
48 | if (quality != value) {
|
---|
49 | if (quality != null) DeregisterQualityEvents();
|
---|
50 | quality = value;
|
---|
51 | if (quality != null) RegisterQualityEvents();
|
---|
52 | OnQualityChanged();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | [StorableConstructor]
|
---|
58 | private OrienteeringSolution(bool deserializing) : base(deserializing) { }
|
---|
59 | private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
|
---|
60 | : base(original, cloner) {
|
---|
61 | this.integerVector = cloner.Clone(original.integerVector);
|
---|
62 | this.coordinates = cloner.Clone(original.coordinates);
|
---|
63 | this.quality = cloner.Clone(original.quality);
|
---|
64 | Initialize();
|
---|
65 | }
|
---|
66 | public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, DoubleValue quality)
|
---|
67 | : base() {
|
---|
68 | this.integerVector = integerVector;
|
---|
69 | this.coordinates = coordinates;
|
---|
70 | this.quality = quality;
|
---|
71 | Initialize();
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
75 | return new OrienteeringSolution(this, cloner);
|
---|
76 | }
|
---|
77 |
|
---|
78 | [StorableHook(HookType.AfterDeserialization)]
|
---|
79 | private void AfterDeserialization() {
|
---|
80 | Initialize();
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void Initialize() {
|
---|
84 | if (integerVector != null) RegisterIntegerVectorEvents();
|
---|
85 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
86 | if (quality != null) RegisterQualityEvents();
|
---|
87 | }
|
---|
88 |
|
---|
89 | #region Events
|
---|
90 | public event EventHandler IntegerVectorChanged;
|
---|
91 | private void OnIntegerVectorChanged() {
|
---|
92 | var changed = IntegerVectorChanged;
|
---|
93 | if (changed != null)
|
---|
94 | changed(this, EventArgs.Empty);
|
---|
95 | }
|
---|
96 |
|
---|
97 | public event EventHandler CoordinatesChanged;
|
---|
98 | private void OnCoordinatesChanged() {
|
---|
99 | var changed = CoordinatesChanged;
|
---|
100 | if (changed != null)
|
---|
101 | changed(this, EventArgs.Empty);
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | public event EventHandler QualityChanged;
|
---|
106 | private void OnQualityChanged() {
|
---|
107 | var changed = QualityChanged;
|
---|
108 | if (changed != null)
|
---|
109 | changed(this, EventArgs.Empty);
|
---|
110 | }
|
---|
111 |
|
---|
112 | private void RegisterIntegerVectorEvents() {
|
---|
113 | IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
114 | IntegerVector.Reset += new EventHandler(IntegerVector_Reset);
|
---|
115 | }
|
---|
116 | private void DeregisterIntegerVectorEvents() {
|
---|
117 | IntegerVector.ItemChanged -= new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
118 | IntegerVector.Reset -= new EventHandler(IntegerVector_Reset);
|
---|
119 | }
|
---|
120 | private void RegisterCoordinatesEvents() {
|
---|
121 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
122 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
123 | }
|
---|
124 | private void DeregisterCoordinatesEvents() {
|
---|
125 | Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
126 | Coordinates.Reset -= new EventHandler(Coordinates_Reset);
|
---|
127 | }
|
---|
128 | private void RegisterQualityEvents() {
|
---|
129 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
130 | }
|
---|
131 | private void DeregisterQualityEvents() {
|
---|
132 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
133 | }
|
---|
134 |
|
---|
135 | private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
136 | OnIntegerVectorChanged();
|
---|
137 | }
|
---|
138 | private void IntegerVector_Reset(object sender, EventArgs e) {
|
---|
139 | OnIntegerVectorChanged();
|
---|
140 | }
|
---|
141 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
142 | OnCoordinatesChanged();
|
---|
143 | }
|
---|
144 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
145 | OnCoordinatesChanged();
|
---|
146 | }
|
---|
147 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
148 | OnQualityChanged();
|
---|
149 | }
|
---|
150 | #endregion
|
---|
151 | }
|
---|
152 | } |
---|