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

Function create_moral_graph

dlib/graph_utils/graph_utils.h:572–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570 typename graph_type
571 >
572 void create_moral_graph (
573 const directed_graph_type& g,
574 graph_type& moral_graph
575 )
576 {
577 // make sure requires clause is not broken
578 DLIB_ASSERT(graph_contains_directed_cycle(g) == false,
579 "\tvoid create_moral_graph(g, moral_graph)"
580 << "\n\tYou can only make moral graphs if g doesn't have directed cycles"
581 );
582 COMPILE_TIME_ASSERT(is_graph<graph_type>::value);
583 COMPILE_TIME_ASSERT(is_directed_graph<directed_graph_type>::value);
584
585 copy_graph_structure(g, moral_graph);
586
587 // now marry all the parents (i.e. add edges between parent nodes)
588 for (unsigned long i = 0; i < g.number_of_nodes(); ++i)
589 {
590 // loop over all combinations of parents of g.node(i)
591 for (unsigned long j = 0; j < g.node(i).number_of_parents(); ++j)
592 {
593 for (unsigned long k = 0; k < g.node(i).number_of_parents(); ++k)
594 {
595 const unsigned long p1 = g.node(i).parent(j).index();
596 const unsigned long p2 = g.node(i).parent(k).index();
597 if (p1 == p2)
598 continue;
599
600 if (moral_graph.has_edge(p1,p2) == false)
601 moral_graph.add_edge(p1,p2);
602 }
603 }
604 }
605 }
606
607// ----------------------------------------------------------------------------------------
608

Callers 5

bayes_nets_testFunction · 0.85
directed_graph_testFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 5

copy_graph_structureFunction · 0.85
number_of_parentsMethod · 0.80
number_of_nodesMethod · 0.45
indexMethod · 0.45

Tested by 2

bayes_nets_testFunction · 0.68
directed_graph_testFunction · 0.68