-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16-algorithms-on-graphs.cc
116 lines (110 loc) · 3.44 KB
/
16-algorithms-on-graphs.cc
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
#include <iostream>
#include <limits>
using std::cin;
using std::cout;
using std::endl;
#include "idebug.h"
#include "graphs.h"
int main() {
int part;
cin >> part;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
while(part != -1) {
cout << "Part: " << part << "----------------------------------------";
cout << "--------------------------------" << endl;
switch(part) {
/* ---- 01 ------------------------------------------------------------ */
case 1: {
cout << "EPI: ";
cout << "Maze" << endl;
vector<vector<int>> m;
readMatrix(m);
Maze<int> maze(m);
Maze<int>::MazeCell start{0, 0};
Maze<int>::MazeCell end{(int) m.size()-1, (int) m[m.size()-1].size()-1};
Maze<int>::MazePath path = maze.findPath(start, end);
cout << "Path found = " << (path.size() > 0) << endl;
for_each(path.begin(), path.end(), [](const Maze<int>::MazeCell &p) ->
void {
cout << p.x << ":" << p.y << endl;
});
break;
}
/* ---- 02 ------------------------------------------------------------ */
case 2: {
cout << "EPI: ";
cout << "Production Sequence" << endl;
vector<string> d;
readArray(d);
string s, t;
cin >> s >> t;
ProductionSequence ps(d);
int result = ps.canProduce(s, t);
cout << "Found sequence " << s << " to " << t << " in " << result;
cout << " steps." << endl;
break;
}
/* ---- 03 ------------------------------------------------------------ */
case 3: {
/*
* @MAYBE
*/
cout << "EPI: ";
cout << "Pins and Wires -> Left & Right" << endl;
int nVertices;
cin >> nVertices;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
vector<vector<int>> m;
readMatrix(m);
Graph<int> g(nVertices);
for(int i = 0; i < (int) m.size(); i++) {
g.addEdge(m[i][0], m[i][1]);
}
g.print();
PinsAndWires<int> pnw(g);
bool aligned = pnw.arePinsLeftAndRight();
cout << "Pins are aligned = " << aligned << endl;
break;
}
/* ---- 04 ------------------------------------------------------------ */
case 4: {
cout << "EPI: ";
cout << "Degree of Connectedness" << endl;
int nV;
cin >> nV;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
vector<vector<int>> m;
readMatrix(m);
Graph<int> g(nV);
for(int i = 0; i < (int) m.size(); i++) {
g.addEdge(m[i][0], m[i][1]);
}
g.print();
ConnectivityDegree<int> cd(g);
/*
* @TODO still do not know 2V and 2E connectedness (good terms ?)
*/
bool is2EConnected = cd.is2VerticeConnected();
cout << "Graph is 2E-connected = " << is2EConnected << endl;
bool is2VConnected = cd.is2EdgeConnected();
cout << "Graph is 2V-connected = " << is2VConnected << endl;
break;
}
/* ---- 11 ------------------------------------------------------------ */
case 11: {
/*
* @TODO Learn Floyd-Warshall algorithm for all nodes shortest path
*/
cout << "EPI: ";
cout << "Strongly connected ?" << endl;
vector<vector<int>> m;
readMatrix(m);
break;
}
default: {
break;
}
}
cin >> part;
}
}