-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalc_graph.cpp
84 lines (67 loc) · 1.99 KB
/
calc_graph.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
#include "graph.h"
using std::string;
Graph1 *create() {
//string graph_name = 'g'+std::to_string(counter++);
Graph1 *g1 = new Graph1;
return g1;
}
void destroy(Graph1 &graph) {
delete &graph;
}
Graph1 &addVertex(Graph1 &graph, const char* vertex) {
graph.addVertex(string(vertex));
return graph;
}
Graph1 &addVertex(Graph1 &graph, string vertex) {
graph.addVertex(vertex);
return graph;
}
Graph1 &addEdge(Graph1 &graph, string vertex1, string vertex2) {
if (!Vertex::checkVertexName(vertex1) || !Vertex::checkVertexName(vertex2)){
throw WrongVertexName();
}
if (!graph.isContain(vertex1) || !graph.isContain(vertex2)){
throw ArgumentNotFound();
}
std::pair<string, string> edge;
edge.first =vertex1;
edge.second = vertex2;
graph.addEdge(edge);
return graph;
}
Graph1& addEdge(Graph1& graph, const char* vertex1, const char* vertex2) {
if (!Vertex::checkVertexName(vertex1) || !Vertex::checkVertexName(vertex2)){
throw WrongVertexName();
}
if (!graph.isContain(vertex1) || !graph.isContain(vertex2)){
throw ArgumentNotFound();
}
std::pair<string, string> edge;
edge.first =vertex1;
edge.second = vertex2;
graph.addEdge(edge);
return graph;
}
void disp(Graph1 &graph) {
std::cout << graph;
}
Graph1 &graphUnion(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1 + graph_in2;
return graph_out;
}
Graph1 &graphIntersection(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1 ^ graph_in2;
return graph_out;
}
Graph1 &graphDifference(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1 - graph_in2;
return graph_out;
}
Graph1 &graphProduct(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1*graph_in2;
return graph_out;
}
Graph1 &graphComplement(Graph1 &graph_in, Graph1 &graph_out) {
graph_out = !graph_in;
return graph_out;
}