summaryrefslogtreecommitdiffstats
path: root/src/CS340.TSP/City.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/CS340.TSP/City.cs')
-rw-r--r--src/CS340.TSP/City.cs57
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