-
Notifications
You must be signed in to change notification settings - Fork 0
/
knot.cc
110 lines (95 loc) · 2.36 KB
/
knot.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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <cstdlib>
using std::cerr;
using std::cout;
using std::endl;
using std::ifstream;
using std::pair;
using std::string;
using std::istringstream;
using std::vector;
struct Edge;
struct Vertex
{
Vertex(string str) : name(str) {;}
string name;
vector<Edge*> e;
};
struct Edge
{
Edge(Vertex *a, Vertex *b) : first(a), second(b) {;}
Vertex *first;
Vertex *second;
};
struct Graph
{
vector<Vertex *> v;
vector<Edge *> e;
Vertex *findVertex(const string str)
{
vector<Vector *>::const_itr vitr;
for (vitr=v.begin(); vitr!=v.end(); ++vitr)
if ((*vitr)->name == str)
return *vitr;
}
return new Vertex(str);
};
// Transform a planar graph into a knot:
// https://en.wikipedia.org/wiki/Knots_and_graphs#Medial_graph
static void to_knot(const Graph &g)
{
// (0) For each vertex of G
vector<Vertex*>::const_iterator vitr;
for (vitr=g.v.begin(); vitr!=g.v.end(); ++vitr)
{
Vertex *v = *vitr;
vector<Edge*>::const_iterator eitr;
for (eitr=v->e.begin(); eitr!=v->e.end(); ++eitr)
{
// (1) Create set of incident egdes (and their corresponding vertex)
// to the vertex.
// vitr..e are the incident edges
incidents.push_back
}
}
/* 2) For each set in 1) If any of the verticies making up the edges in the
* set also share an edge with the verticies making up edges in another set
* (also created in 1)) then we have an intersection.
*/
}
int main(int argc, char **argv)
{
if (argc != 2) {
cerr << "Usage: " << argv[0] << endl;
exit(EXIT_FAILURE);
}
ifstream in(argv[1]);
if (!in.is_open())
{
cerr << "Could not open input file" << endl;
exit(EXIT_FAILURE);
}
Graph graph;
while (in.good())
{
string a, b;
in >> a >> b;
if (!a.length())
break;
a.pop_back();
Vertex *caller = g.findVertex(a);
Vertex *callee = g.findVertex(b);
Edge *edge = new Edge(caller, callee);
caller->e.push_back(edge);
callee->e.push_back(edge);
graph.v.push_back(caller);
graph.v.push_back(callee);
}
to_knot(graph);
in.close();
return 0;
}