Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ Title: main.cpp
Description: main method for our Christofides implementation
Authors: Sean Hinds, Ryan Hong, Jeff Herlitz
Date: 08/16/17

Changes:
- cities coordinate changed from int to double
- removed useless path_vals
*************************************************************************/

#include <iostream>
#include <climits>
#include "tsp.h"
//#include "twoOpt.h"

Expand Down Expand Up @@ -39,19 +42,16 @@ int main(int argc, char** argv) {
cout << "Matching completed" << endl;

// Loop through each index and find shortest path
int best = INT_MAX;
int bestIndex;
TSP::distance_t best = TSP::DINF;
int bestIndex = -1;
for (long t = 0; t < tsp_size; t++) {
int result = tsp.findBestPath(t);

tsp.path_vals[t][0] = t; // set start
tsp.path_vals[t][1] = result; // set end

if (tsp.path_vals[t][1] < best) {
bestIndex = tsp.path_vals[t][0];
best = tsp.path_vals[t][1];
TSP::distance_t result = tsp.findBestPath(t);
if (result < best) {
bestIndex = t;
best = result;
}
}
cout << "BestPath completed " << bestIndex << endl;

//Create path for best tour
tsp.euler_tour(bestIndex,tsp.circuit);
Expand Down
29 changes: 17 additions & 12 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
cc=g++
cflags=-c -std=c++11

all: driver

driver: main.cpp tsp.cpp tsp.h
g++ main.cpp tsp.cpp -o tsp

clean:
rm -f a.out
rm -f *.o
rm -f driver

inp ?= gpx

all: tsp

tsp: main.cpp tsp.cpp tsp.h
g++ -std=c++11 -Wall -O2 main.cpp tsp.cpp -o $@

clean:
rm -f a.out
rm -f *.o
rm -f tsp

test: tsp
./tsp $(inp)
gnuplot -e "plot '$(inp).tour' using 2:3 with lines" -

Loading