Generated on Sat Apr 10 2021 00:00:00 for Gecode by doxygen 1.9.1
element.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, 2004
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/element.hh>
35 
36 namespace Gecode {
37 
38  void
40  IntPropLevel) {
41  using namespace Int;
42  if (c.size() == 0)
43  throw TooFewArguments("Int::element");
45  for (int i=0; i<c.size(); i++)
46  Limits::check(c[i],"Int::element");
47  GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
48  }
49 
50  void
52  IntPropLevel) {
53  using namespace Int;
54  if (c.size() == 0)
55  throw TooFewArguments("Int::element");
57  for (int i=0; i<c.size(); i++)
58  Limits::check(c[i],"Int::element");
59  GECODE_ES_FAIL((Element::post_int<IntView,BoolView>(home,c,x0,x1)));
60  }
61 
62  void
63  element(Home home, IntSharedArray c, IntVar x0, int x1,
64  IntPropLevel) {
65  using namespace Int;
66  if (c.size() == 0)
67  throw TooFewArguments("Int::element");
68  Limits::check(x1,"Int::element");
70  for (int i=0; i<c.size(); i++)
71  Limits::check(c[i],"Int::element");
72  ConstIntView cx1(x1);
74  (Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
75  }
76 
77  void
78  element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
79  IntPropLevel ipl) {
80  using namespace Int;
81  if (c.size() == 0)
82  throw TooFewArguments("Int::element");
84  IdxViewArray<IntView> iv(home,c);
85  if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
87  ::post(home,iv,x0,x1)));
88  } else {
90  ::post(home,iv,x0,x1)));
91  }
92  }
93 
94  void
95  element(Home home, const IntVarArgs& c, IntVar x0, int x1,
96  IntPropLevel ipl) {
97  using namespace Int;
98  if (c.size() == 0)
99  throw TooFewArguments("Int::element");
100  Limits::check(x1,"Int::element");
101  GECODE_POST;
102  IdxViewArray<IntView> iv(home,c);
103  ConstIntView v1(x1);
104  if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
106  ::post(home,iv,x0,v1)));
107  } else {
109  ::post(home,iv,x0,v1)));
110  }
111  }
112 
113  void
114  element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
115  IntPropLevel) {
116  using namespace Int;
117  if (c.size() == 0)
118  throw TooFewArguments("Int::element");
119  GECODE_POST;
120  IdxViewArray<BoolView> iv(home,c);
122  ::post(home,iv,x0,x1)));
123  }
124 
125  void
126  element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
127  IntPropLevel) {
128  using namespace Int;
129  if (c.size() == 0)
130  throw TooFewArguments("Int::element");
131  Limits::check(x1,"Int::element");
132  GECODE_POST;
133  IdxViewArray<BoolView> iv(home,c);
134  ConstIntView v1(x1);
136  ::post(home,iv,x0,v1)));
137  }
138 
139  namespace {
140  IntVar
141  pair(Home home, IntVar x, int w, IntVar y, int h) {
142  IntVar xy(home,0,w*h-1);
143  if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
144  home.fail();
145  return xy;
146  }
147  }
148 
149  void
151  IntVar x, int w, IntVar y, int h, IntVar z,
152  IntPropLevel ipl) {
153  using namespace Int;
154  if (a.size() != w*h)
155  throw Int::ArgumentSizeMismatch("Int::element");
156  GECODE_POST;
157  element(home, a, pair(home,x,w,y,h), z, ipl);
158  }
159 
160  void
162  IntVar x, int w, IntVar y, int h, BoolVar z,
163  IntPropLevel ipl) {
164  using namespace Int;
165  if (a.size() != w*h)
166  throw Int::ArgumentSizeMismatch("Int::element");
167  GECODE_POST;
168  element(home, a, pair(home,x,w,y,h), z, ipl);
169  }
170 
171  void
172  element(Home home, const IntVarArgs& a,
173  IntVar x, int w, IntVar y, int h, IntVar z,
174  IntPropLevel ipl) {
175  using namespace Int;
176  if (a.size() != w*h)
177  throw Int::ArgumentSizeMismatch("Int::element");
178  GECODE_POST;
179  element(home, a, pair(home,x,w,y,h), z, ipl);
180  }
181 
182  void
183  element(Home home, const BoolVarArgs& a,
184  IntVar x, int w, IntVar y, int h, BoolVar z,
185  IntPropLevel ipl) {
186  using namespace Int;
187  if (a.size() != w*h)
188  throw Int::ArgumentSizeMismatch("Int::element");
189  GECODE_POST;
190  element(home, a, pair(home,x,w,y,h), z, ipl);
191  }
192 
193 }
194 
195 // STATISTICS: int-post
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Passing Boolean variables.
Definition: int.hh:712
Boolean integer variables.
Definition: int.hh:512
Home class for posting propagators
Definition: core.hpp:856
Passing integer variables.
Definition: int.hh:656
Integer variables.
Definition: int.hh:371
Exception: Arguments are of different size
Definition: exception.hpp:73
Constant integer view.
Definition: view.hpp:851
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:43
Bounds consistent element propagator for array of views.
Definition: element.hh:232
Domain consistent element propagator for array of views.
Definition: element.hh:262
An array of IdxView pairs.
Definition: idx-view.hh:67
Exception: Too few arguments available in argument array
Definition: exception.hpp:66
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
Definition: element.cpp:39
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:238
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:979
@ IPL_DEF
Simple propagation levels.
Definition: int.hh:976
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition: ipl.hpp:37
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
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::IntArgs v1({Gecode::Int::Limits::min+4, 0, 1, Gecode::Int::Limits::max})