aGrUM  0.16.0
DAG.cpp
Go to the documentation of this file.
1 
29 #include <agrum/graphs/DAG.h>
30 
31 #ifdef GUM_NO_INLINE
32 # include <agrum/graphs/DAG_inl.h>
33 #endif // GUM_NOINLINE
34 
35 namespace gum {
36 
37  // diamond structure require to explicitly initialize NodeGraphPart
38  DAG::DAG(Size nodes_size,
39  bool nodes_resize_policy,
40  Size arcs_size,
41  bool arcs_resize_policy) :
42  NodeGraphPart(nodes_size, nodes_resize_policy),
43  DiGraph(nodes_size, nodes_resize_policy, arcs_size, arcs_resize_policy) {
44  GUM_CONSTRUCTOR(DAG);
45  }
46 
47  // diamond structure require to explicitly initialize NodeGraphPart
48  DAG::DAG(const DAG& g) : NodeGraphPart(g), DiGraph(g) { GUM_CONS_CPY(DAG); }
49 
50  DAG::~DAG() { GUM_DESTRUCTOR(DAG); }
51 
53  UndiGraph moralgraph;
54  moralgraph.populateNodes(*this);
55  // transform the arcs into edges
56  for (const auto arc : arcs())
57  moralgraph.addEdge(arc.first(), arc.second());
58 
59  // marry the parents
60  for (const auto node : nodes()) {
61  const auto& par = parents(node);
62 
63  for (auto it1 = par.begin(); it1 != par.end(); ++it1) {
64  auto it2 = it1;
65 
66  for (++it2; it2 != par.end(); ++it2) {
67  // will automatically check if this edge already exists
68  moralgraph.addEdge(*it1, *it2);
69  }
70  }
71  }
72  return moralgraph;
73  }
74 
75 } /* namespace gum */
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:35
UndiGraph moralGraph() const
Definition: DAG.cpp:52
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual ~DAG()
destructor
Definition: DAG.cpp:50
DAG(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition: DAG.cpp:38
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Base class for all oriented graphs.
Definition: diGraph.h:111
Class for node sets in graph.
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
Base class for undirected graphs.
Definition: undiGraph.h:109
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Base class for dag.
Definition: DAG.h:102
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.