MCPcopy Create free account
hub / github.com/davisking/dlib / make_random_undirected_graph

Function make_random_undirected_graph

dlib/test/graph_cuts.cpp:383–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381
382 template <typename graph_type>
383 void make_random_undirected_graph(
384 dlib::rand& rnd,
385 graph_type& g
386 )
387 {
388 typedef typename graph_type::edge_type edge_weight_type;
389 g.clear();
390 const unsigned int num_nodes = rnd.get_random_32bit_number()%8;
391 g.set_number_of_nodes(num_nodes);
392
393 const unsigned int num_edges = static_cast<unsigned int>(num_nodes*(num_nodes-1)/2*rnd.get_random_double() + 0.5);
394
395 // add the right number of randomly selected edges
396 unsigned int count = 0;
397 while (count < num_edges)
398 {
399 unsigned long i = rnd.get_random_32bit_number()%g.number_of_nodes();
400 unsigned long j = rnd.get_random_32bit_number()%g.number_of_nodes();
401 if (i != j && g.has_edge(i, j) == false)
402 {
403 ++count;
404 g.add_edge(i, j);
405 edge(g, i, j) = static_cast<edge_weight_type>(rnd.get_random_double()*50);
406 }
407 }
408
409 for (unsigned long i = 0; i < g.number_of_nodes(); ++i)
410 {
411 g.node(i).data = static_cast<edge_weight_type>(rnd.get_random_gaussian()*200);
412 }
413 }
414
415// ----------------------------------------------------------------------------------------
416

Callers 1

test_graph_potts_modelFunction · 0.85

Calls 5

get_random_doubleMethod · 0.80
get_random_gaussianMethod · 0.80
clearMethod · 0.45
number_of_nodesMethod · 0.45

Tested by

no test coverage detected