14#include <boost/graph/adjacency_list.hpp>
15#include <boost/graph/connected_components.hpp>
16#include <boost/graph/filtered_graph.hpp>
29using Traits = adjacency_list_traits<vecS, vecS, undirectedS>;
42 vecS, vecS, undirectedS, property<vertex_name_t, Traits::vertex_descriptor>,
43 property<edge_index_t, int, property<edge_weight_t, long>>>;
45using Vertex = graph_traits<Graph>::vertex_descriptor;
46using Edge = graph_traits<Graph>::edge_descriptor;
55using FlowTraits = adjacency_list_traits<vecS, vecS, directedS>;
67 vecS, vecS, directedS, no_property,
68 property<edge_capacity_t, long,
69 property<edge_residual_capacity_t, long, property<edge_reverse_t, FlowTraits::edge_descriptor>>>>;
82 std::map<Vertex, Vertex> local_to_global;
83 std::map<Vertex, Vertex> global_to_local;
85 for (std::size_t i = 0; i < v.size(); ++i) {
86 Vertex v_new = add_vertex(get(vertex_name, g, v[i]), sg);
87 local_to_global.insert({v_new, v[i]});
88 global_to_local.insert({v[i], v_new});
91 typename graph_traits<G>::vertex_iterator vi, vi_end;
92 for (boost::tie(vi, vi_end) = vertices(sg); vi != vi_end; ++vi) {
93 Vertex vv = local_to_global[*vi];
94 typename graph_traits<G>::out_edge_iterator ei, ei_end;
95 for (boost::tie(ei, ei_end) = out_edges(vv, g); ei != ei_end; ++ei) {
96 Vertex uu = target(*ei, g);
97 auto u = global_to_local.find(uu);
98 if (u != global_to_local.end() && !edge(*vi, u->second, sg).second) {
99 add_edge(*vi, u->second, sg);
110 std::vector<Graph> components;
112 std::vector<int> component(num_vertices(g));
113 int num_components = connected_components(g, &component[0]);
115 std::vector<std::vector<Vertex>> component_v(num_components);
117 typename graph_traits<G>::vertex_iterator vi, vi_end;
118 for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi, ++i) {
119 component_v[component[i]].push_back(*vi);
122 for (
const auto& vs : component_v) {
123 components.push_back(
subgraph(g, vs));
143 filtered_graph<Graph, NonCriticalEdge> fg(g, filter);
167 std::set<std::pair<typename graph_traits<G>::vertex_descriptor,
typename graph_traits<G>::vertex_descriptor>>
169 typename graph_traits<G>::edge_iterator ei, ei_end;
170 for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
171 auto u = source(*ei, g);
172 auto v = target(*ei, g);
179 if (!seen.insert({u, v}).second) {
193 for (
int i = 0; i < n; ++i) {
194 add_edge(i, (i + 1) % n, g);
196 add_edge(1, n - 1, g);
203 for (
int i = 0; i < n - 1; ++i) {
204 for (
int j = i + 1; j < n; ++j) {
214 for (
int i = 0; i < n - 1; ++i) {
215 add_edge(i, (i + 1) % (n - 1), g);
216 add_edge(i, n - 1, g);
226 const int n = (n_layers * (n_layers + 1)) / 2;
230 for (
int i = 1; i < n_layers; ++i) {
231 int prev_offset = offset;
233 for (
int src_i = 0; src_i < i + 1; ++src_i) {
234 for (
int tgt_i = 0; tgt_i < i; ++tgt_i) {
235 add_edge(src_i + offset, tgt_i + prev_offset, g);
246 for (
int i = 0; i < n - 2; ++i) {
247 for (
int j = i + 1; j < n - 1; ++j) {
248 add_edge(i + 1, j + 1, g);
258 int n = num_vertices(g);
262 for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
263 Vertex u = perm[source(*ei, g)], v = perm[target(*ei, g)];
284 std::default_random_engine rg(seed);
287 std::uniform_real_distribution<double> distribution(0.0, 1.0);
288 for (
int i = 0; i < n - 1; ++i) {
289 for (
int j = i + 1; j < n; ++j) {
290 if (distribution(rg) < p) {
301 std::default_random_engine rg(seed);
304 std::uniform_real_distribution<double> distribution(0.0, 1.0);
305 std::vector<double> x(n), y(n);
306 for (
int i = 0; i < n; ++i) {
307 x[i] = distribution(rg);
308 y[i] = distribution(rg);
311 for (
int i = 0; i < n; ++i) {
312 for (
int j = i + 1; j < n; ++j) {
313 double d = std::sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
Definition cunningham.hpp:50
Graph random_gnp_graph(int n, double p, int seed)
An Erdos-Renyi G(n,p) random graph.
Definition graphs.hpp:283
adjacency_list< vecS, vecS, undirectedS, property< vertex_name_t, Traits::vertex_descriptor >, property< edge_index_t, int, property< edge_weight_t, long > > > Graph
The undirected graph type used throughout this library.
Definition graphs.hpp:43
bool is_simple_graph(const G &g)
Checks whether g is a simple graph: no self-loops, no parallel edges between the same pair of vertice...
Definition graphs.hpp:166
Graph wheel_graph(int n)
The wheel graph: a cycle on n-1 vertices plus one hub vertex n-1.
Definition graphs.hpp:212
Graph complete_graph(int n)
The complete graph on n vertices.
Definition graphs.hpp:201
adjacency_list< vecS, vecS, directedS, no_property, property< edge_capacity_t, long, property< edge_residual_capacity_t, long, property< edge_reverse_t, FlowTraits::edge_descriptor > > > > FlowGraph
The directed, capacitated graph type used for the max-flow subproblem in Cunningham's algorithm (see ...
Definition graphs.hpp:69
std::vector< Graph > connected_component_graphs(const G &g)
Splits g into one Graph per connected component.
Definition graphs.hpp:109
std::vector< Graph > induced_components(Graph &g, const std::set< Edge > &A)
Splits g into connected components after removing the critical edge set A.
Definition graphs.hpp:141
Graph cycle_plus_triangle(int n)
A cycle on n vertices plus one extra chord (between vertices 1 and n-1).
Definition graphs.hpp:191
adjacency_list_traits< vecS, vecS, undirectedS > Traits
Traits for Graph.
Definition graphs.hpp:29
FlowTraits::vertex_descriptor FlowVertex
Definition graphs.hpp:56
Graph subgraph(const G &g, std::vector< Vertex > v)
Builds the subgraph of g induced by the given vertices.
Definition graphs.hpp:79
graph_traits< Graph >::edge_descriptor Edge
Definition graphs.hpp:46
FlowTraits::edge_descriptor FlowEdge
Definition graphs.hpp:57
graph_traits< Graph >::vertex_iterator VertexIterator
Definition graphs.hpp:47
graph_traits< Graph >::vertex_descriptor Vertex
Definition graphs.hpp:45
graph_traits< Graph >::edge_iterator EdgeIterator
Definition graphs.hpp:48
Graph growing_multipartite(int n_layers)
A multipartite graph with growing layer sizes (1, 2, ..., n_layers) and complete bipartite connection...
Definition graphs.hpp:225
Graph permuted_graph(const Graph &g, const std::vector< int > &perm)
g with vertices relabeled according to perm.
Definition graphs.hpp:257
Graph random_geometric_graph(int n, double r, int seed=381928)
A random geometric graph: n uniform points in the unit square, connected within radius r.
Definition graphs.hpp:300
Graph disconnected_graph()
Two disjoint triangles: a minimal example of a disconnected graph.
Definition graphs.hpp:271
Graph complete_plus_triangle(int n)
The complete graph on n-1 vertices, plus one extra vertex attached to two of them.
Definition graphs.hpp:244
adjacency_list_traits< vecS, vecS, directedS > FlowTraits
Traits for FlowGraph.
Definition graphs.hpp:55
Edge filter selecting edges not in a given critical/tight set.
Definition graphs.hpp:130
NonCriticalEdge(std::set< Edge > a)
Definition graphs.hpp:132
NonCriticalEdge()=default
bool operator()(const Edge &e) const
Definition graphs.hpp:133
std::set< Edge > m_A
Definition graphs.hpp:134