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 IntValue startingPoint;
|
---|
45 | public IntValue StartingPoint {
|
---|
46 | get { return startingPoint; }
|
---|
47 | set {
|
---|
48 | if (startingPoint != value) {
|
---|
49 | if (startingPoint != null) DeregisterStartingPointEvents();
|
---|
50 | startingPoint = value;
|
---|
51 | if (startingPoint != null) RegisterStartingPointEvents();
|
---|
52 | OnStartingPointChanged();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 | [Storable]
|
---|
57 | private IntValue terminusPoint;
|
---|
58 | public IntValue TerminusPoint {
|
---|
59 | get { return terminusPoint; }
|
---|
60 | set {
|
---|
61 | if (terminusPoint != value) {
|
---|
62 | if (terminusPoint != null) DeregisterTerminusPointEvents();
|
---|
63 | terminusPoint = value;
|
---|
64 | if (terminusPoint != null) RegisterTerminusPointEvents();
|
---|
65 | OnTerminusPointChanged();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | [Storable]
|
---|
70 | private DoubleArray scores;
|
---|
71 | public DoubleArray Scores {
|
---|
72 | get { return scores; }
|
---|
73 | set {
|
---|
74 | if (scores != value) {
|
---|
75 | if (scores != null) DeregisterScoresEvents();
|
---|
76 | scores = value;
|
---|
77 | if (scores != null) RegisterScoresEvents();
|
---|
78 | OnScoresChanged();
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 | [Storable]
|
---|
83 | private DoubleValue quality;
|
---|
84 | public DoubleValue Quality {
|
---|
85 | get { return quality; }
|
---|
86 | set {
|
---|
87 | if (quality != value) {
|
---|
88 | if (quality != null) DeregisterQualityEvents();
|
---|
89 | quality = value;
|
---|
90 | if (quality != null) RegisterQualityEvents();
|
---|
91 | OnQualityChanged();
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | [StorableConstructor]
|
---|
97 | private OrienteeringSolution(bool deserializing) : base(deserializing) { }
|
---|
98 | private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
|
---|
99 | : base(original, cloner) {
|
---|
100 | this.integerVector = cloner.Clone(original.integerVector);
|
---|
101 | this.coordinates = cloner.Clone(original.coordinates);
|
---|
102 | this.quality = cloner.Clone(original.quality);
|
---|
103 | Initialize();
|
---|
104 | }
|
---|
105 | public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, IntValue startingPoint, IntValue terminusPoint,
|
---|
106 | DoubleArray scores, DoubleValue quality)
|
---|
107 | : base() {
|
---|
108 | this.integerVector = integerVector;
|
---|
109 | this.coordinates = coordinates;
|
---|
110 | this.startingPoint = startingPoint;
|
---|
111 | this.terminusPoint = terminusPoint;
|
---|
112 | this.scores = scores;
|
---|
113 | this.quality = quality;
|
---|
114 | Initialize();
|
---|
115 | }
|
---|
116 |
|
---|
117 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
118 | return new OrienteeringSolution(this, cloner);
|
---|
119 | }
|
---|
120 |
|
---|
121 | [StorableHook(HookType.AfterDeserialization)]
|
---|
122 | private void AfterDeserialization() {
|
---|
123 | Initialize();
|
---|
124 | }
|
---|
125 |
|
---|
126 | private void Initialize() {
|
---|
127 | if (integerVector != null) RegisterIntegerVectorEvents();
|
---|
128 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
129 | if (startingPoint != null) RegisterStartingPointEvents();
|
---|
130 | if (terminusPoint != null) RegisterTerminusPointEvents();
|
---|
131 | if (scores != null) RegisterScoresEvents();
|
---|
132 | if (quality != null) RegisterQualityEvents();
|
---|
133 | }
|
---|
134 |
|
---|
135 | #region Events
|
---|
136 | public event EventHandler IntegerVectorChanged;
|
---|
137 | private void OnIntegerVectorChanged() {
|
---|
138 | var changed = IntegerVectorChanged;
|
---|
139 | if (changed != null)
|
---|
140 | changed(this, EventArgs.Empty);
|
---|
141 | }
|
---|
142 |
|
---|
143 | public event EventHandler CoordinatesChanged;
|
---|
144 | private void OnCoordinatesChanged() {
|
---|
145 | var changed = CoordinatesChanged;
|
---|
146 | if (changed != null)
|
---|
147 | changed(this, EventArgs.Empty);
|
---|
148 | }
|
---|
149 |
|
---|
150 | public event EventHandler StartingPointChanged;
|
---|
151 | private void OnStartingPointChanged() {
|
---|
152 | var changed = StartingPointChanged;
|
---|
153 | if (changed != null)
|
---|
154 | changed(this, EventArgs.Empty);
|
---|
155 | }
|
---|
156 |
|
---|
157 | public event EventHandler TerminusPointChanged;
|
---|
158 | private void OnTerminusPointChanged() {
|
---|
159 | var changed = TerminusPointChanged;
|
---|
160 | if (changed != null)
|
---|
161 | changed(this, EventArgs.Empty);
|
---|
162 | }
|
---|
163 |
|
---|
164 | public event EventHandler ScoresChanged;
|
---|
165 | private void OnScoresChanged() {
|
---|
166 | var changed = ScoresChanged;
|
---|
167 | if (changed != null)
|
---|
168 | changed(this, EventArgs.Empty);
|
---|
169 | }
|
---|
170 |
|
---|
171 | public event EventHandler QualityChanged;
|
---|
172 | private void OnQualityChanged() {
|
---|
173 | var changed = QualityChanged;
|
---|
174 | if (changed != null)
|
---|
175 | changed(this, EventArgs.Empty);
|
---|
176 | }
|
---|
177 |
|
---|
178 | private void RegisterIntegerVectorEvents() {
|
---|
179 | IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
180 | IntegerVector.Reset += new EventHandler(IntegerVector_Reset);
|
---|
181 | }
|
---|
182 | private void DeregisterIntegerVectorEvents() {
|
---|
183 | IntegerVector.ItemChanged -= new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
|
---|
184 | IntegerVector.Reset -= new EventHandler(IntegerVector_Reset);
|
---|
185 | }
|
---|
186 | private void RegisterCoordinatesEvents() {
|
---|
187 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
188 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
189 | }
|
---|
190 | private void DeregisterCoordinatesEvents() {
|
---|
191 | Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
192 | Coordinates.Reset -= new EventHandler(Coordinates_Reset);
|
---|
193 | }
|
---|
194 | private void RegisterStartingPointEvents() {
|
---|
195 | StartingPoint.ValueChanged += new EventHandler(StartingPoint_ValueChanged);
|
---|
196 | }
|
---|
197 | private void DeregisterStartingPointEvents() {
|
---|
198 | StartingPoint.ValueChanged -= new EventHandler(StartingPoint_ValueChanged);
|
---|
199 | }
|
---|
200 | private void RegisterTerminusPointEvents() {
|
---|
201 | TerminusPoint.ValueChanged += new EventHandler(TerminusPoint_ValueChanged);
|
---|
202 | }
|
---|
203 | private void DeregisterTerminusPointEvents() {
|
---|
204 | TerminusPoint.ValueChanged -= new EventHandler(TerminusPoint_ValueChanged);
|
---|
205 | }
|
---|
206 | private void RegisterScoresEvents() {
|
---|
207 | Scores.ItemChanged += new EventHandler<EventArgs<int>>(Scores_ItemChanged);
|
---|
208 | Scores.Reset += new EventHandler(Scores_Reset);
|
---|
209 | }
|
---|
210 | private void DeregisterScoresEvents() {
|
---|
211 | Scores.ItemChanged -= new EventHandler<EventArgs<int>>(Scores_ItemChanged);
|
---|
212 | Scores.Reset -= new EventHandler(Scores_Reset);
|
---|
213 | }
|
---|
214 | private void RegisterQualityEvents() {
|
---|
215 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
216 | }
|
---|
217 | private void DeregisterQualityEvents() {
|
---|
218 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
219 | }
|
---|
220 |
|
---|
221 | private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) {
|
---|
222 | OnIntegerVectorChanged();
|
---|
223 | }
|
---|
224 | private void IntegerVector_Reset(object sender, EventArgs e) {
|
---|
225 | OnIntegerVectorChanged();
|
---|
226 | }
|
---|
227 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
228 | OnCoordinatesChanged();
|
---|
229 | }
|
---|
230 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
231 | OnCoordinatesChanged();
|
---|
232 | }
|
---|
233 | private void StartingPoint_ValueChanged(object sender, EventArgs e) {
|
---|
234 | OnStartingPointChanged();
|
---|
235 | }
|
---|
236 | private void TerminusPoint_ValueChanged(object sender, EventArgs e) {
|
---|
237 | OnTerminusPointChanged();
|
---|
238 | }
|
---|
239 | private void Scores_ItemChanged(object sender, EventArgs<int> e) {
|
---|
240 | OnCoordinatesChanged();
|
---|
241 | }
|
---|
242 | private void Scores_Reset(object sender, EventArgs e) {
|
---|
243 | OnCoordinatesChanged();
|
---|
244 | }
|
---|
245 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
246 | OnQualityChanged();
|
---|
247 | }
|
---|
248 | #endregion
|
---|
249 | }
|
---|
250 | } |
---|