Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
extensional-tuple-set.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Linnea Ingmar <linnea.ingmar@hotmail.com>
5  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  * Christian Schulte <schulte@gecode.org>
7  *
8  * Copyright:
9  * Linnea Ingmar, 2017
10  * Mikael Lagerkvist, 2007
11  * Christian Schulte, 2017
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
39 
40 namespace Gecode {
41 
42  void
43  extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos,
44  IntPropLevel) {
45  using namespace Int;
46  if (!t.finalized())
47  throw NotYetFinalized("Int::extensional");
48  if (t.arity() != x.size())
49  throw ArgumentSizeMismatch("Int::extensional");
51 
52  ViewArray<IntView> xv(home,x);
53  if (pos)
54  GECODE_ES_FAIL((Extensional::postposcompact<IntView>(home,xv,t)));
55  else
56  GECODE_ES_FAIL((Extensional::postnegcompact<IntView>(home,xv,t)));
57  }
58 
59  void
60  extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos,
61  Reify r,
62  IntPropLevel) {
63  using namespace Int;
64  if (!t.finalized())
65  throw NotYetFinalized("Int::extensional");
66  if (t.arity() != x.size())
67  throw ArgumentSizeMismatch("Int::extensional");
69 
70  ViewArray<IntView> xv(home,x);
71  if (pos) {
72  switch (r.mode()) {
73  case RM_EQV:
74  GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_EQV>
75  (home,xv,t,r.var())));
76  break;
77  case RM_IMP:
78  GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_IMP>
79  (home,xv,t,r.var())));
80  break;
81  case RM_PMI:
82  GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_PMI>
83  (home,xv,t,r.var())));
84  break;
85  default: throw UnknownReifyMode("Int::extensional");
86  }
87  } else {
88  NegBoolView n(r.var());
89  switch (r.mode()) {
90  case RM_EQV:
91  GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_EQV>
92  (home,xv,t,n)));
93  break;
94  case RM_IMP:
95  GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_PMI>
96  (home,xv,t,n)));
97  break;
98  case RM_PMI:
99  GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_IMP>
100  (home,xv,t,n)));
101  break;
102  default: throw UnknownReifyMode("Int::extensional");
103  }
104  }
105  }
106 
107  void
108  extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos,
109  IntPropLevel) {
110  using namespace Int;
111  if (!t.finalized())
112  throw NotYetFinalized("Int::extensional");
113  if (t.arity() != x.size())
114  throw ArgumentSizeMismatch("Int::extensional");
115  if ((t.min() < 0) || (t.max() > 1))
116  throw NotZeroOne("Int::extensional");
117  GECODE_POST;
118 
119  ViewArray<BoolView> xv(home,x);
120  if (pos)
121  GECODE_ES_FAIL((Extensional::postposcompact<BoolView>(home,xv,t)));
122  else
123  GECODE_ES_FAIL((Extensional::postnegcompact<BoolView>(home,xv,t)));
124  }
125 
126  void
127  extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos,
128  Reify r,
129  IntPropLevel) {
130  using namespace Int;
131  if (!t.finalized())
132  throw NotYetFinalized("Int::extensional");
133  if (t.arity() != x.size())
134  throw ArgumentSizeMismatch("Int::extensional");
135  if ((t.min() < 0) || (t.max() > 1))
136  throw NotZeroOne("Int::extensional");
137  GECODE_POST;
138 
139  ViewArray<BoolView> xv(home,x);
140  if (pos) {
141  switch (r.mode()) {
142  case RM_EQV:
143  GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_EQV>
144  (home,xv,t,r.var())));
145  break;
146  case RM_IMP:
147  GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_IMP>
148  (home,xv,t,r.var())));
149  break;
150  case RM_PMI:
151  GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_PMI>
152  (home,xv,t,r.var())));
153  break;
154  default: throw UnknownReifyMode("Int::extensional");
155  }
156  } else {
157  NegBoolView n(r.var());
158  switch (r.mode()) {
159  case RM_EQV:
160  GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_EQV>
161  (home,xv,t,n)));
162  break;
163  case RM_IMP:
164  GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_PMI>
165  (home,xv,t,n)));
166  break;
167  case RM_PMI:
168  GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_IMP>
169  (home,xv,t,n)));
170  break;
171  default: throw UnknownReifyMode("Int::extensional");
172  }
173  }
174  }
175 
176 }
177 
178 // STATISTICS: int-post
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:115
Negated Boolean view.
Definition: view.hpp:1574
Post propagator for SetVar x
Definition: set.hh:767
Exception: Arguments are of different size
Definition: exception.hpp:73
@ RM_PMI
Inverse implication for reification.
Definition: int.hh:869
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
Passing integer variables.
Definition: int.hh:656
@ RM_IMP
Implication for reification.
Definition: int.hh:862
NodeType t
Type of node.
Definition: bool-expr.cpp:230
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Exception: Tuple set not yet finalized
Definition: exception.hpp:136
Exception: Not 0/1 integer
Definition: exception.hpp:51
Gecode toplevel namespace
Reification specification.
Definition: int.hh:876
Passing Boolean variables.
Definition: int.hh:712
@ RM_EQV
Equivalence for reification (default)
Definition: int.hh:855
Home class for posting propagators
Definition: core.hpp:856
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
Class represeting a set of tuples.
Definition: int.hh:2191
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:41