Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.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  * Last modified:
10  * $Date: 2015-01-16 14:10:48 +0100 (Fri, 16 Jan 2015) $ by $Author: schulte $
11  * $Revision: 14362 $
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/element.hh>
39 
40 namespace Gecode {
41 
42  void
44  IntConLevel) {
45  using namespace Int;
46  if (c.size() == 0)
47  throw TooFewArguments("Int::element");
48  if (home.failed()) return;
49  for (int i = c.size(); i--; )
50  Limits::check(c[i],"Int::element");
51  GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
52  }
53 
54  void
56  IntConLevel) {
57  using namespace Int;
58  if (c.size() == 0)
59  throw TooFewArguments("Int::element");
60  if (home.failed()) return;
61  for (int i = c.size(); i--; )
62  Limits::check(c[i],"Int::element");
63  GECODE_ES_FAIL((Element::post_int<IntView,BoolView>(home,c,x0,x1)));
64  }
65 
66  void
67  element(Home home, IntSharedArray c, IntVar x0, int x1,
68  IntConLevel) {
69  using namespace Int;
70  if (c.size() == 0)
71  throw TooFewArguments("Int::element");
72  Limits::check(x1,"Int::element");
73  if (home.failed()) return;
74  for (int i = c.size(); i--; )
75  Limits::check(c[i],"Int::element");
76  ConstIntView cx1(x1);
78  (Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
79  }
80 
81  void
82  element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
83  IntConLevel icl) {
84  using namespace Int;
85  if (c.size() == 0)
86  throw TooFewArguments("Int::element");
87  if (home.failed()) return;
88  IdxViewArray<IntView> iv(home,c);
89  if ((icl == ICL_DOM) || (icl == ICL_DEF)) {
91  ::post(home,iv,x0,x1)));
92  } else {
94  ::post(home,iv,x0,x1)));
95  }
96  }
97 
98  void
99  element(Home home, const IntVarArgs& c, IntVar x0, int x1,
100  IntConLevel icl) {
101  using namespace Int;
102  if (c.size() == 0)
103  throw TooFewArguments("Int::element");
104  Limits::check(x1,"Int::element");
105  if (home.failed()) return;
106  IdxViewArray<IntView> iv(home,c);
107  ConstIntView v1(x1);
108  if ((icl == ICL_DOM) || (icl == ICL_DEF)) {
110  ::post(home,iv,x0,v1)));
111  } else {
113  ::post(home,iv,x0,v1)));
114  }
115  }
116 
117  void
118  element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
119  IntConLevel) {
120  using namespace Int;
121  if (c.size() == 0)
122  throw TooFewArguments("Int::element");
123  if (home.failed()) return;
124  IdxViewArray<BoolView> iv(home,c);
126  ::post(home,iv,x0,x1)));
127  }
128 
129  void
130  element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
131  IntConLevel) {
132  using namespace Int;
133  if (c.size() == 0)
134  throw TooFewArguments("Int::element");
135  Limits::check(x1,"Int::element");
136  if (home.failed()) return;
137  IdxViewArray<BoolView> iv(home,c);
138  ConstIntView v1(x1);
140  ::post(home,iv,x0,v1)));
141  }
142 
143  namespace {
144  IntVar
145  pair(Home home, IntVar x, int w, IntVar y, int h) {
146  IntVar xy(home,0,w*h-1);
147  if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
148  home.fail();
149  return xy;
150  }
151  }
152 
153  void
155  IntVar x, int w, IntVar y, int h, IntVar z,
156  IntConLevel icl) {
157  using namespace Int;
158  if (a.size() != w*h)
159  throw Int::ArgumentSizeMismatch("Int::element");
160  if (home.failed()) return;
161  element(home, a, pair(home,x,w,y,h), z, icl);
162  }
163 
164  void
166  IntVar x, int w, IntVar y, int h, BoolVar z,
167  IntConLevel icl) {
168  using namespace Int;
169  if (a.size() != w*h)
170  throw Int::ArgumentSizeMismatch("Int::element");
171  if (home.failed()) return;
172  element(home, a, pair(home,x,w,y,h), z, icl);
173  }
174 
175  void
176  element(Home home, const IntVarArgs& a,
177  IntVar x, int w, IntVar y, int h, IntVar z,
178  IntConLevel icl) {
179  using namespace Int;
180  if (a.size() != w*h)
181  throw Int::ArgumentSizeMismatch("Int::element");
182  if (home.failed()) return;
183  element(home, a, pair(home,x,w,y,h), z, icl);
184  }
185 
186  void
187  element(Home home, const BoolVarArgs& a,
188  IntVar x, int w, IntVar y, int h, BoolVar z,
189  IntConLevel icl) {
190  using namespace Int;
191  if (a.size() != w*h)
192  throw Int::ArgumentSizeMismatch("Int::element");
193  if (home.failed()) return;
194  element(home, a, pair(home,x,w,y,h), z, icl);
195  }
196 
197 }
198 
199 // STATISTICS: int-post
Domain consistent element propagator for array of views.
Definition: element.hh:262
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:47
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Exception: Too few arguments available in argument array
Definition: exception.hpp:70
Gecode::IntArgs i(4, 1, 2, 3, 4)
int size(void) const
Return number of elements.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntConLevel)
Post domain consistent propagator for .
Definition: element.cpp:43
Passing integer variables.
Definition: int.hh:636
Passing Boolean variables.
Definition: int.hh:690
Boolean integer variables.
Definition: int.hh:491
Constant integer view.
Definition: view.hpp:804
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Integer variables.
Definition: int.hh:350
The default consistency for a constraint.
Definition: int.hh:941
Execution is okay.
Definition: core.hpp:527
An array of IdxView pairs.
Definition: idx-view.hh:71
Gecode toplevel namespace
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
Exception: Arguments are of different size
Definition: exception.hpp:77
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
Bounds consistent element propagator for array of views.
Definition: element.hh:232
Domain propagation or consistency.
Definition: int.hh:940