blob: 27ab5a505f9fb435ca6a7af72740c9e195e77ba8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using System;
using System.Collections.Generic;
using System.Linq;
using Graph;
namespace TSP
{
using Vertex = Vertex<Edge<double>, double>;
public class Tour
{
public List<City> Cities { get; set; } = new List<City>();
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(city => city.Id == index); }
public Tour() =>
Cities = new List<City>();
public Tour(Tour tour) : this(tour.Cities) { }
public Tour(List<City> cities) =>
Cities.AddRange(cities.Select(city => new City(city)));
public Tour(List<Vertex> cities, List<Coordinate> 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}";
}
}
|