diff options
Diffstat (limited to 'src/CS340.TSP/Tour.cs')
-rw-r--r-- | src/CS340.TSP/Tour.cs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/CS340.TSP/Tour.cs b/src/CS340.TSP/Tour.cs index 456c944..80db19d 100644 --- a/src/CS340.TSP/Tour.cs +++ b/src/CS340.TSP/Tour.cs @@ -26,18 +26,14 @@ namespace TSP // indexer: get vertex where vertex.Id == index public Vertex<T> this[int index] { get => Cities.Find(vertex => vertex.Id == index); } - public Tour(List<Vertex<T>> cities) => Cities = cities; + public Tour(List<Vertex<T>> cities) => Cities.AddRange(cities.Select(city => new Vertex<T>(city))); public Tour() => Cities = new List<Vertex<T>>(); + public Tour(Tour<T> tour) : this(tour.Cities) { } + - public Tour<T> DeepCopy() - { - Tour<T> other = (Tour<T>)this.MemberwiseClone(); - other.Cities = Cities.ConvertAll(city => city.DeepCopy()); - return other; - } public override string ToString() => - $"tour: {String.Join(" -> ", Cities.Select(city => city.Id))}\n" + - $"distance: {Weight}"; + $"tour: {String.Join(" -> ", Cities.Select(city => city.Id))}\n" + + $"distance: {Weight}"; } } |