|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Random undirected graph generator. More...
#include <random_graph.H>
Private Types | |
| typedef GT::Node | GT_Node |
| typedef GT::Arc | GT_Arc |
Private Member Functions | |
| virtual void | update_parity_after_arc_insertion (GT_Node *src, GT_Node *tgt) |
| void | create_nodes_and_initialize_arc_index () override |
| void | connect () override |
| GT | create_p (const size_t &__num_nodes, const double &p, const bool connected) override |
| void | make_eulerian () override |
| void | balance_graph_nodes_degree (GT_Node *src, GT_Node *tgt) |
| void | make_hamiltonian () override |
Private Attributes | |
| DynSetRandTree< GT_Node * > | odd_nodes |
| DynSetRandTree< GT_Node * > | even_nodes |
Random undirected graph generator.
Random_Graph is a class for generating random undirected graphs with a specified number of nodes and, depending on the invoked operation, a specified number of arcs or arc probability.
The class exports two generation methods via the function-call operator, intended for generating sparse and dense graphs respectively.
For this class to compile, GT::Node_Type and GT::Arc_Type must have default constructors.
Template parameters:
The Init_Node class must have the following structure:
The Init_Arc class must have the following structure:
The generation routines include a boolean parameter that determines whether the graph should be connected. By default, this parameter is true. Consider setting it to false if connectivity is not required, since ensuring connectivity requires computing connected components, which adds time and memory overhead.
Definition at line 368 of file random_graph.H.
|
private |
Definition at line 371 of file random_graph.H.
|
private |
Definition at line 370 of file random_graph.H.
|
inline |
Constructor.
| [in] | seed | Seed for the random number generator. |
| [in] | __init_node | Node initialization functor. |
| [in] | __init_arc | Arc initialization functor. |
Definition at line 485 of file random_graph.H.
References ah_domain_error_if, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, and GraphCommon< GT, Node, Arc >::is_digraph().
|
inline |
Definition at line 494 of file random_graph.H.
References ah_domain_error_if, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, and GraphCommon< GT, Node, Arc >::is_digraph().
|
inlineprivate |
Definition at line 595 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_arcs(), GraphCommon< GT, Node, Arc >::get_num_nodes(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::idx_arc, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::insert_arc(), Aleph::maps(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::nodes, and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::r.
Referenced by Aleph::Random_Graph< GT, Init_Node, Init_Arc >::make_hamiltonian().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 426 of file random_graph.H.
References Aleph::DynList< T >::append(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::insert_arc(), Aleph::maps(), and Aleph::HTList::size().
Referenced by Aleph::Random_Graph< GT, Init_Node, Init_Arc >::create_p().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 404 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::idx_arc, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::init_node, Aleph::DynSetTree< Key, Tree, Compare >::insert(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), Aleph::maps(), NODE_COUNTER, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::nodes, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::num_nodes, and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::save_parity.
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 453 of file random_graph.H.
References ah_domain_error_if, Aleph::Random_Graph< GT, Init_Node, Init_Arc >::connect(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::initialize_and_create_nodes(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::insert_arc(), Aleph::maps(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::nodes, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::num_nodes, and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::r.
Referenced by Aleph::Random_Graph< GT, Init_Node, Init_Arc >::eulerian(), Aleph::Random_Graph< GT, Init_Node, Init_Arc >::operator()(), and Aleph::Random_Graph< GT, Init_Node, Init_Arc >::sufficient_hamiltonian().
|
inline |
Create a random Eulerian graph (dense version).
This version builds a random Eulerian graph with probability p of an arc existing between any pair of nodes.
Use this routine to generate dense graphs. In this case, use a value of p greater than or equal to 0.5.
__num_nodes increases.| [in] | __num_nodes | Number of nodes the graph should have. |
| [in] | p | Probability of an arc existing between any pair of nodes. |
| bad_alloc | if there is not enough memory. |
| domain_error | if p is not in the range (0, 1]. |
Definition at line 671 of file random_graph.H.
References Aleph::Random_Graph< GT, Init_Node, Init_Arc >::create_p(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, Aleph::Random_Graph< GT, Init_Node, Init_Arc >::make_eulerian(), and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::save_parity.
|
inline |
Create a random Eulerian graph (sparse version).
This version builds a sparse random graph that is guaranteed to be Eulerian; that is, it contains Eulerian cycles.
The process first generates a sparse random graph, then examines the result and creates new arcs so that the output contains an Eulerian cycle.
| [in] | __num_nodes | Number of nodes the graph should have. |
| [in] | __num_arcs | Number of arcs the graph should have. |
| bad_alloc | if there is not enough memory. |
Definition at line 645 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::create(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, Aleph::Random_Graph< GT, Init_Node, Init_Arc >::make_eulerian(), Aleph::maps(), and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::save_parity.
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 556 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::idx_arc, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::insert_arc(), Aleph::maps(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::r, Aleph::DynSetTree< Key, Tree, Compare >::select(), and Aleph::DynSetTree< Key, Tree, Compare >::size().
Referenced by Aleph::Random_Graph< GT, Init_Node, Init_Arc >::eulerian(), and Aleph::Random_Graph< GT, Init_Node, Init_Arc >::eulerian().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 619 of file random_graph.H.
References Aleph::Random_Graph< GT, Init_Node, Init_Arc >::balance_graph_nodes_degree(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_nodes(), and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::nodes.
Referenced by Aleph::Random_Graph< GT, Init_Node, Init_Arc >::sufficient_hamiltonian().
|
inline |
Create a random graph with arc probability.
This version builds a random graph with probability p of an arc existing between any pair of nodes.
Use this routine to generate dense graphs. In this case, use a value of p greater than or equal to 0.5.
The procedure is quadratic: all node pairs are enumerated, and for each pair (i, j) a random draw with probability p determines whether an arc is created.
__num_nodes increases.| [in] | __num_nodes | Number of nodes the graph should have. |
| [in] | p | Probability of an arc existing between any pair of nodes. |
| [in] | connected | Whether the generated graph should be connected. Defaults to true. |
| bad_alloc | if there is not enough memory. |
| domain_error | if p is not in the range (0, 1]. |
Definition at line 549 of file random_graph.H.
References Aleph::Random_Graph< GT, Init_Node, Init_Arc >::create_p(), and Aleph::maps().
|
inline |
Create a sparse random graph.
This version builds a random graph with approximately __num_arcs arcs. The graph contains no parallel arcs.
The randomization procedure selects two nodes at random and inserts an arc between them if one does not already exist. The routine is linear, proportional to __num_arcs.
| [in] | __num_nodes | Number of nodes the graph should have. |
| [in] | __num_arcs | Number of arcs the graph should have. |
| [in] | connected | Whether the generated graph should be connected. Defaults to true. |
| bad_alloc | if there is not enough memory. |
Definition at line 520 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::create(), and Aleph::maps().
|
inlineprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 376 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_arcs(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), Aleph::is_even(), Aleph::maps(), Aleph::DynSetTree< Key, Tree, Compare >::remove(), and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::save_parity.
|
private |
Definition at line 374 of file random_graph.H.
|
private |
Definition at line 373 of file random_graph.H.