using System; using System.Collections.Generic; using System.Linq; using Graph; namespace TSP { using Vertex = Vertex, double>; public class Tour { public List Cities { get; set; } = new List(); public double Weight { get => Cities .Where(city => city.Parent != -1) .Sum(city => city.Key); } // indexer: get vertex where vertex.Id == index public City this[int index] { get => Cities.Find(vertex => vertex.Id == index); } public Tour(List cities) => Cities.AddRange(cities.Select(city => new City(city))); public Tour(List cities) => Cities.AddRange(cities.Select(city => new City(city))); public Tour() => Cities = new List(); public Tour(Tour tour) : this(tour.Cities) { } public override string ToString() => $"tour: {String.Join(" -> ", Cities.Select(city => city.Id))}\n" + $"distance: {Weight}"; } }