175#include <tclap/CmdLine.h>
183using namespace Aleph;
197 cout <<
"\n" << string(60,
'=') <<
"\n";
199 cout << string(60,
'=') <<
"\n\n";
211 cout <<
" Vertices: " << g.get_num_nodes() <<
endl;
212 cout <<
" Edges: " << g.get_num_arcs() <<
endl;
216 size_t min_deg = numeric_limits<size_t>::max();
219 for (
auto it = g.get_node_it(); it.has_curr(); it.next())
243 cout <<
"Generate a graph with n vertices and m random edges.\n";
244 cout <<
"Edges are placed uniformly at random.\n\n";
249 cout <<
"Parameters: n=" << n <<
" vertices, m=" << m <<
" edges\n";
270 cout <<
"Graph is CONNECTED\n";
273 cout <<
"Graph is DISCONNECTED\n";
274 cout <<
"Component sizes: ";
276 cout << it.get_curr().get_num_nodes() <<
" ";
281 double density = 2.0 * m / (n * (n - 1));
283 cout <<
"(1.0 = complete graph, 0.0 = no edges)\n";
294 cout <<
"Generate a random graph and then force connectivity (if needed).\n";
295 cout <<
"This demo requests a connected graph from the generator.\n\n";
300 cout <<
"Parameters: n=" << n <<
" vertices, m=" << m <<
" edges\n";
301 cout <<
"(Reference threshold for connectivity in G(n,m): ~n*ln(n)/2 = "
319 cout <<
"Graph is CONNECTED (as expected for dense graphs)\n";
321 cout <<
"Graph is disconnected (rare for this density)\n";
332 cout <<
"Generate a random graph where all vertices have even degree.\n";
333 cout <<
"Such a graph has an Eulerian cycle.\n\n";
338 cout <<
"Parameters: n=" << n <<
" vertices, m=" << m <<
" edges\n";
352 cout <<
"Vertex degrees: ";
353 for (
auto it = g.
get_node_it(); it.has_curr(); it.next())
367 cout <<
"Is Eulerian (Test_Eulerian)? " << (
test(g) ?
"YES" :
"NO") <<
endl;
378 cout <<
"Generate random directed graphs (digraphs).\n\n";
383 cout <<
"Parameters: n=" << n <<
" vertices, m=" << m <<
" arcs\n";
391 cout <<
"Digraph statistics:" <<
endl;
392 cout <<
" Vertices: " << g.get_num_nodes() <<
endl;
393 cout <<
" Arcs: " << g.get_num_arcs() <<
endl;
401 for (
auto it = g.get_node_it(); it.has_curr(); it.next())
423 cout <<
"Generate a random digraph where in-degree = out-degree for all.\n";
424 cout <<
"(Has an Eulerian cycle)\n\n";
429 cout <<
"Parameters: n=" << n <<
" vertices, m=" << m <<
" arcs\n";
437 cout <<
"Digraph statistics:" <<
endl;
438 cout <<
" Vertices: " << g.get_num_nodes() <<
endl;
439 cout <<
" Arcs: " << g.get_num_arcs() <<
endl;
445 cout <<
"Is Eulerian (Test_Eulerian)? " << (
test(g) ?
"YES" :
"NO") <<
endl;
456 cout <<
"How does edge count affect connectivity?\n\n";
461 cout <<
"n = " << n <<
" vertices, " <<
trials <<
" trials each\n\n";
464 <<
setw(20) <<
"Avg Components" <<
setw(15) <<
"% Connected" <<
endl;
469 for (
size_t m = n/2; m <= n*3; m += n/2)
474 for (
size_t t = 0; t <
trials; t++)
486 double density = 2.0 * m / (n * (n - 1));
496 cout <<
"\nNote: Connectivity threshold is around m ≈ n*ln(n)/2 ≈ "
497 << (
size_t)(n *
log(n) / 2) <<
" edges\n";
509 "Random graph generation example for Aleph-w.\n"
510 "Demonstrates various random graph models.",
516 "Run only specific section: erdos, connected, eulerian, digraph, "
517 "eulerian_dig, params, or 'all'",
518 false,
"all",
"section",
cmd
526 cout <<
"============================================================\n";
527 cout <<
" ALEPH-W RANDOM GRAPH GENERATION EXAMPLE\n";
528 cout <<
"============================================================\n";
548 cout <<
"\n" << string(60,
'=') <<
"\n";
549 cout <<
"Random graph generation demo completed!\n";
550 cout << string(60,
'=') <<
"\n\n";
554 catch (TCLAP::ArgException& e)
556 cerr <<
"Error: " << e.error() <<
" for argument " << e.argId() <<
endl;
561 cerr <<
"Error: " << e.what() <<
endl;
WeightedDigraph::Node Node
Generic directed graph (digraph) wrapper template.
Dynamic singly linked list with functional programming support.
size_t size() const noexcept
Count the number of elements of the list.
Graph implemented with double-linked adjacency lists.
Random directed graph (digraph) generator.
Random undirected graph generator.
Tests whether a graph or digraph is Eulerian.
Compute the connected components of a graph.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Eulerian graph detection and path/cycle finding.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log_function > > log(const __gmp_expr< T, U > &expr)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Random graph generation utilities.
void print_subsection(const string &title)
void print_section(const string &title)
void demo_eulerian_digraph()
void print_graph_stats(const string &label, G &g)
Arc of graph implemented with double-linked adjacency lists.
Node belonging to a graph implemented with a double linked adjacency list.
Filtered iterator of adjacent arcs of a node.
void test(unsigned long n, gsl_rng *r)
Graph connectivity and connected components.
Generic graph and digraph implementations.