Generated on Sat Jan 20 2018 22:21:14 for Gecode by doxygen 1.8.13
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: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
11  * $Revision: 15073 $
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  IntPropLevel) {
45  using namespace Int;
46  if (c.size() == 0)
47  throw TooFewArguments("Int::element");
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  IntPropLevel) {
57  using namespace Int;
58  if (c.size() == 0)
59  throw TooFewArguments("Int::element");
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  IntPropLevel) {
69  using namespace Int;
70  if (c.size() == 0)
71  throw TooFewArguments("Int::element");
72  Limits::check(x1,"Int::element");
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  IntPropLevel ipl) {
84  using namespace Int;
85  if (c.size() == 0)
86  throw TooFewArguments("Int::element");
88  IdxViewArray<IntView> iv(home,c);
89  if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_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  IntPropLevel ipl) {
101  using namespace Int;
102  if (c.size() == 0)
103  throw TooFewArguments("Int::element");
104  Limits::check(x1,"Int::element");
105  GECODE_POST;
106  IdxViewArray<IntView> iv(home,c);
107  ConstIntView v1(x1);
108  if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_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  IntPropLevel) {
120  using namespace Int;
121  if (c.size() == 0)
122  throw TooFewArguments("Int::element");
123  GECODE_POST;
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  IntPropLevel) {
132  using namespace Int;
133  if (c.size() == 0)
134  throw TooFewArguments("Int::element");
135  Limits::check(x1,"Int::element");
136  GECODE_POST;
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  IntPropLevel ipl) {
157  using namespace Int;
158  if (a.size() != w*h)
159  throw Int::ArgumentSizeMismatch("Int::element");
160  GECODE_POST;
161  element(home, a, pair(home,x,w,y,h), z, ipl);
162  }
163 
164  void
166  IntVar x, int w, IntVar y, int h, BoolVar z,
167  IntPropLevel ipl) {
168  using namespace Int;
169  if (a.size() != w*h)
170  throw Int::ArgumentSizeMismatch("Int::element");
171  GECODE_POST;
172  element(home, a, pair(home,x,w,y,h), z, ipl);
173  }
174 
175  void
176  element(Home home, const IntVarArgs& a,
177  IntVar x, int w, IntVar y, int h, IntVar z,
178  IntPropLevel ipl) {
179  using namespace Int;
180  if (a.size() != w*h)
181  throw Int::ArgumentSizeMismatch("Int::element");
182  GECODE_POST;
183  element(home, a, pair(home,x,w,y,h), z, ipl);
184  }
185 
186  void
187  element(Home home, const BoolVarArgs& a,
188  IntVar x, int w, IntVar y, int h, BoolVar z,
189  IntPropLevel ipl) {
190  using namespace Int;
191  if (a.size() != w*h)
192  throw Int::ArgumentSizeMismatch("Int::element");
193  GECODE_POST;
194  element(home, a, pair(home,x,w,y,h), z, ipl);
195  }
196 
197 }
198 
199 // STATISTICS: int-post
Domain consistent element propagator for array of views.
Definition: element.hh:266
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition: ipl.hpp:41
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1669
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:47
Exception: Too few arguments available in argument array
Definition: exception.hpp:70
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int size(void) const
Return number of elements.
Simple propagation levels.
Definition: int.hh:957
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:784
Passing integer variables.
Definition: int.hh:639
Passing Boolean variables.
Definition: int.hh:693
Boolean integer variables.
Definition: int.hh:494
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:955
Constant integer view.
Definition: view.hpp:804
Gecode::IntArgs v1(4, Gecode::Int::Limits::min+4, 0, 1, Gecode::Int::Limits::max)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Integer variables.
Definition: int.hh:353
Domain propagation Preferences: prefer speed or memory.
Definition: int.hh:960
Post propagator for SetVar x
Definition: set.hh:784
Execution is okay.
Definition: core.hpp:544
void fail(void)
Mark space as failed.
Definition: core.hpp:4090
An array of IdxView pairs.
Definition: idx-view.hh:71
Gecode toplevel namespace
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:44
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:922
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:107
Shared array with arbitrary number of elements.
Bounds consistent element propagator for array of views.
Definition: element.hh:236
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
Definition: element.cpp:43
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.