Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/PathTSPTour.cs @ 3158

Last change on this file since 3158 was 3158, checked in by swagner, 14 years ago

Renamed HeuristicLab.Problems.TSP to HeuristicLab.Problems.TravelingSalesman (#924).

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.PermutationEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.TravelingSalesman {
30  /// <summary>
31  /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.
32  /// </summary>
33  [Item("PathTSPTour", "Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.")]
34  [StorableClass]
35  public sealed class PathTSPTour : Item {
36    private DoubleMatrix coordinates;
37    [Storable]
38    public DoubleMatrix Coordinates {
39      get { return coordinates; }
40      set {
41        if (coordinates != value) {
42          if (coordinates != null) DeregisterCoordinatesEvents();
43          coordinates = value;
44          if (coordinates != null) RegisterCoordinatesEvents();
45          OnCoordinatesChanged();
46        }
47      }
48    }
49    private Permutation permutation;
50    [Storable]
51    public Permutation Permutation {
52      get { return permutation; }
53      set {
54        if (permutation != value) {
55          if (permutation != null) DeregisterPermutationEvents();
56          permutation = value;
57          if (permutation != null) RegisterPermutationEvents();
58          OnPermutationChanged();
59        }
60      }
61    }
62
63    public PathTSPTour() : base() { }
64    public PathTSPTour(DoubleMatrix coordinates)
65      : base() {
66      Coordinates = coordinates;
67    }
68    public PathTSPTour(DoubleMatrix coordinates, Permutation permutation)
69      : this(coordinates) {
70      Permutation = permutation;
71    }
72
73    public override IDeepCloneable Clone(Cloner cloner) {
74      PathTSPTour clone = new PathTSPTour();
75      cloner.RegisterClonedObject(this, clone);
76      clone.Coordinates = (DoubleMatrix)cloner.Clone(coordinates);
77      clone.Permutation = (Permutation)cloner.Clone(permutation);
78      return clone;
79    }
80
81    #region Events
82    public event EventHandler CoordinatesChanged;
83    private void OnCoordinatesChanged() {
84      if (CoordinatesChanged != null)
85        CoordinatesChanged(this, EventArgs.Empty);
86    }
87    public event EventHandler PermutationChanged;
88    private void OnPermutationChanged() {
89      if (PermutationChanged != null)
90        PermutationChanged(this, EventArgs.Empty);
91    }
92
93    private void RegisterCoordinatesEvents() {
94      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
95      Coordinates.Reset += new EventHandler(Coordinates_Reset);
96    }
97    private void DeregisterCoordinatesEvents() {
98      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
99      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
100    }
101    private void RegisterPermutationEvents() {
102      Permutation.ItemChanged += new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
103      Permutation.Reset += new EventHandler(Permutation_Reset);
104    }
105    private void DeregisterPermutationEvents() {
106      Permutation.ItemChanged -= new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
107      Permutation.Reset -= new EventHandler(Permutation_Reset);
108    }
109
110    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
111      OnCoordinatesChanged();
112    }
113    private void Coordinates_Reset(object sender, EventArgs e) {
114      OnCoordinatesChanged();
115    }
116    private void Permutation_ItemChanged(object sender, EventArgs<int> e) {
117      OnPermutationChanged();
118    }
119    private void Permutation_Reset(object sender, EventArgs e) {
120      OnPermutationChanged();
121    }
122    #endregion
123  }
124}
Note: See TracBrowser for help on using the repository browser.