Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/10 04:56:06 (14 years ago)
Author:
swagner
Message:

Continued to implement TSP tour visualization (#924)

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/PathTSPTour.cs

    r3104 r3107  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    2829namespace HeuristicLab.Problems.TSP {
    2930  /// <summary>
    30   /// Represents a tour of a Traveling Salesman Problem which can be visualized in the GUI.
     31  /// Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.
    3132  /// </summary>
    32   [Item("TSPTour", "Represents a tour of a Traveling Salesman Problem which can be visualized in the GUI.")]
     33  [Item("PathTSPTour", "Represents a tour of a Traveling Salesman Problem given in path representation which can be visualized in the GUI.")]
    3334  [StorableClass]
    34   public sealed class TSPTour : Item {
     35  public sealed class PathTSPTour : Item {
    3536    private DoubleMatrix coordinates;
    3637    [Storable]
     
    4041        if (value == null) throw new ArgumentNullException();
    4142        if (coordinates != value) {
     43          if (coordinates != null) DeregisterCoordinatesEvents();
    4244          coordinates = value;
     45          if (coordinates != null) RegisterCoordinatesEvents();
    4346          OnCoordinatesChanged();
    4447        }
     
    5255        if (value == null) throw new ArgumentNullException();
    5356        if (permutation != value) {
     57          if (permutation != null) DeregisterPermutationEvents();
    5458          permutation = value;
     59          if (permutation != null) RegisterCoordinatesEvents();
    5560          OnPermutationChanged();
    5661        }
     
    5863    }
    5964
    60     private TSPTour() : base() { }
    61     public TSPTour(DoubleMatrix coordinates, Permutation permutation)
     65    private PathTSPTour() : base() { }
     66    public PathTSPTour(DoubleMatrix coordinates, Permutation permutation)
    6267      : base() {
    63       if ((coordinates == null) || (permutation == null)) throw new ArgumentNullException();
    64       this.coordinates = coordinates;
    65       this.permutation = permutation;
     68      Coordinates = coordinates;
     69      Permutation = permutation;
    6670    }
    6771
    6872    public override IDeepCloneable Clone(Cloner cloner) {
    69       TSPTour clone = new TSPTour((DoubleMatrix)cloner.Clone(coordinates), (Permutation)cloner.Clone(permutation));
     73      PathTSPTour clone = new PathTSPTour();
    7074      cloner.RegisterClonedObject(this, clone);
     75      clone.Coordinates = (DoubleMatrix)cloner.Clone(coordinates);
     76      clone.Permutation = (Permutation)cloner.Clone(permutation);
    7177      return clone;
    7278    }
    7379
     80    #region Events
    7481    public event EventHandler CoordinatesChanged;
    7582    private void OnCoordinatesChanged() {
     
    8289        PermutationChanged(this, EventArgs.Empty);
    8390    }
     91
     92    private void RegisterCoordinatesEvents() {
     93      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
     94      Coordinates.Reset += new EventHandler(Coordinates_Reset);
     95    }
     96    private void DeregisterCoordinatesEvents() {
     97      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
     98      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
     99    }
     100    private void RegisterPermutationEvents() {
     101      Permutation.ItemChanged += new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
     102      Permutation.Reset += new EventHandler(Permutation_Reset);
     103    }
     104    private void DeregisterPermutationEvents() {
     105      Permutation.ItemChanged -= new EventHandler<EventArgs<int>>(Permutation_ItemChanged);
     106      Permutation.Reset -= new EventHandler(Permutation_Reset);
     107    }
     108
     109    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
     110      OnCoordinatesChanged();
     111    }
     112    private void Coordinates_Reset(object sender, EventArgs e) {
     113      OnCoordinatesChanged();
     114    }
     115    private void Permutation_ItemChanged(object sender, EventArgs<int> e) {
     116      OnPermutationChanged();
     117    }
     118    private void Permutation_Reset(object sender, EventArgs e) {
     119      OnPermutationChanged();
     120    }
     121    #endregion
    84122  }
    85123}
Note: See TracChangeset for help on using the changeset viewer.