Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
nvalues.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2011
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <gecode/int/nvalues.hh>
35 #include <gecode/int/rel.hh>
36 
37 namespace Gecode {
38 
39  void
40  nvalues(Home home, const IntVarArgs& x, IntRelType irt, int y,
41  IntPropLevel) {
42  using namespace Int;
43  Limits::check(y,"Int::nvalues");
44  // Due to the quadratic Boolean matrix used in propagation
45  long long int n = x.size();
46  Limits::check(n*n,"Int::nvalues");
47 
49 
50  ViewArray<IntView> xv(home,x);
51 
52  switch (irt) {
53  case IRT_EQ:
54  {
55  ConstIntView yv(y);
57  }
58  break;
59  case IRT_NQ:
60  {
61  IntVar z(home,0,x.size());
62  GECODE_ME_FAIL(IntView(z).nq(home,y));
64  }
65  break;
66  case IRT_LE:
67  y--;
68  // Fall through
69  case IRT_LQ:
70  {
71  ConstIntView yv(y);
73  }
74  break;
75  case IRT_GR:
76  y++;
77  // Fall through
78  case IRT_GQ:
79  {
80  ConstIntView yv(y);
82  }
83  break;
84  default:
85  throw UnknownRelation("Int::nvalues");
86  }
87  }
88 
89  void
90  nvalues(Home home, const IntVarArgs& x, IntRelType irt, IntVar y,
91  IntPropLevel) {
92  using namespace Int;
93  // Due to the quadratic Boolean matrix used in propagation
94  long long int n = x.size();
95  Limits::check(n*n,"Int::nvalues");
96 
98 
99  if (y.assigned()) {
100  nvalues(home, x, irt, y.val());
101  return;
102  }
103 
104  ViewArray<IntView> xv(home,x);
105 
106  switch (irt) {
107  case IRT_EQ:
109  break;
110  case IRT_NQ:
111  {
112  IntVar z(home,0,x.size());
115  }
116  break;
117  case IRT_LE:
118  {
119  OffsetView z(y,-1);
121  }
122  break;
123  case IRT_LQ:
125  break;
126  case IRT_GR:
127  {
128  OffsetView z(y,1);
130  }
131  break;
132  case IRT_GQ:
134  break;
135  default:
136  throw UnknownRelation("Int::nvalues");
137  }
138  }
139 
140  void
141  nvalues(Home home, const BoolVarArgs& x, IntRelType irt, int y,
142  IntPropLevel) {
143  using namespace Int;
144  Limits::check(y,"Int::nvalues");
145 
146  GECODE_POST;
147 
148  Region region;
149  ViewArray<BoolView> xv(region,x);
150 
151  switch (irt) {
152  case IRT_EQ:
153  {
154  ConstIntView yv(y);
156  }
157  break;
158  case IRT_NQ:
159  {
160  IntVar z(home,0,2);
161  GECODE_ME_FAIL(IntView(z).nq(home,y));
163  }
164  break;
165  case IRT_LE:
166  y--;
167  // Fall through
168  case IRT_LQ:
169  {
170  ConstIntView yv(y);
172  }
173  break;
174  case IRT_GR:
175  y++;
176  // Fall through
177  case IRT_GQ:
178  {
179  ConstIntView yv(y);
181  }
182  break;
183  default:
184  throw UnknownRelation("Int::nvalues");
185  }
186  }
187 
188  void
190  IntPropLevel) {
191  using namespace Int;
192 
193  GECODE_POST;
194 
195  if (y.assigned()) {
196  nvalues(home, x, irt, y.val());
197  return;
198  }
199 
200  Region region;
201  ViewArray<BoolView> xv(region,x);
202 
203  switch (irt) {
204  case IRT_EQ:
206  break;
207  case IRT_NQ:
208  {
209  IntVar z(home,0,2);
212  }
213  break;
214  case IRT_LE:
215  {
216  OffsetView z(y,-1);
218  }
219  break;
220  case IRT_LQ:
222  break;
223  case IRT_GR:
224  {
225  OffsetView z(y,1);
227  }
228  break;
229  case IRT_GQ:
231  break;
232  default:
233  throw UnknownRelation("Int::nvalues");
234  }
235  }
236 
237 }
238 
239 // STATISTICS: int-post
240 
Post propagator for SetVar x
Definition: set.hh:767
IntRelType
Relation types for integers.
Definition: int.hh:925
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Constant integer view.
Definition: view.hpp:851
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
@ IRT_GQ
Greater or equal ( )
Definition: int.hh:930
Passing integer variables.
Definition: int.hh:656
@ IRT_LE
Less ( )
Definition: int.hh:929
Equal to number of values propagator for integer views.
Definition: nvalues.hh:185
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:46
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Greater or equal to number of values propagator for Boolean views.
Definition: nvalues.hh:391
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:111
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel)
Post propagator for .
Definition: nvalues.cpp:40
Binary disequality propagator.
Definition: rel.hh:460
Equal to number of values propagator for Boolean views.
Definition: nvalues.hh:327
Gecode toplevel namespace
Passing Boolean variables.
Definition: int.hh:712
Home class for posting propagators
Definition: core.hpp:856
Handle to region.
Definition: region.hpp:55
Integer variables.
Definition: int.hh:371
Less or equal to number of values propagator for integer views.
Definition: nvalues.hh:219
Offset integer view.
Definition: view.hpp:443
Less or equal to number of values propagator for Boolean views.
Definition: nvalues.hh:359
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
Integer view for integer variables.
Definition: view.hpp:129
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:77
@ IRT_EQ
Equality ( )
Definition: int.hh:926
Exception: Unknown relation passed as argument
Definition: exception.hpp:87
@ IRT_NQ
Disequality ( )
Definition: int.hh:927
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
@ IRT_GR
Greater ( )
Definition: int.hh:931
@ IRT_LQ
Less or equal ( )
Definition: int.hh:928
Greater or equal to number of values propagator for integer views.
Definition: nvalues.hh:251