25 # ifndef DSGBUILDGRAPH_H 26 # define DSGBUILDGRAPH_H 33 template <
class GT,
class NodeInit,
class ArcInit>
37 class NodeInit = DftNodeInit<GT>,
38 class ArcInit = DftArcInit<GT>>
40 ArcInit && arc_init = ArcInit());
42 template <
class GT,
class NodeInit,
class ArcInit>
44 ArcInit & arc_init,
bool with_diagonal =
true);
47 class NodeInit = DftGridNodeInit<GT>,
48 class ArcInit = DftGridArcInit<GT>>
50 ArcInit && arc_init = ArcInit(),
bool with_diagonal =
true);
52 template <
class GT,
class NodeInit,
class ArcInit>
56 class NodeInit = DftNodeInit<GT>,
57 class ArcInit = DftArcInit<GT>>
59 NodeInit && node_init = NodeInit(),
60 ArcInit && arc_init = ArcInit());
63 class NodeInit = DftNodeInit<GT>,
64 class ArcInit = DftArcInit<GT>>
66 NodeInit && node_init = NodeInit(),
67 ArcInit && arc_init = ArcInit());
69 template <
class GT,
class NodeInit,
class ArcInit>
73 class NodeInit = DftNodeInit<GT>,
74 class ArcInit = DftArcInit<GT>>
76 NodeInit && node_init = NodeInit(),
77 ArcInit && arc_init = ArcInit());
79 template <
class GT,
class NodeInit,
class ArcInit>
83 class NodeInit = DftNodeInit<GT>,
84 class ArcInit = DftArcInit<GT>>
86 NodeInit && node_init = NodeInit(),
87 ArcInit && arc_init = ArcInit());
89 template <
class GT,
class NodeInit,
class ArcInit>
96 for (
nat_t i = 0; i < num_nodes; ++i)
103 for (
nat_t i = 0; i < num_nodes - 1; ++i)
104 for (
nat_t j = i + 1; j < num_nodes; ++j)
108 Arc<GT> * fa = g.insert_arc(s, t);
111 if (not g.is_digraph())
114 Arc<GT> * ba = g.insert_arc(t, s);
121 template <
class GT,
class NodeInit,
class ArcInit>
124 return full_graph<GT, NodeInit, ArcInit>(num_nodes, node_init, arc_init);
127 template <
class GT,
class NodeInit,
class ArcInit>
129 ArcInit & arc_init,
bool with_diagonal)
131 if (width < 2 or height < 2)
132 throw std::length_error(
"The minimun size must be 2 x 2");
138 for (
nat_t i = 0; i < height; ++i)
139 for (
nat_t j = 0; j < width; ++j)
141 mat(i, j) = g.insert_node();
142 node_init(mat(i ,j), i, j);
146 auto a = g.insert_arc(mat(i, j - 1), mat(i, j));
152 auto a = g.insert_arc(mat(i - 1, j), mat(i, j));
160 auto a = g.insert_arc(mat(i - 1, j - 1), mat(i, j));
164 if (i > 0 and j + 1 < width)
166 auto a = g.insert_arc(mat(i - 1, j + 1), mat(i, j));
175 template <
class GT,
class NodeInit,
class ArcInit>
177 ArcInit && arc_init,
bool with_diagonal)
179 return build_grid<GT, NodeInit, ArcInit>
180 (width, height, node_init, arc_init, with_diagonal);
183 template <
class GT,
class NodeInit,
class ArcInit>
185 NodeInit & node_init, ArcInit & arc_init)
193 for (
nat_t i = 0; i < num_nodes; ++i)
200 for (
nat_t i = 0; i < num_arcs; ++i)
208 if (g.search_arc(s, t) !=
nullptr)
211 Arc<GT> * a = g.insert_arc(s, t);
218 template <
class GT,
class NodeInit,
class ArcInit>
220 NodeInit && node_init, ArcInit && arc_init)
222 return random_graph<GT, NodeInit, ArcInit>
223 (num_nodes, num_arcs, seed, node_init, arc_init);
226 template <
class GT,
class NodeInit,
class ArcInit>
228 NodeInit && node_init, ArcInit && arc_init)
230 return random_graph<GT, NodeInit, ArcInit>
234 template <
class GT,
class NodeInit,
class ArcInit>
236 bool grant_connectivity, NodeInit & node_init,
245 for (
nat_t i = 0; i < num_nodes; ++i)
252 for (
nat_t i = 0; i < num_nodes - 1; ++i)
253 for (
nat_t j = i + 1; j < num_nodes; ++j)
256 Arc<GT> * a = g.insert_arc(nodes[i], nodes[j]);
260 if (not grant_connectivity)
268 auto it1 = l.begin();
269 auto it2 = l.begin();
272 for ( ; it2.has_current(); it1.next(), it2.next())
277 Arc<GT> * a = g.insert_arc(l1.get_first(), l2.get_last());
284 template <
class GT,
class NodeInit,
class ArcInit>
286 bool grant_connectivity, NodeInit && node_init,
289 return ps_random_graph<GT, NodeInit, ArcInit>
290 (num_nodes, prob_arc, seed, grant_connectivity, node_init, arc_init);
293 template <
class GT,
class NodeInit,
class ArcInit>
295 NodeInit & node_init, ArcInit & arc_init)
297 return ps_random_graph<GT, NodeInit, ArcInit>
299 node_init, arc_init);
302 template <
class GT,
class NodeInit,
class ArcInit>
304 NodeInit && node_init, ArcInit && arc_init)
306 return p_random_graph<GT, NodeInit, ArcInit>
307 (num_nodes, prob_arc, grant_connectivity, node_init, arc_init);
312 # endif // DSGBUILDGRAPH_H GT build_grid(nat_t width, nat_t height, NodeInit &node_init, ArcInit &arc_init, bool with_diagonal=true)
Definition: buildgraph.H:128
T random_uniform(rng_t &, T)
Definition: random.H:54
double real_t
Definition: types.H:51
nat_t size() const
Definition: array.H:271
GT full_graph(nat_t, NodeInit &, ArcInit &)
Definition: buildgraph.H:90
GT p_random_graph(nat_t, real_t, bool, NodeInit &, ArcInit &)
Definition: buildgraph.H:294
std::mt19937_64 rng_t
Definition: types.H:52
rng_t::result_type rng_seed_t
Definition: types.H:53
rng_seed_t get_random_seed()
typename GT::Node Node
Definition: graphutilities.H:78
SLList< SLList< Node< GT > * > > connected_components_node_list(const GT &)
Definition: graphalgorithms.H:499
GT ps_random_graph(nat_t, real_t, rng_seed_t, bool, NodeInit &, ArcInit &)
Definition: buildgraph.H:235
GT random_graph(nat_t, nat_t, rng_seed_t, NodeInit &, ArcInit &)
Definition: buildgraph.H:184
unsigned long int nat_t
Definition: types.H:50
bool random_Bernoulli(rng_t &, real_t p=DEFAULT_P)
typename GT::Arc Arc
Definition: graphutilities.H:79