|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Random directed graph (digraph) generator. More...
#include <random_graph.H>
Public Member Functions | |
| Random_Digraph (unsigned long seed, const Init_Node &__init_node, const Init_Arc &__init_arc) | |
| Constructor. | |
| Random_Digraph (unsigned long seed=time(nullptr), const Init_Node &&__init_node=Init_Node(), const Init_Arc &&__init_arc=Init_Arc()) | |
| Random_Digraph (const Init_Node &__init_node, const Init_Arc &__init_arc) | |
| ~Random_Digraph () | |
| GT | operator() (const size_t &__num_nodes, const size_t &__num_arcs, bool connected=true) |
| Create a sparse random digraph. | |
| GT | operator() (const size_t &__num_nodes, const double &p, bool connected=true) |
| Create a random digraph with arc probability. | |
Public Member Functions inherited from Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc > | |
| GT | eulerian (const size_t &__num_nodes, const size_t &__num_arcs) |
| Create a random Eulerian graph (sparse version). | |
| GT | eulerian (const size_t &__num_nodes, const double &p) |
| Create a random Eulerian graph (dense version). | |
| GT | sufficient_hamiltonian (const size_t &__num_nodes, const double &p=0.5) |
| Create a random Hamiltonian graph. | |
Private Types | |
| typedef GT::Node | GT_Node |
| typedef GT::Arc | GT_Arc |
Private Member Functions | |
| bool | verify_tables () |
| 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, bool connected) override |
| void | make_eulerian () override |
| void | balance_digraph_node (GT_Node *p) |
| void | balance_digraph_nodes_degree (GT_Node *src, GT_Node *tgt) |
| void | make_hamiltonian () override |
Private Attributes | |
| DynSetRandTree< GT_Node * > | greater |
| DynSetRandTree< GT_Node * > | smaller |
| DynSetRandTree< GT_Node * > | equal |
Random directed graph (digraph) generator.
Random_Digraph is a class for generating random directed 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 digraphs respectively.
Template parameters:
Definition at line 741 of file random_graph.H.
|
private |
Definition at line 744 of file random_graph.H.
|
private |
Definition at line 743 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 996 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, and GraphCommon< GT, Node, Arc >::set_digraph().
|
inline |
Definition at line 1004 of file random_graph.H.
|
inline |
Definition at line 1012 of file random_graph.H.
|
inline |
Definition at line 1019 of file random_graph.H.
References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, and GraphCommon< GT, Node, Arc >::set_digraph().
|
inlineprivate |
Definition at line 1112 of file random_graph.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), 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(), NODE_COUNTER, 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_Digraph< GT, Init_Node, Init_Arc >::balance_digraph_nodes_degree().
|
inlineprivate |
Definition at line 1139 of file random_graph.H.
References Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::balance_digraph_node(), Aleph::blossom_maximum_cardinality_matching(), 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(), NODE_COUNTER, 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_Digraph< GT, Init_Node, Init_Arc >::make_hamiltonian().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 908 of file random_graph.H.
References Aleph::DynArray< T >::access(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_nodes(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::idx_arc, Aleph::in_degree(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::insert_arc(), NODE_COUNTER, Aleph::DynArray< T >::reserve(), and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::select_random_node().
Referenced by Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::create_p().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 885 of file random_graph.H.
References Aleph::blossom_maximum_cardinality_matching(), 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(), 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 964 of file random_graph.H.
References ah_domain_error_if, Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Random_Digraph< 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 >::idx_arc, 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::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_Digraph< GT, Init_Node, Init_Arc >::operator()().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 1077 of file random_graph.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::idx_arc, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::insert_arc(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::r, Aleph::DynSetTree< Key, Tree, Compare >::select(), and Aleph::DynSetTree< Key, Tree, Compare >::size().
|
inlineoverrideprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 1176 of file random_graph.H.
References Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::balance_digraph_nodes_degree(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_nodes(), NODE_COUNTER, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::nodes, and GraphCommon< GT, Node, Arc >::reset_counter_nodes().
|
inline |
Create a random digraph with arc probability.
This version builds a random digraph with probability p of an arc existing between any ordered pair of nodes.
Use this routine to generate dense digraphs. In this case, use a value of p greater than or equal to 0.5.
The procedure is quadratic: all ordered 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 digraph should have. |
| [in] | p | Probability of an arc existing between any ordered pair of nodes. |
| [in] | connected | Whether the generated digraph should be strongly 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 1070 of file random_graph.H.
References Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::create_p().
|
inline |
Create a sparse random digraph.
This version builds a random digraph with approximately __num_arcs arcs. The digraph 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 digraph should have. |
| [in] | __num_arcs | Number of arcs the digraph should have. |
| [in] | connected | Whether the generated digraph should be strongly connected. Defaults to true. |
| bad_alloc | if there is not enough memory. |
Definition at line 1040 of file random_graph.H.
References Aleph::blossom_maximum_cardinality_matching(), and Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::create().
|
inlineprivatevirtual |
Implements Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >.
Definition at line 835 of file random_graph.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_arcs(), Aleph::DynSetTree< Key, Tree, Compare >::insert(), NODE_COUNTER, Aleph::DynSetTree< Key, Tree, Compare >::remove(), Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::save_parity, and Aleph::DynSetTree< Key, Tree, Compare >::search().
|
inlineprivate |
Definition at line 750 of file random_graph.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::equal, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::g, GraphCommon< GT, Node, Arc >::get_num_arcs(), GraphCommon< GT, Node, Arc >::get_num_nodes(), NODE_COUNTER, Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::nodes, Aleph::DynSetTree< Key, Tree, Compare >::search(), Aleph::DynSetTree< Key, Tree, Compare >::size(), and Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::smaller.
|
private |
Definition at line 748 of file random_graph.H.
Referenced by Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::verify_tables().
|
private |
Definition at line 746 of file random_graph.H.
|
private |
Definition at line 747 of file random_graph.H.
Referenced by Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::verify_tables().