Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Random_Digraph< GT, Init_Node, Init_Arc > Class Template Reference

Random directed graph (digraph) generator. More...

#include <random_graph.H>

Inheritance diagram for Aleph::Random_Digraph< GT, Init_Node, Init_Arc >:
[legend]
Collaboration diagram for Aleph::Random_Digraph< GT, Init_Node, Init_Arc >:
[legend]

Public Member Functions

template<class N = Init_Node, class A = Init_Arc>
requires (std::constructible_from<Kept_Initializer<Init_Node>, N> and std::constructible_from<Kept_Initializer<Init_Arc>, A>)
 Random_Digraph (unsigned long seed=time(nullptr), N &&__init_node=Init_Node(), A &&__init_arc=Init_Arc())
 Constructor.
 
template<class N , class A >
requires (std::constructible_from<Kept_Initializer<Init_Node>, N> and std::constructible_from<Kept_Initializer<Init_Arc>, A>)
 Random_Digraph (N &&__init_node, A &&__init_arc)
 
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
 
using Base = Random_Graph_Base< GT, Init_Node, Init_Arc >
 

Private Member Functions

bool verify_tables ()
 
void update_parity_after_arc_insertion (GT_Node *src, GT_Node *tgt) override
 
void prepare_new_graph () override
 
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
 
bool join (GT_Node *src, GT_Node *tgt)
 
bool join_any_unbalanced_nodes ()
 
void join_through_a_path (GT_Node *src)
 
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

Base::Node_Set greater {typename Base::By_Creation{this}}
 
Base::Node_Set smaller {typename Base::By_Creation{this}}
 
Base::Node_Set equal {typename Base::By_Creation{this}}
 

Additional Inherited Members

- Protected Types inherited from Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >
typedef GT::Node GT_Node
 
typedef GT::Arc GT_Arc
 
using Node_Set = DynSetRandTree< GT_Node *, By_Creation >
 
- Protected Member Functions inherited from Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >
size_t order_of (GT_Node *p) const
 
void sort_components (DynList< DynList< GT_Node * > > &comps) const
 
GT_Arc * insert_arc (GT_Node *src, GT_Node *tgt)
 
GT_Node * select_random_node (GT_Node *excluded=nullptr) noexcept
 Select a random node different from excluded.
 
GT_Node * select_random_node (DynList< GT_Node * > &list) noexcept
 Select a random node from the given list.
 
void initialize_and_create_nodes (const size_t &__num_nodes, const size_t &__num_arcs)
 
template<class N , class A >
 Random_Graph_Base (const unsigned long seed, N &&__init_node, A &&__init_arc)
 
virtual ~Random_Graph_Base ()=default
 
GT create (const size_t &__num_nodes, const size_t &__num_arcs, const bool connected)
 Create a sparse random graph.
 
- Protected Attributes inherited from Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >
Kept_Initializer< Init_Node > kept_node
 
Kept_Initializer< Init_Arc > kept_arc
 
Gsl_Compatible_Rng_Owner r
 
Init_Node & init_node
 
Init_Arc & init_arc
 
std::unique_ptr< DynArray< GT_Node * > > nodes
 
std::unique_ptr< IndexArc< GT > > idx_arc
 
size_t num_nodes
 
size_t num_arcs
 
unsigned long rand_max
 
GT g
 
bool save_parity
 
DynMapHash< GT_Node *, size_t > creation
 

Detailed Description

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
class Aleph::Random_Digraph< GT, Init_Node, Init_Arc >

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:

  • GT: The graph type to construct. A graph of an undirected type is built as a digraph: it says that it is directed (see set_digraph()).
  • Init_Node: Functor class for initializing node data.
  • Init_Arc: Functor class for initializing arc data.
Author
Leandro Rabindranath Leon

Definition at line 1016 of file random_graph.H.

Member Typedef Documentation

◆ Base

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
using Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::Base = Random_Graph_Base<GT, Init_Node, Init_Arc>
private

Definition at line 1021 of file random_graph.H.

◆ GT_Arc

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
typedef GT::Arc Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::GT_Arc
private

Definition at line 1019 of file random_graph.H.

◆ GT_Node

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
typedef GT::Node Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::GT_Node
private

Definition at line 1018 of file random_graph.H.

Constructor & Destructor Documentation

◆ Random_Digraph() [1/2]

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
template<class N = Init_Node, class A = Init_Arc>
requires (std::constructible_from<Kept_Initializer<Init_Node>, N> and std::constructible_from<Kept_Initializer<Init_Arc>, A>)
Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::Random_Digraph ( unsigned long  seed = time(nullptr),
N &&  __init_node = Init_Node(),
A &&  __init_arc = Init_Arc() 
)
inline

Constructor.

Parameters
[in]seedSeed for the random number generator.
[in]__init_nodeNode initialization functor.
[in]__init_arcArc initialization functor.

Definition at line 1290 of file random_graph.H.

◆ Random_Digraph() [2/2]

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
template<class N , class A >
requires (std::constructible_from<Kept_Initializer<Init_Node>, N> and std::constructible_from<Kept_Initializer<Init_Arc>, A>)
Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::Random_Digraph ( N &&  __init_node,
A &&  __init_arc 
)
inline

Definition at line 1302 of file random_graph.H.

Member Function Documentation

◆ balance_digraph_node()

◆ balance_digraph_nodes_degree()

◆ connect()

◆ create_nodes_and_initialize_arc_index()

◆ create_p()

◆ join()

◆ join_any_unbalanced_nodes()

◆ join_through_a_path()

◆ make_eulerian()

◆ make_hamiltonian()

◆ operator()() [1/2]

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
GT Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::operator() ( const size_t &  __num_nodes,
const double &  p,
bool  connected = true 
)
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.

Warning
The procedure can be extremely slow and memory-intensive as __num_nodes increases.
Parameters
[in]__num_nodesNumber of nodes the digraph should have.
[in]pProbability of an arc existing between any ordered pair of nodes.
[in]connectedWhether the generated digraph should be strongly connected. Defaults to true.
Returns
The randomly created digraph.
Exceptions
bad_allocif there is not enough memory.
domain_errorif p is not in the range (0, 1].

Definition at line 1355 of file random_graph.H.

References Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::create_p().

◆ operator()() [2/2]

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
GT Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::operator() ( const size_t &  __num_nodes,
const size_t &  __num_arcs,
bool  connected = true 
)
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.

Parameters
[in]__num_nodesNumber of nodes the digraph should have.
[in]__num_arcsNumber of arcs the digraph should have.
[in]connectedWhether the generated digraph should be strongly connected. Defaults to true.
Returns
The randomly created digraph.
Exceptions
bad_allocif there is not enough memory.

Definition at line 1325 of file random_graph.H.

References Aleph::Random_Graph_Base< GT, Init_Node, Init_Arc >::create().

◆ prepare_new_graph()

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
void Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::prepare_new_graph ( )
inlineoverrideprivatevirtual

◆ update_parity_after_arc_insertion()

◆ verify_tables()

Member Data Documentation

◆ equal

◆ greater

template<AlephGraph GT, class Init_Node = Dft_Init_Rand_Node<GT>, class Init_Arc = Dft_Init_Rand_Arc<GT>>
Base::Node_Set Aleph::Random_Digraph< GT, Init_Node, Init_Arc >::greater {typename Base::By_Creation{this}}
private

Definition at line 1024 of file random_graph.H.

◆ smaller


The documentation for this class was generated from the following file: