diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-04-22 01:08:33 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-04-22 01:08:33 -0500 |
commit | 292555a07b72ae1470c49ee2cee82db16d1c9cbd (patch) | |
tree | 21418f63624c37befaa34f57886d47b4a9824a8c /src/CS340.TSP/City.cs | |
parent | d2dea1b16ff29f6e45fca971290f94d4e0ed2467 (diff) |
added more generics
Diffstat (limited to 'src/CS340.TSP/City.cs')
-rw-r--r-- | src/CS340.TSP/City.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/CS340.TSP/City.cs b/src/CS340.TSP/City.cs new file mode 100644 index 0000000..1990094 --- /dev/null +++ b/src/CS340.TSP/City.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Graph; +using Interfaces; + +namespace TSP +{ + + public class City : IVertex<Road, double>, IComparable<INode<double>> + { + public int Id { get; set; } + public double Key { get; set; } + + public int Parent { get; set; } = -1; + public List<Road> Edges { get; set; } = new List<Road>(); + + // indexer for accessing edge with v of index + public Road this[int index] { get => Edges.Find(edge => edge.V == index); } + + public City() { } + + public City(int id) => + Id = id; + + public City(int id, List<Road> edges) : this(id) => + Edges = edges; + + public City(City vertex) + { + Id = vertex.Id; + Parent = vertex.Parent; + Key = vertex.Key; + foreach (Road edge in vertex.Edges) + { + Road newEdge = new Road(edge.U, edge.V, edge.Weight); + Edges.Add(newEdge); + } + } + public City(Vertex<Edge<double>, double> vertex) + { + Id = vertex.Id; + Parent = vertex.Parent; + Key = vertex.Key; + foreach (Edge<double> edge in vertex.Edges) + { + Road newEdge = new Road(edge.U, edge.V, edge.Weight); + Edges.Add(newEdge); + } + } + + public int CompareTo(INode<double> node) => + Key.CompareTo(node.Key); + + public override string ToString() => $"{Id} {String.Join(" ", Edges.Select(e => (e.V, e.Weight)))}"; + } +}
\ No newline at end of file |