Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs @ 13777

Last change on this file since 13777 was 13656, checked in by ascheibe, 9 years ago

#2582 created branch for Hive Web Job Manager

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