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 { if (Cities.Count == 0) return double.MaxValue; return 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(city => city.Id == index); } public Tour() => Cities = new List(); public Tour(Tour tour) : this(tour.Cities) { } public Tour(List cities) => Cities.AddRange(cities.Select(city => new City(city))); public Tour(List cities, List coordinates) => Cities.AddRange(cities.Select(city => new City(city, coordinates[city.Id]))); public override string ToString() => $"tour: {String.Join(" -> ", Cities.Select(city => city.Id))}\n" + $"distance: {Weight}"; } }