From 771a298977d37cd2bca618b3f4ad5b6aaba89405 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Fri, 23 Apr 2021 20:46:50 -0500 Subject: added dialog for plot file location --- src/CS340.TSP/City.cs | 10 ++-------- src/CS340.TSP/TSPSolver.cs | 11 +++++------ 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src/CS340.TSP') diff --git a/src/CS340.TSP/City.cs b/src/CS340.TSP/City.cs index a64439b..460b5cd 100644 --- a/src/CS340.TSP/City.cs +++ b/src/CS340.TSP/City.cs @@ -22,14 +22,8 @@ namespace TSP public City(int id) => Id = id; - public City(int id, List edges) : this(id) - { - foreach (Road edge in edges) - { - Road newEdge = new Road(edge.U, edge.V, edge.Weight); - Edges.Add(newEdge); - } - } + public City(int id, List edges) : this(id) => + Edges = edges; public City(IVertex city) : this(city.Id, city.Edges) => Parent = city.Parent; diff --git a/src/CS340.TSP/TSPSolver.cs b/src/CS340.TSP/TSPSolver.cs index 567c7de..159286a 100644 --- a/src/CS340.TSP/TSPSolver.cs +++ b/src/CS340.TSP/TSPSolver.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Extensions; @@ -74,9 +73,9 @@ namespace TSP static void BruteForce(City cityInput, Tour unvisitedInput, Tour visitedInput) { // create local copy of Tour variables - Tour unvisited = new Tour(unvisitedInput.Cities); - Tour visited = new Tour(visitedInput.Cities); - City city = new City(cityInput); + Tour unvisited = new(unvisitedInput.Cities); + Tour visited = new(visitedInput.Cities); + City city = new(cityInput); // remove current City from tour int removed = unvisited.Cities.RemoveAll(c => c.Id == city.Id); @@ -92,8 +91,8 @@ namespace TSP // add current City to visited visited.Cities.Add(city); - // loop through each city. Each level of recursion has a one less city in currTour.Cities - // leaving the base case + // loop through each city. Each level of recursion has a one less city in unvisited.Cities + // so each loop is (n - 1)! down to n == 0 as the base case foreach (City neighbor in unvisited.Cities) BruteForce(neighbor, unvisited, visited); -- cgit v1.2.3-70-g09d2