-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
194 lines (157 loc) · 7.03 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
193
194
#include <iostream>
#include <cstdlib>
#include <filesystem>
#include "graph.hpp"
#include "bfs_dfs.hpp"
#include "utility.hpp"
int main(int argc, char* argv[]) {
// argc: Number of command-line args
// argv: Array of command-line args
// Ensure the "dot" directory exists
std::filesystem::create_directories("dot");
// Counter for output files
int file_counter = 0;
// Order of diagrams
int order = 0;
if (argc > 1) {
order = std::atoi(argv[1]);
} else {
std::cout << "Order is not specified." << std::endl;
return 1;
}
// Limit of order
if (order > 2) {
std::cout << "Please specify the order as 1 or 2." << std::endl;
return 1;
}
int max_of_vertices = 2 * order;
// flag for ignoring diagrams with fermion-loop
bool ignore_fermion_loop = true;
std::vector<SimpleGraph> unique_graphs;
for (int number_of_vertices = 1; number_of_vertices < max_of_vertices + 1; ++number_of_vertices) {
// Create all possible edges
std::vector<std::pair<int, int>> all_edges;
for (int i = 0; i < number_of_vertices; ++i) {
for (int j = i; j < number_of_vertices; ++j) {
all_edges.push_back({i, j});
}
}
// Generate all combinations of order edges
auto all_dashed_combinations = combinations(all_edges, order);
for (const auto& dashed_edges : all_dashed_combinations) {
auto all_solid_combinations = combinations(all_edges, number_of_vertices - 1);
for (const auto& solid_edges : all_solid_combinations) {
// Initialize graph
std::tuple<SimpleGraph, std::vector<SimpleGraph::vertex_descriptor>> result = get_initial_graph_and_vertices(number_of_vertices);
SimpleGraph G;
std::vector<SimpleGraph::vertex_descriptor> vertices;
std::tie(G, vertices) = result;
// Initialize graph_is_correct flag
bool graph_is_correct = true;
// Add dashed edges
for (const auto& dashed_edge : dashed_edges) {
auto e = add_edge(vertices[dashed_edge.first], vertices[dashed_edge.second], G).first;
G[vertices[dashed_edge.first]].dashed_degree++;
G[vertices[dashed_edge.second]].dashed_degree++;
if (dashed_edge.first == dashed_edge.second) {
G[vertices[dashed_edge.first]].dashed_loop = true;
}
G[e].style = "dashed";
}
// Add solid edges
for (const auto& solid_edge : solid_edges) {
auto e = add_edge(vertices[solid_edge.first], vertices[solid_edge.second], G).first;
G[vertices[solid_edge.first]].solid_degree++;
G[vertices[solid_edge.second]].solid_degree++;
if (solid_edge.first == solid_edge.second) {
G[vertices[solid_edge.first]].solid_loop = true;
}
G[e].style = "solid";
}
// Perform DFS to find all vertices connected to vertices[0]
auto reachable_from_initial = dfs_reachable_vertices(G, vertices[0]);
for (const auto& v : vertices) {
if (reachable_from_initial.find(v) == reachable_from_initial.end()) {
graph_is_correct = false;
break;
}
}
if (!graph_is_correct) {
continue;
}
// Check shape of graph
int count_initial_and_final_vertices = 0;
int count_same_initial_and_final_vertices = 0;
int count_intermediate_vertices = 0;
int initial_is_found = false;
for (const auto& v : vertices) {
if (G[v].solid_degree == 1) {
if (count_initial_and_final_vertices == 0) {
G[v].fillcolor = "red";
G[v].initial = true;
} else if (count_initial_and_final_vertices == 1) {
G[v].fillcolor = "blue";
G[v].final = true;
}
count_initial_and_final_vertices += 1;
} else if (G[v].solid_degree == 2) {
count_intermediate_vertices += 1;
} else if (G[v].solid_degree == 0) {
G[v].fillcolor = "red";
G[v].initial = true;
G[v].final = true;
count_same_initial_and_final_vertices += 1;
} else {
graph_is_correct = false;
break;
}
if (G[v].dashed_degree == 0) {
graph_is_correct = false;
break;
}
if (G[v].solid_loop && ignore_fermion_loop) {
graph_is_correct = false;
break;
}
}
if (!graph_is_correct) {
continue;
}
if (count_same_initial_and_final_vertices == 0) {
if (count_initial_and_final_vertices + count_intermediate_vertices != vertices.size() || count_initial_and_final_vertices > 2) {
continue;
}
} else if (count_same_initial_and_final_vertices == 1) {
if (count_same_initial_and_final_vertices + count_intermediate_vertices != vertices.size() || count_initial_and_final_vertices != 0) {
continue;
}
} else {
continue;
}
// Labeling
for (const auto& v : vertices) {
int d = G[v].dashed_degree;
G[v].label = std::to_string(d);
}
bool is_duplicate = false;
for (const auto& existing_graph : unique_graphs) {
if (are_graphs_isomorphic(G, existing_graph)) {
is_duplicate = true;
break;
}
}
if (!is_duplicate) {
unique_graphs.push_back(G);
// Add short slanted lines to initial and final vertices
add_short_slanted_lines(G, vertices);
// Align graph
// align_vertices(G, vertices, 3.0, 3.0);
// Write graph
std::ofstream file("dot/graph_" + std::to_string(file_counter++) + ".dot");
boost::write_graphviz(file, G, vertex_writer(G), edge_writer(G), graph_writer());
}
}
}
}
return 0;
}