aGrUM  0.16.0
structuralConstraintDAG_inl.h
Go to the documentation of this file.
1 
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 # include <agrum/agrum.h>
33 
34 namespace gum {
35 
36  namespace learning {
37 
39  INLINE void StructuralConstraintDAG::setGraphAlone(const DiGraph& graph) {
40  // check that the digraph has no cycle
41  DAG g;
42 
43  for (auto node : graph)
44  g.addNodeWithId(node);
45 
46  for (auto& arc : graph.arcs())
47  g.addArc(arc.tail(), arc.head());
48 
50  }
51 
53  INLINE void StructuralConstraintDAG::setGraphAlone(Size nb_nodes) {
54  DAG g;
55 
56  for (NodeId i = 0; i < nb_nodes; ++i) {
57  g.addNodeWithId(i);
58  }
59 
61  }
62 
65  NodeId y) const {
67  }
68 
71  NodeId y) const {
73  }
74 
77  NodeId y) const {
79  }
80 
83  const ArcAddition& change) const {
84  return checkArcAdditionAlone(change.node1(), change.node2());
85  }
86 
89  const ArcDeletion& change) const {
90  return checkArcDeletionAlone(change.node1(), change.node2());
91  }
92 
95  const ArcReversal& change) const {
96  return checkArcReversalAlone(change.node1(), change.node2());
97  }
98 
101  const GraphChange& change) const {
102  switch (change.type()) {
104  return checkArcAdditionAlone(change.node1(), change.node2());
105 
107  return checkArcDeletionAlone(change.node1(), change.node2());
108 
110  return checkArcReversalAlone(change.node1(), change.node2());
111 
112  default:
113  GUM_ERROR(OperationNotAllowed,
114  "edge modifications are not "
115  "supported by StructuralConstraintDAG");
116  }
117  }
118 
120  INLINE void
121  StructuralConstraintDAG::modifyGraphAlone(const ArcAddition& change) {
122  _DAG__cycle_detector.addArc(change.node1(), change.node2());
123  }
124 
126  INLINE void
127  StructuralConstraintDAG::modifyGraphAlone(const ArcDeletion& change) {
128  _DAG__cycle_detector.eraseArc(change.node1(), change.node2());
129  }
130 
132  INLINE void
133  StructuralConstraintDAG::modifyGraphAlone(const ArcReversal& change) {
134  _DAG__cycle_detector.reverseArc(change.node1(), change.node2());
135  }
136 
138  INLINE void
139  StructuralConstraintDAG::modifyGraphAlone(const GraphChange& change) {
140  switch (change.type()) {
142  modifyGraphAlone(reinterpret_cast< const ArcAddition& >(change));
143  break;
144 
146  modifyGraphAlone(reinterpret_cast< const ArcDeletion& >(change));
147  break;
148 
150  modifyGraphAlone(reinterpret_cast< const ArcReversal& >(change));
151  break;
152 
153  default:
154  GUM_ERROR(OperationNotAllowed,
155  "edge modifications are not supported by DAG constraints");
156  }
157  }
158 
160  INLINE bool
161  StructuralConstraintDAG::isAlwaysInvalidAlone(const GraphChange&) const {
162  return false;
163  }
164 
166  INLINE void StructuralConstraintDAG::setGraph(const DAG& graph) {
167  constraints::setGraph(graph);
169  }
170 
172  INLINE void StructuralConstraintDAG::setGraph(Size nb_nodes) {
174  setGraphAlone(nb_nodes);
175  }
176 
177 // include all the methods applicable to the whole class hierarchy
178 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintDAG
180 # undef GUM_CONSTRAINT_CLASS_NAME
181 
182  } /* namespace learning */
183 
184 } /* namespace gum */
185 
186 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
bool checkModificationAlone(const ArcAddition &change) const
checks whether the constraints enable to add an arc
void setGraph(const DAG &graph)
sets a new graph from which we will perform checkings
void setGraph(Size nb_nodes)
sets a new empty graph from which we will perform checkings
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
void eraseArc(NodeId x, NodeId y)
removes an arc from the current DAG
void addArc(NodeId x, NodeId y)
adds a new arc to the current DAG
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
void setDAG(const DAG &dag)
sets the initial DAG from which changes shall be applied
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
bool hasCycleFromAddition(NodeId x, NodeId y) const noexcept
indicates whether an arc addition would create a cycle
bool hasCycleFromReversal(NodeId x, NodeId y) const noexcept
indicates wether an arc reversal would create a cycle
bool hasCycleFromDeletion(NodeId x, NodeId y) const noexcept
indicates whether an arc deletion would create a cycle
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Size NodeId
Type for node ids.
Definition: graphElements.h:98
DAGCycleDetector _DAG__cycle_detector
the cycle detector used to check quickly graph modifications
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void reverseArc(NodeId x, NodeId y)
reverses an arc from the DAG