From 292555a07b72ae1470c49ee2cee82db16d1c9cbd Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Thu, 22 Apr 2021 01:08:33 -0500 Subject: added more generics --- src/CS340.TSP/City.cs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/CS340.TSP/City.cs (limited to 'src/CS340.TSP/City.cs') 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, IComparable> + { + public int Id { get; set; } + public double Key { get; set; } + + public int Parent { get; set; } = -1; + public List Edges { get; set; } = new List(); + + // 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 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, double> vertex) + { + Id = vertex.Id; + Parent = vertex.Parent; + Key = vertex.Key; + foreach (Edge edge in vertex.Edges) + { + Road newEdge = new Road(edge.U, edge.V, edge.Weight); + Edges.Add(newEdge); + } + } + + public int CompareTo(INode 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 -- cgit v1.2.3-70-g09d2