aGrUM  0.14.2
structuralConstraintTabuList_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
35  if (new_size == _TabuList__changes.size()) return;
36 
37  if (_TabuList__changes.size() > new_size) {
38  // remove the oldest elements, so that only newsize elements remain
39  while (_TabuList__changes.size() > new_size) {
42  }
43  } else {
44  // add dummy elements
45  while (_TabuList__changes.size() < new_size) {
47  _TabuList__changes.insert(
48  ArcAddition(std::numeric_limits< NodeId >::max() - _TabuList__offset,
49  std::numeric_limits< NodeId >::max()),
51  }
52  }
53  }
54 
56  INLINE void StructuralConstraintTabuList::setGraphAlone(const DiGraph& graph) {
57  }
58 
60  INLINE bool
62  NodeId y) const {
63  return !_TabuList__changes.existsFirst(ArcDeletion(x, y))
64  && !_TabuList__changes.existsFirst(ArcAddition(x, y));
65  }
66 
68  INLINE bool
70  NodeId y) const {
71  return !_TabuList__changes.existsFirst(ArcAddition(x, y))
72  && !_TabuList__changes.existsFirst(ArcDeletion(x, y));
73  }
74 
76  INLINE bool
78  NodeId y) const {
79  return !_TabuList__changes.existsFirst(ArcReversal(y, x))
80  && !_TabuList__changes.existsFirst(ArcReversal(x, y));
81  }
82 
85  const ArcAddition& change) const {
86  return checkArcAdditionAlone(change.node1(), change.node2());
87  }
88 
91  const ArcDeletion& change) const {
92  return checkArcDeletionAlone(change.node1(), change.node2());
93  }
94 
97  const ArcReversal& change) const {
98  return checkArcReversalAlone(change.node1(), change.node2());
99  }
100 
103  const GraphChange& change) const {
104  switch (change.type()) {
106  return checkArcAdditionAlone(change.node1(), change.node2());
107 
109  return checkArcDeletionAlone(change.node1(), change.node2());
110 
112  return checkArcReversalAlone(change.node1(), change.node2());
113 
114  default:
115  GUM_ERROR(OperationNotAllowed,
116  "edge modifications are not "
117  "supported by StructuralConstraintTabuList");
118  }
119  }
120 
122  INLINE void
123  StructuralConstraintTabuList::modifyGraphAlone(const ArcAddition& change) {
126  _TabuList__changes.insert(
127  change, NodeId(_TabuList__offset + _TabuList__changes.size()));
128  }
129 
131  INLINE void
132  StructuralConstraintTabuList::modifyGraphAlone(const ArcDeletion& change) {
135  _TabuList__changes.insert(
136  change, _TabuList__offset + NodeId(_TabuList__changes.size()));
137  }
138 
140  INLINE void
141  StructuralConstraintTabuList::modifyGraphAlone(const ArcReversal& change) {
144  _TabuList__changes.insert(
145  change, _TabuList__offset + NodeId(_TabuList__changes.size()));
146  }
147 
149  INLINE void
150  StructuralConstraintTabuList::modifyGraphAlone(const GraphChange& change) {
151  switch (change.type()) {
153  modifyGraphAlone(static_cast< const ArcAddition& >(change));
154  break;
155 
157  modifyGraphAlone(static_cast< const ArcDeletion& >(change));
158  break;
159 
161  modifyGraphAlone(static_cast< const ArcReversal& >(change));
162  break;
163 
164  default:
165  GUM_ERROR(OperationNotAllowed,
166  "edge modifications are not supported by digraph constraint");
167  }
168  }
169 
172  const GraphChange&) const {
173  return false;
174  }
175 
176 // include all the methods applicable to the whole class hierarchy
177 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintTabuList
179 # undef GUM_CONSTRAINT_CLASS_NAME
180 
181  } /* namespace learning */
182 
183 } /* namespace gum */
184 
185 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
void setTabuListSize(Size new_size)
sets the size of the tabu list
bool checkModificationAlone(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
NodeId _TabuList__offset
the index of the oldest element
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
Bijection< GraphChange, NodeId > _TabuList__changes
the tabu list
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52