Generated on Sat Feb 7 2015 02:01:25 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
11  * $Revision: 13292 $
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 
38 #include <gecode/int/nvalues.hh>
39 #include <gecode/int/rel.hh>
40 
41 namespace Gecode {
42 
43  void
44  nvalues(Home home, const IntVarArgs& x, IntRelType irt, int y,
45  IntConLevel) {
46  using namespace Int;
47  Limits::check(y,"Int::nvalues");
48  // Due to the quadratic Boolean matrix used in propagation
49  long long int n = x.size();
50  Limits::check(n*n,"Int::nvalues");
51 
52  if (home.failed()) return;
53 
54  ViewArray<IntView> xv(home,x);
55 
56  switch (irt) {
57  case IRT_EQ:
58  {
59  ConstIntView yv(y);
61  }
62  break;
63  case IRT_NQ:
64  {
65  IntVar z(home,0,x.size());
66  GECODE_ME_FAIL(IntView(z).nq(home,y));
68  }
69  break;
70  case IRT_LE:
71  y--;
72  // Fall through
73  case IRT_LQ:
74  {
75  ConstIntView yv(y);
77  }
78  break;
79  case IRT_GR:
80  y++;
81  // Fall through
82  case IRT_GQ:
83  {
84  ConstIntView yv(y);
86  }
87  break;
88  default:
89  throw UnknownRelation("Int::nvalues");
90  }
91  }
92 
93  void
94  nvalues(Home home, const IntVarArgs& x, IntRelType irt, IntVar y,
95  IntConLevel) {
96  using namespace Int;
97  // Due to the quadratic Boolean matrix used in propagation
98  long long int n = x.size();
99  Limits::check(n*n,"Int::nvalues");
100 
101  if (home.failed()) return;
102 
103  if (y.assigned()) {
104  nvalues(home, x, irt, y.val());
105  return;
106  }
107 
108  ViewArray<IntView> xv(home,x);
109 
110  switch (irt) {
111  case IRT_EQ:
113  break;
114  case IRT_NQ:
115  {
116  IntVar z(home,0,x.size());
119  }
120  break;
121  case IRT_LE:
122  {
123  OffsetView z(y,-1);
125  }
126  break;
127  case IRT_LQ:
129  break;
130  case IRT_GR:
131  {
132  OffsetView z(y,1);
134  }
135  break;
136  case IRT_GQ:
138  break;
139  default:
140  throw UnknownRelation("Int::nvalues");
141  }
142  }
143 
144  void
145  nvalues(Home home, const BoolVarArgs& x, IntRelType irt, int y,
146  IntConLevel) {
147  using namespace Int;
148  Limits::check(y,"Int::nvalues");
149 
150  if (home.failed()) return;
151 
152  Region region(home);
153  ViewArray<BoolView> xv(region,x);
154 
155  switch (irt) {
156  case IRT_EQ:
157  {
158  ConstIntView yv(y);
160  }
161  break;
162  case IRT_NQ:
163  {
164  IntVar z(home,0,2);
165  GECODE_ME_FAIL(IntView(z).nq(home,y));
167  }
168  break;
169  case IRT_LE:
170  y--;
171  // Fall through
172  case IRT_LQ:
173  {
174  ConstIntView yv(y);
176  }
177  break;
178  case IRT_GR:
179  y++;
180  // Fall through
181  case IRT_GQ:
182  {
183  ConstIntView yv(y);
185  }
186  break;
187  default:
188  throw UnknownRelation("Int::nvalues");
189  }
190  }
191 
192  void
193  nvalues(Home home, const BoolVarArgs& x, IntRelType irt, IntVar y,
194  IntConLevel) {
195  using namespace Int;
196 
197  if (home.failed()) return;
198 
199  if (y.assigned()) {
200  nvalues(home, x, irt, y.val());
201  return;
202  }
203 
204  Region region(home);
205  ViewArray<BoolView> xv(region,x);
206 
207  switch (irt) {
208  case IRT_EQ:
210  break;
211  case IRT_NQ:
212  {
213  IntVar z(home,0,2);
216  }
217  break;
218  case IRT_LE:
219  {
220  OffsetView z(y,-1);
222  }
223  break;
224  case IRT_LQ:
226  break;
227  case IRT_GR:
228  {
229  OffsetView z(y,1);
231  }
232  break;
233  case IRT_GQ:
235  break;
236  default:
237  throw UnknownRelation("Int::nvalues");
238  }
239  }
240 
241 }
242 
243 // STATISTICS: int-post
244 
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
Greater or equal to number of values propagator for integer views.
Definition: nvalues.hh:257
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Less or equal to number of values propagator for Boolean views.
Definition: nvalues.hh:363
Less or equal ( )
Definition: int.hh:906
Equal to number of values propagator for integer views.
Definition: nvalues.hh:191
Handle to region.
Definition: region.hpp:61
Greater ( )
Definition: int.hh:909
Greater or equal ( )
Definition: int.hh:908
Exception: Unknown relation passed as argument
Definition: exception.hpp:91
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:904
IntRelType
Relation types for integers.
Definition: int.hh:903
Less ( )
Definition: int.hh:907
Offset integer view.
Definition: view.hpp:422
Passing integer variables.
Definition: int.hh:636
Passing Boolean variables.
Definition: int.hh:690
Less or equal to number of values propagator for integer views.
Definition: nvalues.hh:225
Constant integer view.
Definition: view.hpp:804
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Integer variables.
Definition: int.hh:350
Greater or equal to number of values propagator for Boolean views.
Definition: nvalues.hh:395
int val(void) const
Return assigned value.
Definition: int.hpp:60
Binary disequality propagator.
Definition: rel.hh:432
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:70
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:123
Equal to number of values propagator for Boolean views.
Definition: nvalues.hh:331
Gecode toplevel namespace
Disequality ( )
Definition: int.hh:905
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:50
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntConLevel)
Post propagator for .
Definition: nvalues.cpp:44