diff options
Diffstat (limited to 'src/CS340.TSP')
-rw-r--r-- | src/CS340.TSP/City.cs | 25 | ||||
-rw-r--r-- | src/CS340.TSP/Road.cs | 27 |
2 files changed, 9 insertions, 43 deletions
diff --git a/src/CS340.TSP/City.cs b/src/CS340.TSP/City.cs index 1a38e2c..eaf4ef3 100644 --- a/src/CS340.TSP/City.cs +++ b/src/CS340.TSP/City.cs @@ -6,8 +6,11 @@ using Interfaces; namespace TSP { + using INode = INode<double>; + using IVertex = IVertex<Edge<double>, double>; + using Road = Edge<double>; - public class City : IVertex<Road, double>, IComparable<INode<double>> + public class City : IVertex, IComparable<INode> { public int Id { get; set; } public double Key { get => this[Parent].Weight; set => Key = value; } @@ -26,28 +29,18 @@ namespace TSP public City(int id, List<Road> edges) : this(id) => Edges = edges; - public City(City vertex) + public City(IVertex city) { - Id = vertex.Id; - Parent = vertex.Parent; - 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; - foreach (Edge<double> edge in vertex.Edges) + Id = city.Id; + Parent = city.Parent; + foreach (Road edge in city.Edges) { Road newEdge = new Road(edge.U, edge.V, edge.Weight); Edges.Add(newEdge); } } - public int CompareTo(INode<double> node) => + public int CompareTo(INode node) => Key.CompareTo(node.Key); public override string ToString() => $"{Id} {String.Join(" ", Edges.Select(e => (e.V, e.Weight)))}"; diff --git a/src/CS340.TSP/Road.cs b/src/CS340.TSP/Road.cs deleted file mode 100644 index cc939e9..0000000 --- a/src/CS340.TSP/Road.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Interfaces; - -namespace TSP -{ - using IEdge = IEdge<double>; - public class Road : IEdge, IComparable<IEdge> - { - public int U { get; set; } - public int V { get; set; } - public double Weight { get; set; } - - public Road() { } - - public Road(int u, int v, double weight) - { - U = u; - V = v; - Weight = weight; - } - - public int CompareTo(IEdge edge) => - Weight.CompareTo(edge.Weight); - - public override string ToString() => $"{U} {V} {Weight}"; - } -} |