-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
192 lines (152 loc) · 4.27 KB
/
main.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <iostream>
#include <fstream>
#include <sstream>
#include "Graph.h"
using namespace std;
struct runStore {
int endId;
int parentId;
difficulty diff;
int length;
};
void outVector(vector<converge> v) {
for (int i = v.size() - 1; i >= 0; i--) {
cout << v[i].id << ",";
}
cout << endl << "===============" << endl;
}
difficulty convertStringToEnum(string str) {
difficulty diff;
if (str == "green") {
diff = green;
}
else if (str == "blue") {
diff = blue;
}
else if (str == "black") {
diff = black;
}
else if (str == "double_black") {
diff = double_black;
}
else if (str == "chair") {
diff = chair;
}
return diff;
}
void testAddConvergeRun() {
Graph *g = new Graph();
g->insertConverge(0);
g->insertConverge(1);
g->addRun(0, 1, black, 750);
}
void testDijkstras(Graph *g) {
outVector(g->getDistanceBetween(0, 12));
outVector(g->getDistanceBetween(0, 2));
outVector(g->getDistanceBetween(0, 4));
outVector(g->getDistanceBetween(0, 10));
}
void testMaxFlow(Graph *g) {
cout << "From 3 to 0" << endl;
cout << g->getMaxFlow(0, 4) << endl;
cout << "From 0 to 3" << endl;
cout << g->getMaxFlow(0, 3) << endl;
}
void buildGraph(Graph *g, string filePath) {
ifstream dataFile(filePath);
vector<runStore*> runs;
if (dataFile.is_open()) {
string line;
while(getline(dataFile, line)) {
stringstream ss;
ss << line;
string idStr;
ss >> idStr;
g->insertConverge(stoi(idStr));
string subLine;
while(getline(ss, subLine, ',')) {
stringstream ss1;
ss1 << subLine;
string endIdStr;
getline(ss1, endIdStr, '-');
string diffStr;
getline(ss1, diffStr, '-');
string lengthStr;
getline(ss1, lengthStr, '-');
runStore *rs = new runStore();
rs->parentId = stoi(idStr);
rs->endId = stoi(endIdStr);
rs->diff = convertStringToEnum(diffStr);
rs->length = stoi(lengthStr);
runs.push_back(rs);
}
}
for (int i = 0; i < runs.size(); i++) {
g->addRun(runs[i]->parentId, runs[i]->endId, runs[i]->diff, runs[i]->length);
}
dataFile.close();
}
else {
cout << "was unable to open the file" << endl;
}
}
void getMaxFlow(Graph *g) {
cout << "Enter a source node" << endl;
string str1;
getline(cin, str1);
cout << "Enter a sink node" << endl;
string str2;
getline(cin, str2);
cout << g->getMaxFlow(stoi(str1), stoi(str2)) << endl;
}
int main() {
try {
testAddConvergeRun();
}
catch(...) {
cout << "test 1 failed" << endl;
}
Graph *g = new Graph();
string filePath = "";
//buildGraph(g, "/home/kieran/Documents/CSCI2275/FinalProject2275/stevens_pass_nodes");
//testMaxFlow(g);
bool isContinue = true;
while(isContinue) {
cout << "=== Menu ===" << endl;
cout << "1. Build Graph" << endl;
cout << "2. Get Max Flow" << endl;
cout << "3. Get shortest distance" << endl;
cout << "4. Quit" << endl;
cout << "5. Test Dijkstras" << endl;
cout << "6. Test max flow" << endl;
string choiceStr;
getline(cin, choiceStr);
int choice = stoi(choiceStr);
switch(choice) {
case 1: {
cout << "Enter in the file path or press enter to use default:" << endl;
getline(cin, filePath);
if (filePath == "") {
filePath = "/home/kieran/Documents/CSCI2275/FinalProject2275/stevens_pass_nodes";
}
buildGraph(g, filePath);
}
break;
case 2:
getMaxFlow(g);
break;
case 3:
break;
case 4:
isContinue = false;
break;
case 5:
testDijkstras(g);
break;
case 6:
testMaxFlow(g);
break;
}
}
return 0;
}