aGrUM  0.14.2
structuralConstraintSliceOrder_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  ***************************************************************************/
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 
39 namespace gum {
40 
41  namespace learning {
42 
44  INLINE void
45  StructuralConstraintSliceOrder::setGraphAlone(const DiGraph& graph) {}
46 
48  INLINE bool
50  NodeId y) const {
51  try {
52  return _SliceOrder__order[x] <= _SliceOrder__order[y];
53  } catch (const Exception&) { return true; }
54  }
55 
57  INLINE bool
59  NodeId y) const {
60  return true;
61  }
62 
64  INLINE bool
66  NodeId y) const {
67  try {
68  return _SliceOrder__order[x] == _SliceOrder__order[y];
69  } catch (const Exception&) { return true; }
70  }
71 
74  const ArcAddition& change) {}
75 
78  const ArcDeletion& change) {}
79 
82  const ArcReversal& change) {}
83 
86  const GraphChange& change) {}
87 
90  const GraphChange& change) const {
91  switch (change.type()) {
93  try {
94  return (_SliceOrder__order[change.node1()]
95  > _SliceOrder__order[change.node2()]);
96  } catch (const Exception&) { return false; }
97 
98  case GraphChangeType::ARC_DELETION: return false;
99 
101  try {
102  return (_SliceOrder__order[change.node1()]
103  != _SliceOrder__order[change.node2()]);
104  } catch (const Exception&) { return false; }
105 
106  default:
107  GUM_ERROR(OperationNotAllowed,
108  "edge modifications are not "
109  "supported by SliceOrder constraints");
110  }
111  }
112 
115  const ArcAddition& change) const {
116  return checkArcAdditionAlone(change.node1(), change.node2());
117  }
118 
121  const ArcDeletion& change) const {
122  return checkArcDeletionAlone(change.node1(), change.node2());
123  }
124 
127  const ArcReversal& change) const {
128  return checkArcReversalAlone(change.node1(), change.node2());
129  }
130 
133  const GraphChange& change) const {
134  switch (change.type()) {
136  return checkArcAdditionAlone(change.node1(), change.node2());
137 
139  return checkArcDeletionAlone(change.node1(), change.node2());
140 
142  return checkArcReversalAlone(change.node1(), change.node2());
143 
144  default:
145  GUM_ERROR(OperationNotAllowed,
146  "edge modifications are not "
147  "supported by StructuralConstraintSliceOrder");
148  }
149  }
150 
153  const NodeProperty< NodeId >& order) {
154  _SliceOrder__order = order;
155  }
156 
159  for (auto& node : _SliceOrder__order) {
160  node.second = slice;
161  }
162  }
163 
166  NodeId slice) {
167  _SliceOrder__order.set(node, slice);
168  }
169 
171  INLINE const NodeProperty< NodeId >&
173  return _SliceOrder__order;
174  }
175 
176 // include all the methods applicable to the whole class hierarchy
177 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintSliceOrder
179 # undef GUM_CONSTRAINT_CLASS_NAME
180 
181  } /* namespace learning */
182 
183 } /* namespace gum */
184 
185 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
void setDefaultSlice(NodeId slice)
assign a given slice to all the nodes specified in the partial order
NodeProperty< NodeId > _SliceOrder__order
slices to which belong the nodes
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool checkModificationAlone(const ArcAddition &change) const
checks whether the constraints enable to add an arc
void setSliceOrder(const NodeProperty< NodeId > &slice)
sets the time slices of all the nodes in the property
const NodeProperty< NodeId > & sliceOrder() const
returns the current slice order
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void addNode(NodeId node, NodeId slice)
adds a new node in the slice order
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52