aGrUM  0.14.2
structuralConstraintSetStatic_tpl.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 # include <iostream>
29 
30 namespace gum {
31 
32  namespace learning {
33 
35  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
36  INLINE __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
37  __StructuralConstraintSetStatic() {}
38 
40  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
41  INLINE __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
42  __StructuralConstraintSetStatic(
43  const __StructuralConstraintSetStatic< CONSTRAINT1,
44  OTHER_CONSTRAINTS... >& from) :
45  CONSTRAINT1(from),
46  __StructuralConstraintSetStatic< OTHER_CONSTRAINTS... >(from) {}
47 
49  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
50  INLINE __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
51  ~__StructuralConstraintSetStatic() {}
52 
54  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
55  INLINE __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >&
56  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
57  operator=(
58  const __StructuralConstraintSetStatic< CONSTRAINT1,
59  OTHER_CONSTRAINTS... >& from) {
60  if (this != &from) {
61  next_constraints::operator=(from);
62  first_constraint::operator=(from);
63  }
64 
65  return *this;
66  }
67 
69  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
70  INLINE void
71  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
72  setGraph(const DiGraph& graph) {
73  next_constraints::setGraph(graph);
74  first_constraint::setGraphAlone(graph);
75  }
76 
78  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
79  INLINE void
80  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
81  modifyGraph(const ArcAddition& change) {
82  next_constraints::modifyGraph(change);
83  first_constraint::modifyGraphAlone(change);
84  }
85 
87  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
88  INLINE void
89  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
90  modifyGraph(const ArcDeletion& change) {
91  next_constraints::modifyGraph(change);
92  first_constraint::modifyGraphAlone(change);
93  }
94 
96  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
97  INLINE void
98  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
99  modifyGraph(const ArcReversal& change) {
100  next_constraints::modifyGraph(change);
101  first_constraint::modifyGraphAlone(change);
102  }
103 
105  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
106  INLINE void
107  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
108  modifyGraph(const GraphChange& change) {
109  next_constraints::modifyGraph(change);
110  first_constraint::modifyGraphAlone(change);
111  }
112 
114  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
115  INLINE bool
116  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
117  isAlwaysInvalid(const GraphChange& change) const {
118  return next_constraints::isAlwaysInvalid(change)
119  || first_constraint::isAlwaysInvalidAlone(change);
120  }
121 
123  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
124  INLINE bool
125  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
126  checkArcAddition(NodeId x, NodeId y) const {
127  return next_constraints::checkArcAddition(x, y)
128  && first_constraint::checkArcAdditionAlone(x, y);
129  }
130 
132  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
133  INLINE bool
134  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
135  checkArcDeletion(NodeId x, NodeId y) const {
136  return next_constraints::checkArcDeletion(x, y)
137  && first_constraint::checkArcDeletionAlone(x, y);
138  }
139 
141  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
142  INLINE bool
143  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
144  checkArcReversal(NodeId x, NodeId y) const {
145  return next_constraints::checkArcReversal(x, y)
146  && first_constraint::checkArcReversalAlone(x, y);
147  }
148 
150  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
151  INLINE bool
152  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
153  checkModification(const ArcAddition& change) const {
154  return next_constraints::checkModification(change)
155  && first_constraint::checkModificationAlone(change);
156  }
157 
159  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
160  INLINE bool
161  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
162  checkModification(const ArcDeletion& change) const {
163  return next_constraints::checkModification(change)
164  && first_constraint::checkModificationAlone(change);
165  }
166 
168  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
169  INLINE bool
170  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
171  checkModification(const ArcReversal& change) const {
172  return next_constraints::checkModification(change)
173  && first_constraint::checkModificationAlone(change);
174  }
175 
177  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
178  INLINE bool
179  __StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
180  checkModification(const GraphChange& change) const {
181  return next_constraints::checkModification(change)
182  && first_constraint::checkModificationAlone(change);
183  }
184 
185  // ===========================================================================
186 
188  template < typename CONSTRAINT >
189  INLINE __StructuralConstraintSetStatic<
190  CONSTRAINT >::__StructuralConstraintSetStatic() {}
191 
193  template < typename CONSTRAINT >
194  INLINE __StructuralConstraintSetStatic< CONSTRAINT >::
195  __StructuralConstraintSetStatic(
196  const __StructuralConstraintSetStatic< CONSTRAINT >& from) :
197  CONSTRAINT(from) {}
198 
200  template < typename CONSTRAINT >
201  INLINE __StructuralConstraintSetStatic<
202  CONSTRAINT >::~__StructuralConstraintSetStatic() {}
203 
205  template < typename CONSTRAINT >
206  INLINE __StructuralConstraintSetStatic< CONSTRAINT >&
207  __StructuralConstraintSetStatic< CONSTRAINT >::
208  operator=(const __StructuralConstraintSetStatic< CONSTRAINT >& from) {
209  if (this != &from) { CONSTRAINT::operator=(from); }
210 
211  return *this;
212  }
213 
215  template < typename CONSTRAINT >
216  INLINE void __StructuralConstraintSetStatic< CONSTRAINT >::setGraph(
217  const DiGraph& graph) {
218  first_constraint::setGraphAlone(graph);
219  }
220 
222  template < typename CONSTRAINT >
223  INLINE void __StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
224  const ArcAddition& change) {
225  first_constraint::modifyGraphAlone(change);
226  }
227 
229  template < typename CONSTRAINT >
230  INLINE void __StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
231  const ArcDeletion& change) {
232  first_constraint::modifyGraphAlone(change);
233  }
234 
236  template < typename CONSTRAINT >
237  INLINE void __StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
238  const ArcReversal& change) {
239  first_constraint::modifyGraphAlone(change);
240  }
241 
243  template < typename CONSTRAINT >
244  INLINE void __StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
245  const GraphChange& change) {
246  first_constraint::modifyGraphAlone(change);
247  }
248 
250  template < typename CONSTRAINT >
251  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::isAlwaysInvalid(
252  const GraphChange& change) const {
253  return first_constraint::isAlwaysInvalidAlone(change);
254  }
255 
257  template < typename CONSTRAINT >
258  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkArcAddition(
259  NodeId x, NodeId y) const {
260  return first_constraint::checkArcAdditionAlone(x, y);
261  }
262 
264  template < typename CONSTRAINT >
265  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkArcDeletion(
266  NodeId x, NodeId y) const {
267  return first_constraint::checkArcDeletionAlone(x, y);
268  }
269 
271  template < typename CONSTRAINT >
272  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkArcReversal(
273  NodeId x, NodeId y) const {
274  return first_constraint::checkArcReversalAlone(x, y);
275  }
276 
278  template < typename CONSTRAINT >
279  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
280  const ArcAddition& change) const {
281  return first_constraint::checkModificationAlone(change);
282  }
283 
285  template < typename CONSTRAINT >
286  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
287  const ArcDeletion& change) const {
288  return first_constraint::checkModificationAlone(change);
289  }
290 
292  template < typename CONSTRAINT >
293  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
294  const ArcReversal& change) const {
295  return first_constraint::checkModificationAlone(change);
296  }
297 
299  template < typename CONSTRAINT >
300  INLINE bool __StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
301  const GraphChange& change) const {
302  return first_constraint::checkModificationAlone(change);
303  }
304 
305  // ===========================================================================
306 
308  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
309  INLINE StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
310  StructuralConstraintSetStatic() {
311  GUM_CONSTRUCTOR(StructuralConstraintSetStatic);
312  }
313 
315  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
316  INLINE StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
317  StructuralConstraintSetStatic(
318  const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >&
319  from) :
320  constraints(from) {
321  GUM_CONS_CPY(StructuralConstraintSetStatic);
322  }
323 
325  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
326  INLINE StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
327  ~StructuralConstraintSetStatic() {
328  GUM_DESTRUCTOR(StructuralConstraintSetStatic);
329  }
330 
332  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
333  INLINE StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >&
334  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
335  operator=(
336  const StructuralConstraintSetStatic< CONSTRAINT1,
337  OTHER_CONSTRAINTS... >& from) {
338  if (this != &from) { constraints::operator=(from); }
339 
340  return *this;
341  }
342 
344  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
345  INLINE void
346  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
347  setGraph(const DiGraph& graph) {
348  constraints::setGraph(graph);
349  }
350 
352  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
353  INLINE bool
354  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
355  checkArcAddition(NodeId x, NodeId y) const {
356  return constraints::checkArcAddition(x, y);
357  }
358 
360  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
361  INLINE bool
362  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
363  checkArcDeletion(NodeId x, NodeId y) const {
364  return constraints::checkArcDeletion(x, y);
365  }
366 
368  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
369  INLINE bool
370  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
371  checkArcReversal(NodeId x, NodeId y) const {
372  return constraints::checkArcReversal(x, y);
373  }
374 
376  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
377  INLINE bool
378  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
379  checkModification(const ArcAddition& change) const {
380  return constraints::checkModification(change);
381  }
382 
384  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
385  INLINE bool
386  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
387  checkModification(const ArcDeletion& change) const {
388  return constraints::checkModification(change);
389  }
390 
392  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
393  INLINE bool
394  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
395  checkModification(const ArcReversal& change) const {
396  return constraints::checkModification(change);
397  }
398 
400  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
401  INLINE bool
402  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
403  checkModification(const GraphChange& change) const {
404  return constraints::checkModification(change);
405  }
406 
408  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
409  INLINE void
410  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
411  modifyGraph(const ArcAddition& change) {
412  if (checkModification(change)) {
413  constraints::modifyGraph(change);
414  } else {
415  GUM_ERROR(OperationNotAllowed,
416  "the constraint set does not allow this arc addition between "
417  << change.node1() << " and " << change.node2());
418  }
419  }
420 
422  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
423  INLINE void
424  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
425  modifyGraph(const ArcDeletion& change) {
426  if (checkModification(change)) {
427  constraints::modifyGraph(change);
428  } else {
429  GUM_ERROR(OperationNotAllowed,
430  "the constraint set does not allow this arc deletion between "
431  << change.node1() << " and " << change.node2());
432  }
433  }
434 
436  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
437  INLINE void
438  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
439  modifyGraph(const ArcReversal& change) {
440  if (checkModification(change)) {
441  constraints::modifyGraph(change);
442  } else {
443  GUM_ERROR(OperationNotAllowed,
444  "the constraint set does not allow this arc reversal between "
445  << change.node1() << " and " << change.node2());
446  }
447  }
448 
450  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
451  INLINE void
452  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
453  modifyGraph(const GraphChange& change) {
454  switch (change.type()) {
456  modifyGraph(reinterpret_cast< const ArcAddition& >(change));
457  break;
458 
460  modifyGraph(reinterpret_cast< const ArcDeletion& >(change));
461  break;
462 
464  modifyGraph(reinterpret_cast< const ArcReversal& >(change));
465  break;
466 
467  default:
468  GUM_ERROR(OperationNotAllowed,
469  "edge modifications are not "
470  "currently supported by constraint sets");
471  }
472  }
473 
475  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
476  INLINE bool
477  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
478  isAlwaysInvalid(const GraphChange& change) const {
479  return constraints::isAlwaysInvalid(change);
480  }
481 
482  // ===========================================================================
483 
485  template < typename CONSTRAINT >
486  INLINE StructuralConstraintSetStatic<
487  CONSTRAINT >::StructuralConstraintSetStatic() {
488  GUM_CONSTRUCTOR(StructuralConstraintSetStatic);
489  }
490 
492  template < typename CONSTRAINT >
493  INLINE
494  StructuralConstraintSetStatic< CONSTRAINT >::StructuralConstraintSetStatic(
495  const StructuralConstraintSetStatic< CONSTRAINT >& from) :
496  constraints(from) {
497  GUM_CONS_CPY(StructuralConstraintSetStatic);
498  }
499 
501  template < typename CONSTRAINT >
502  INLINE StructuralConstraintSetStatic<
503  CONSTRAINT >::~StructuralConstraintSetStatic() {
504  GUM_DESTRUCTOR(StructuralConstraintSetStatic);
505  }
506 
508  template < typename CONSTRAINT >
509  INLINE StructuralConstraintSetStatic< CONSTRAINT >&
510  StructuralConstraintSetStatic< CONSTRAINT >::
511  operator=(const StructuralConstraintSetStatic< CONSTRAINT >& from) {
512  if (this != &from) { constraints::operator=(from); }
513 
514  return *this;
515  }
516 
518  template < typename CONSTRAINT >
519  INLINE void StructuralConstraintSetStatic< CONSTRAINT >::setGraph(
520  const DiGraph& graph) {
521  constraints::setGraph(graph);
522  }
523 
525  template < typename CONSTRAINT >
526  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkArcAddition(
527  NodeId x, NodeId y) const {
528  return constraints::checkArcAddition(x, y);
529  }
530 
532  template < typename CONSTRAINT >
533  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkArcDeletion(
534  NodeId x, NodeId y) const {
535  return constraints::checkArcDeletion(x, y);
536  }
537 
539  template < typename CONSTRAINT >
540  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkArcReversal(
541  NodeId x, NodeId y) const {
542  return constraints::checkArcReversal(x, y);
543  }
544 
546  template < typename CONSTRAINT >
547  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
548  const ArcAddition& change) const {
549  return constraints::checkModification(change);
550  }
551 
553  template < typename CONSTRAINT >
554  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
555  const ArcDeletion& change) const {
556  return constraints::checkModification(change);
557  }
558 
560  template < typename CONSTRAINT >
561  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
562  const ArcReversal& change) const {
563  return constraints::checkModification(change);
564  }
565 
567  template < typename CONSTRAINT >
568  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
569  const GraphChange& change) const {
570  return constraints::checkModification(change);
571  }
572 
574  template < typename CONSTRAINT >
575  INLINE void StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
576  const ArcAddition& change) {
577  if (checkModification(change)) {
578  constraints::modifyGraph(change);
579  } else {
580  GUM_ERROR(OperationNotAllowed,
581  "the constraint set does not allow this arc addition between "
582  << change.node1() << " and " << change.node2());
583  }
584  }
585 
587  template < typename CONSTRAINT >
588  INLINE void StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
589  const ArcDeletion& change) {
590  if (checkModification(change)) {
591  constraints::modifyGraph(change);
592  } else {
593  GUM_ERROR(OperationNotAllowed,
594  "the constraint set does not allow this arc deletion between "
595  << change.node1() << " and " << change.node2());
596  }
597  }
598 
600  template < typename CONSTRAINT >
601  INLINE void StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
602  const ArcReversal& change) {
603  if (checkModification(change)) {
604  constraints::modifyGraph(change);
605  } else {
606  GUM_ERROR(OperationNotAllowed,
607  "the constraint set does not allow this arc reversal between "
608  << change.node1() << " and " << change.node2());
609  }
610  }
611 
613  template < typename CONSTRAINT >
614  INLINE void StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(
615  const GraphChange& change) {
616  switch (change.type()) {
618  modifyGraph(reinterpret_cast< const ArcAddition& >(change));
619  break;
620 
622  modifyGraph(reinterpret_cast< const ArcDeletion& >(change));
623  break;
624 
626  modifyGraph(reinterpret_cast< const ArcReversal& >(change));
627  break;
628 
629  default:
630  GUM_ERROR(OperationNotAllowed,
631  "edge modifications are not "
632  "currently supported by constraint sets");
633  }
634  }
635 
637  template < typename CONSTRAINT >
638  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::isAlwaysInvalid(
639  const GraphChange& change) const {
640  return constraints::isAlwaysInvalid(change);
641  }
642 
643  } /* namespace learning */
644 
645 } /* namespace gum */
646 
647 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52