aGrUM  0.14.2
structuralConstraintDiGraph_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 
28 namespace gum {
29 
30  namespace learning {
31 
33  INLINE void StructuralConstraintDiGraph::setGraphAlone(const DiGraph& graph) {
34  _DiGraph__graph = graph;
35  }
36 
38  INLINE bool
40  NodeId y) const {
42  && !_DiGraph__graph.existsArc(x, y);
43  }
44 
46  INLINE bool
48  NodeId y) const {
49  return _DiGraph__graph.existsArc(x, y);
50  }
51 
53  INLINE bool
55  NodeId y) const {
56  return _DiGraph__graph.existsArc(x, y) && !_DiGraph__graph.existsArc(y, x);
57  }
58 
61  const ArcAddition& change) const {
62  return checkArcAdditionAlone(change.node1(), change.node2());
63  }
64 
67  const ArcDeletion& change) const {
68  return checkArcDeletionAlone(change.node1(), change.node2());
69  }
70 
73  const ArcReversal& change) const {
74  return checkArcReversalAlone(change.node1(), change.node2());
75  }
76 
79  const GraphChange& change) const {
80  switch (change.type()) {
82  return checkArcAdditionAlone(change.node1(), change.node2());
83 
85  return checkArcDeletionAlone(change.node1(), change.node2());
86 
88  return checkArcReversalAlone(change.node1(), change.node2());
89 
90  default:
91  GUM_ERROR(OperationNotAllowed,
92  "edge modifications are not "
93  "supported by StructuralConstraintDiGraph");
94  }
95  }
96 
98  INLINE void
99  StructuralConstraintDiGraph::modifyGraphAlone(const ArcAddition& change) {
100  _DiGraph__graph.addArc(change.node1(), change.node2());
101  }
102 
104  INLINE void
105  StructuralConstraintDiGraph::modifyGraphAlone(const ArcDeletion& change) {
106  _DiGraph__graph.eraseArc(Arc(change.node1(), change.node2()));
107  }
108 
110  INLINE void
111  StructuralConstraintDiGraph::modifyGraphAlone(const ArcReversal& change) {
112  _DiGraph__graph.eraseArc(Arc(change.node1(), change.node2()));
113  _DiGraph__graph.addArc(change.node2(), change.node1());
114  }
115 
117  INLINE void
118  StructuralConstraintDiGraph::modifyGraphAlone(const GraphChange& change) {
119  switch (change.type()) {
121  modifyGraphAlone(reinterpret_cast< const ArcAddition& >(change));
122  break;
123 
125  modifyGraphAlone(reinterpret_cast< const ArcDeletion& >(change));
126  break;
127 
129  modifyGraphAlone(reinterpret_cast< const ArcReversal& >(change));
130  break;
131 
132  default:
133  GUM_ERROR(OperationNotAllowed,
134  "edge modifications are not supported by digraph constraint");
135  }
136  }
137 
140  const GraphChange&) const {
141  return false;
142  }
143 
145  INLINE void StructuralConstraintDiGraph::setGraph(Size nb_nodes) {
147 
148  for (NodeId i = 0; i < nb_nodes; ++i) {
150  }
151  }
152 
153 // include all the methods applicable to the whole class hierarchy
154 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintDiGraph
156 # undef GUM_CONSTRAINT_CLASS_NAME
157 
158  } /* namespace learning */
159 
160 } /* namespace gum */
161 
162 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: diGraph_inl.h:32
void setGraph(Size nb_nodes)
sets a new empty graph from which we will perform checkings
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
virtual void clear()
removes all the nodes and arcs from the graph
Definition: diGraph_inl.h:40
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
DiGraph _DiGraph__graph
the DiGraph on which we perform checks
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
bool checkModificationAlone(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52