[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Xml;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Permutation;
|
---|
[1699] | 29 | using HeuristicLab.Persistence.Default.Decomposers.Storable;
|
---|
[2] | 30 |
|
---|
| 31 | namespace HeuristicLab.Routing.TSP {
|
---|
[884] | 32 | /// <summary>
|
---|
| 33 | /// Represent the tour of a TSP.
|
---|
| 34 | /// </summary>
|
---|
[2] | 35 | public class TSPTour : ItemBase, IVisualizationItem {
|
---|
[1699] | 36 |
|
---|
| 37 | [Storable]
|
---|
[2] | 38 | private DoubleMatrixData myCoordinates;
|
---|
[884] | 39 | /// <summary>
|
---|
| 40 | /// Gets or sets the coordinates of the current instance.
|
---|
| 41 | /// </summary>
|
---|
[2] | 42 | public DoubleMatrixData Coordinates {
|
---|
| 43 | get { return myCoordinates; }
|
---|
| 44 | set { myCoordinates = value; }
|
---|
| 45 | }
|
---|
[1699] | 46 |
|
---|
| 47 | [Storable]
|
---|
[2] | 48 | private Permutation.Permutation myTour;
|
---|
[884] | 49 | /// <summary>
|
---|
| 50 | /// Gets or sets the current permutation/tour of the current instance.
|
---|
| 51 | /// </summary>
|
---|
[2] | 52 | public Permutation.Permutation Tour {
|
---|
| 53 | get { return myTour; }
|
---|
| 54 | set { myTour = value; }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 |
|
---|
[884] | 58 | /// <summary>
|
---|
| 59 | /// Initializes a new instance of <see cref="TSPTour"/>.
|
---|
| 60 | /// </summary>
|
---|
[2] | 61 | public TSPTour() { }
|
---|
[884] | 62 | /// <summary>
|
---|
| 63 | /// Initializes a new instance of <see cref="TSPTour"/> with the given <paramref name="coordinates"/>
|
---|
| 64 | /// and the given <paramref name="tour"/>.
|
---|
| 65 | /// </summary>
|
---|
| 66 | /// <param name="coordinates">The coordinates of the TSP.</param>
|
---|
| 67 | /// <param name="tour">The tour the current instance should represent.</param>
|
---|
[2] | 68 | public TSPTour(DoubleMatrixData coordinates, Permutation.Permutation tour) {
|
---|
| 69 | myCoordinates = coordinates;
|
---|
| 70 | myTour = tour;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[884] | 73 | /// <summary>
|
---|
| 74 | /// Clones the current instance (deep clone).
|
---|
| 75 | /// </summary>
|
---|
| 76 | /// <remarks>Uses <see cref="Auxiliary.Clone"/> method of class <see cref="Auxiliary"/> to clone
|
---|
| 77 | /// the coordinates.</remarks>
|
---|
| 78 | /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
|
---|
| 79 | /// <returns>The cloned object as <see cref="TSPTour"/>.</returns>
|
---|
[2] | 80 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 81 | TSPTour clone = (TSPTour)base.Clone(clonedObjects);
|
---|
| 82 | clone.myCoordinates = (DoubleMatrixData)Auxiliary.Clone(Coordinates, clonedObjects);
|
---|
| 83 | clone.myTour = Tour;
|
---|
| 84 | return clone;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[884] | 87 | /// <summary>
|
---|
| 88 | /// Creates a new instance of <see cref="TSPTourView"/> to display the current instance.
|
---|
| 89 | /// </summary>
|
---|
| 90 | /// <returns>The created view as <see cref="TSPTourView"/>.</returns>
|
---|
[2] | 91 | public override IView CreateView() {
|
---|
| 92 | return new TSPTourView(this);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[884] | 95 | /// <summary>
|
---|
| 96 | /// Occurs when the coordinates of the current instance have been changed.
|
---|
| 97 | /// </summary>
|
---|
[2] | 98 | public event EventHandler CoordinatesChanged;
|
---|
[884] | 99 | /// <summary>
|
---|
| 100 | /// Fires a new <c>CoordinatesChanged</c> event.
|
---|
| 101 | /// </summary>
|
---|
[2] | 102 | protected virtual void OnCoordinatesChanged() {
|
---|
| 103 | if (CoordinatesChanged != null)
|
---|
| 104 | CoordinatesChanged(this, new EventArgs());
|
---|
| 105 | }
|
---|
[884] | 106 | /// <summary>
|
---|
| 107 | /// Occurs when the tour of the current instance has been changed.
|
---|
| 108 | /// </summary>
|
---|
[2] | 109 | public event EventHandler TourChanged;
|
---|
[884] | 110 | /// <summary>
|
---|
| 111 | /// Fires a new <c>TourChanged</c> event.
|
---|
| 112 | /// </summary>
|
---|
[2] | 113 | protected virtual void OnTourChanged() {
|
---|
| 114 | if (TourChanged != null)
|
---|
| 115 | TourChanged(this, new EventArgs());
|
---|
[1699] | 116 | }
|
---|
[2] | 117 | }
|
---|
| 118 | }
|
---|