Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs @ 17956

Last change on this file since 17956 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 11.6 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;
23using System.Drawing;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.IntegerVectorEncoding;
28using HEAL.Attic;
29
30namespace HeuristicLab.Problems.Orienteering {
31  [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
32  [StorableType("BC58ED08-B9A7-40F3-B8E0-A6B33AA993F4")]
33  public sealed class OrienteeringSolution : Item {
34    public static new Image StaticItemImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
36    }
37
38    [Storable]
39    private IntegerVector integerVector;
40    public IntegerVector IntegerVector {
41      get { return integerVector; }
42      set {
43        if (integerVector != value) {
44          if (integerVector != null) DeregisterIntegerVectorEvents();
45          integerVector = value;
46          if (integerVector != null) RegisterIntegerVectorEvents();
47          OnIntegerVectorChanged();
48        }
49      }
50    }
51    [Storable]
52    private DoubleMatrix coordinates;
53    public DoubleMatrix Coordinates {
54      get { return coordinates; }
55      set {
56        if (coordinates != value) {
57          if (coordinates != null) DeregisterCoordinatesEvents();
58          coordinates = value;
59          if (coordinates != null) RegisterCoordinatesEvents();
60          OnCoordinatesChanged();
61        }
62      }
63    }
64    [Storable]
65    private IntValue startingPoint;
66    public IntValue StartingPoint {
67      get { return startingPoint; }
68      set {
69        if (startingPoint != value) {
70          if (startingPoint != null) DeregisterStartingPointEvents();
71          startingPoint = value;
72          if (startingPoint != null) RegisterStartingPointEvents();
73          OnStartingPointChanged();
74        }
75      }
76    }
77    [Storable]
78    private IntValue terminalPoint;
79    public IntValue TerminalPoint {
80      get { return terminalPoint; }
81      set {
82        if (terminalPoint != value) {
83          if (terminalPoint != null) DeregisterTerminalPointEvents();
84          terminalPoint = value;
85          if (terminalPoint != null) RegisterTerminalPointEvents();
86          OnTerminalPointChanged();
87        }
88      }
89    }
90    [Storable]
91    private DoubleArray scores;
92    public DoubleArray Scores {
93      get { return scores; }
94      set {
95        if (scores != value) {
96          if (scores != null) DeregisterScoresEvents();
97          scores = value;
98          if (scores != null) RegisterScoresEvents();
99          OnScoresChanged();
100        }
101      }
102    }
103    [Storable]
104    private DoubleValue quality;
105    public DoubleValue Quality {
106      get { return quality; }
107      set {
108        if (quality != value) {
109          if (quality != null) DeregisterQualityEvents();
110          quality = value;
111          if (quality != null) RegisterQualityEvents();
112          OnQualityChanged();
113        }
114      }
115    }
116    [Storable]
117    private DoubleValue penalty;
118    public DoubleValue Penalty {
119      get { return penalty; }
120      set {
121        if (penalty != value) {
122          if (penalty != null) DeregisterPenaltyEvents();
123          penalty = value;
124          if (penalty != null) RegisterPenaltyEvents();
125          OnPenaltyChanged();
126        }
127      }
128    }
129    [Storable]
130    private DoubleValue distance;
131    public DoubleValue Distance {
132      get { return distance; }
133      set {
134        if (distance != value) {
135          if (distance != null) DeregisterDistanceEvents();
136          distance = value;
137          if (distance != null) RegisterDistanceEvents();
138          OnDistanceChanged();
139        }
140      }
141    }
142
143    [StorableConstructor]
144    private OrienteeringSolution(StorableConstructorFlag _) : base(_) { }
145    private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
146      : base(original, cloner) {
147      this.integerVector = cloner.Clone(original.integerVector);
148      this.coordinates = cloner.Clone(original.coordinates);
149      this.quality = cloner.Clone(original.quality);
150      this.penalty = cloner.Clone(original.penalty);
151      Initialize();
152    }
153    public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, IntValue startingPoint, IntValue terminalPoint,
154      DoubleArray scores, DoubleValue quality = null, DoubleValue penalty = null, DoubleValue distance = null)
155      : base() {
156      this.integerVector = integerVector;
157      this.coordinates = coordinates;
158      this.startingPoint = startingPoint;
159      this.terminalPoint = terminalPoint;
160      this.scores = scores;
161      this.quality = quality;
162      this.penalty = penalty;
163      this.distance = distance;
164      Initialize();
165    }
166
167    public override IDeepCloneable Clone(Cloner cloner) {
168      return new OrienteeringSolution(this, cloner);
169    }
170
171    [StorableHook(HookType.AfterDeserialization)]
172    private void AfterDeserialization() {
173      Initialize();
174    }
175
176    private void Initialize() {
177      if (integerVector != null) RegisterIntegerVectorEvents();
178      if (coordinates != null) RegisterCoordinatesEvents();
179      if (startingPoint != null) RegisterStartingPointEvents();
180      if (terminalPoint != null) RegisterTerminalPointEvents();
181      if (scores != null) RegisterScoresEvents();
182      if (quality != null) RegisterQualityEvents();
183      if (penalty != null) RegisterPenaltyEvents();
184      if (distance != null) RegisterDistanceEvents();
185    }
186
187    #region Events
188    public event EventHandler IntegerVectorChanged;
189    private void OnIntegerVectorChanged() {
190      var changed = IntegerVectorChanged;
191      if (changed != null)
192        changed(this, EventArgs.Empty);
193    }
194
195    public event EventHandler CoordinatesChanged;
196    private void OnCoordinatesChanged() {
197      var changed = CoordinatesChanged;
198      if (changed != null)
199        changed(this, EventArgs.Empty);
200    }
201
202    public event EventHandler StartingPointChanged;
203    private void OnStartingPointChanged() {
204      var changed = StartingPointChanged;
205      if (changed != null)
206        changed(this, EventArgs.Empty);
207    }
208
209    public event EventHandler TerminalPointChanged;
210    private void OnTerminalPointChanged() {
211      var changed = TerminalPointChanged;
212      if (changed != null)
213        changed(this, EventArgs.Empty);
214    }
215
216    public event EventHandler ScoresChanged;
217    private void OnScoresChanged() {
218      var changed = ScoresChanged;
219      if (changed != null)
220        changed(this, EventArgs.Empty);
221    }
222
223    public event EventHandler QualityChanged;
224    private void OnQualityChanged() {
225      var changed = QualityChanged;
226      if (changed != null)
227        changed(this, EventArgs.Empty);
228    }
229
230    public event EventHandler PenaltyChanged;
231    private void OnPenaltyChanged() {
232      var changed = PenaltyChanged;
233      if (changed != null)
234        changed(this, EventArgs.Empty);
235    }
236
237    public event EventHandler DistanceChanged;
238    private void OnDistanceChanged() {
239      var changed = DistanceChanged;
240      if (changed != null)
241        changed(this, EventArgs.Empty);
242    }
243
244    private void RegisterIntegerVectorEvents() {
245      IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
246      IntegerVector.Reset += new EventHandler(IntegerVector_Reset);
247    }
248    private void DeregisterIntegerVectorEvents() {
249      IntegerVector.ItemChanged -= new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
250      IntegerVector.Reset -= new EventHandler(IntegerVector_Reset);
251    }
252    private void RegisterCoordinatesEvents() {
253      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
254      Coordinates.Reset += new EventHandler(Coordinates_Reset);
255    }
256    private void DeregisterCoordinatesEvents() {
257      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
258      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
259    }
260    private void RegisterStartingPointEvents() {
261      StartingPoint.ValueChanged += new EventHandler(StartingPoint_ValueChanged);
262    }
263    private void DeregisterStartingPointEvents() {
264      StartingPoint.ValueChanged -= new EventHandler(StartingPoint_ValueChanged);
265    }
266    private void RegisterTerminalPointEvents() {
267      TerminalPoint.ValueChanged += new EventHandler(TerminalPoint_ValueChanged);
268    }
269    private void DeregisterTerminalPointEvents() {
270      TerminalPoint.ValueChanged -= new EventHandler(TerminalPoint_ValueChanged);
271    }
272    private void RegisterScoresEvents() {
273      Scores.ItemChanged += new EventHandler<EventArgs<int>>(Scores_ItemChanged);
274      Scores.Reset += new EventHandler(Scores_Reset);
275    }
276    private void DeregisterScoresEvents() {
277      Scores.ItemChanged -= new EventHandler<EventArgs<int>>(Scores_ItemChanged);
278      Scores.Reset -= new EventHandler(Scores_Reset);
279    }
280    private void RegisterQualityEvents() {
281      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
282    }
283    private void DeregisterQualityEvents() {
284      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
285    }
286    private void RegisterPenaltyEvents() {
287      Penalty.ValueChanged += new EventHandler(Penalty_ValueChanged);
288    }
289    private void DeregisterPenaltyEvents() {
290      Penalty.ValueChanged -= new EventHandler(Penalty_ValueChanged);
291    }
292    private void RegisterDistanceEvents() {
293      Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
294    }
295    private void DeregisterDistanceEvents() {
296      Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
297    }
298
299    private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) {
300      OnIntegerVectorChanged();
301    }
302    private void IntegerVector_Reset(object sender, EventArgs e) {
303      OnIntegerVectorChanged();
304    }
305    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
306      OnCoordinatesChanged();
307    }
308    private void Coordinates_Reset(object sender, EventArgs e) {
309      OnCoordinatesChanged();
310    }
311    private void StartingPoint_ValueChanged(object sender, EventArgs e) {
312      OnStartingPointChanged();
313    }
314    private void TerminalPoint_ValueChanged(object sender, EventArgs e) {
315      OnTerminalPointChanged();
316    }
317    private void Scores_ItemChanged(object sender, EventArgs<int> e) {
318      OnCoordinatesChanged();
319    }
320    private void Scores_Reset(object sender, EventArgs e) {
321      OnCoordinatesChanged();
322    }
323    private void Quality_ValueChanged(object sender, EventArgs e) {
324      OnQualityChanged();
325    }
326    private void Penalty_ValueChanged(object sender, EventArgs e) {
327      OnPenaltyChanged();
328    }
329    private void Distance_ValueChanged(object sender, EventArgs e) {
330      OnDistanceChanged();
331    }
332    #endregion
333  }
334}
Note: See TracBrowser for help on using the repository browser.