forked from guillaumeportails/Christofides_Algorithm_Cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsp.h
111 lines (77 loc) · 1.77 KB
/
tsp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*************************************************************************
Title: TSP.hpp
Description: TSP class specification file for our Christofides implementation
Authors: Sean Hinds, Ryan Hong, Jeff Herlitz
Date: 08/16/17
Changes:
- cities coordinates changed from int to double
- removed unused members
*************************************************************************/
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;
#ifndef TSP_H
#define TSP_H
class TSP
{
private:
struct City{
double x;
double y;
};
string iFile;
string oFile;
// List of odd nodes
vector<int>odds;
//Adjacency list
vector<int> *adjList;
void findOdds();
protected:
public:
// Number of cities
int n;
//Shortest path length
int pathLength;
//euler circuit
vector<int> circuit;
vector<City> cities;
// n x n, pairwise distances between cities
typedef double distance_t;
distance_t **graph;
static distance_t const DINF;
vector<int>* adjlist;
// Constructor
TSP(string in, string out);
// Destructor
~TSP();
distance_t get_distance(struct City c1, struct City c2);
//Find perfect matching
void perfectMatching();
//Find Euler tour
void euler_tour(int start, vector<int> &path);
//Find Hamiltonian path
void make_hamiltonian(vector<int> &path, int &pathCost);
// Prim's algorithm
void findMST();
int getMinIndex(distance_t key[], bool mst[]);
void printResult();
void printPath();
void printEuler();
void printAdjList();
void printCities();
int get_size(){return n;};
void fillMatrix();
int findBestPath(int start);
};
#endif