Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Problems.TravelingSalesman/3.3/PathTSPTour.cs @ 16674

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

#2582 created branch for Hive Web Job Manager

File size: 6.4 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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;
[3107]23using HeuristicLab.Common;
[2]24using HeuristicLab.Core;
25using HeuristicLab.Data;
[3097]26using HeuristicLab.Encodings.PermutationEncoding;
[1823]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[2]28
[3158]29namespace HeuristicLab.Problems.TravelingSalesman {
[884]30  /// <summary>
[3107]31  /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.
[884]32  /// </summary>
[3107]33  [Item("PathTSPTour", "Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.")]
[3097]34  [StorableClass]
[3107]35  public sealed class PathTSPTour : Item {
[3306]36
[13656]37
[3317]38    [Storable]
[3097]39    private DoubleMatrix coordinates;
[13656]40    public DoubleMatrix Coordinates
41    {
[3097]42      get { return coordinates; }
[13656]43      set
44      {
[3097]45        if (coordinates != value) {
[3107]46          if (coordinates != null) DeregisterCoordinatesEvents();
[3097]47          coordinates = value;
[3107]48          if (coordinates != null) RegisterCoordinatesEvents();
[3097]49          OnCoordinatesChanged();
50        }
51      }
[2]52    }
[3317]53    [Storable]
[3097]54    private Permutation permutation;
[13656]55    public Permutation Permutation
56    {
[3097]57      get { return permutation; }
[13656]58      set
59      {
[3097]60        if (permutation != value) {
[3107]61          if (permutation != null) DeregisterPermutationEvents();
[3097]62          permutation = value;
[3133]63          if (permutation != null) RegisterPermutationEvents();
[3097]64          OnPermutationChanged();
65        }
66      }
[2]67    }
[3616]68    [Storable]
69    private DoubleValue quality;
[13656]70    public DoubleValue Quality
71    {
[3616]72      get { return quality; }
[13656]73      set
74      {
[3616]75        if (quality != value) {
76          if (quality != null) DeregisterQualityEvents();
77          quality = value;
78          if (quality != null) RegisterQualityEvents();
79          OnQualityChanged();
80        }
81      }
82    }
[2]83
[4722]84    [StorableConstructor]
85    private PathTSPTour(bool deserializing) : base(deserializing) { }
86    private PathTSPTour(PathTSPTour original, Cloner cloner)
87      : base(original, cloner) {
88      this.coordinates = cloner.Clone(original.coordinates);
89      this.permutation = cloner.Clone(original.permutation);
90      this.quality = cloner.Clone(original.quality);
91      Initialize();
92    }
[3139]93    public PathTSPTour() : base() { }
94    public PathTSPTour(DoubleMatrix coordinates)
[3097]95      : base() {
[3317]96      this.coordinates = coordinates;
97      Initialize();
[3139]98    }
99    public PathTSPTour(DoubleMatrix coordinates, Permutation permutation)
[3317]100      : base() {
101      this.coordinates = coordinates;
102      this.permutation = permutation;
103      Initialize();
[2]104    }
[3616]105    public PathTSPTour(DoubleMatrix coordinates, Permutation permutation, DoubleValue quality)
106      : base() {
107      this.coordinates = coordinates;
108      this.permutation = permutation;
109      this.quality = quality;
110      Initialize();
111    }
[2]112
[4722]113    public override IDeepCloneable Clone(Cloner cloner) {
114      return new PathTSPTour(this, cloner);
115    }
116
[3317]117    [StorableHook(HookType.AfterDeserialization)]
[4722]118    private void AfterDeserialization() {
119      Initialize();
120    }
121
[3317]122    private void Initialize() {
123      if (coordinates != null) RegisterCoordinatesEvents();
124      if (permutation != null) RegisterPermutationEvents();
[3616]125      if (quality != null) RegisterQualityEvents();
[3317]126    }
127
[3107]128    #region Events
[2]129    public event EventHandler CoordinatesChanged;
[3097]130    private void OnCoordinatesChanged() {
[3239]131      var changed = CoordinatesChanged;
132      if (changed != null)
133        changed(this, EventArgs.Empty);
[2]134    }
[3097]135    public event EventHandler PermutationChanged;
136    private void OnPermutationChanged() {
[3239]137      var changed = PermutationChanged;
138      if (changed != null)
139        changed(this, EventArgs.Empty);
[3097]140    }
[3616]141    public event EventHandler QualityChanged;
142    private void OnQualityChanged() {
143      var changed = QualityChanged;
144      if (changed != null)
145        changed(this, EventArgs.Empty);
146    }
[3107]147
148    private void RegisterCoordinatesEvents() {
149      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
150      Coordinates.Reset += new EventHandler(Coordinates_Reset);
151    }
152    private void DeregisterCoordinatesEvents() {
153      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
154      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
155    }
156    private void RegisterPermutationEvents() {
157      Permutation.ItemChanged += new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
158      Permutation.Reset += new EventHandler(Permutation_Reset);
159    }
160    private void DeregisterPermutationEvents() {
161      Permutation.ItemChanged -= new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
162      Permutation.Reset -= new EventHandler(Permutation_Reset);
163    }
[3616]164    private void RegisterQualityEvents() {
165      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
166    }
167    private void DeregisterQualityEvents() {
168      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
169    }
[3107]170
171    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
172      OnCoordinatesChanged();
173    }
174    private void Coordinates_Reset(object sender, EventArgs e) {
175      OnCoordinatesChanged();
176    }
177    private void Permutation_ItemChanged(object sender, EventArgs<int> e) {
178      OnPermutationChanged();
179    }
180    private void Permutation_Reset(object sender, EventArgs e) {
181      OnPermutationChanged();
182    }
[3616]183    private void Quality_ValueChanged(object sender, EventArgs e) {
184      OnQualityChanged();
185    }
[3107]186    #endregion
[2]187  }
188}
Note: See TracBrowser for help on using the repository browser.