Generated on Tue Mar 5 2013 22:37:19 for Gecode by doxygen 1.8.3.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: 2010-03-04 03:40:32 +1100 (Thu, 04 Mar 2010) $ by $Author: schulte $
11  * $Revision: 10365 $
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  using namespace Int;
43 
44  void
46  IntConLevel) {
47  if (c.size() == 0)
48  throw TooFewArguments("Int::element");
49  if (home.failed()) return;
50  for (int i = c.size(); i--; )
51  Limits::check(c[i],"Int::element");
52  GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
53  }
54 
55  void
57  IntConLevel) {
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  if (c.size() == 0)
70  throw TooFewArguments("Int::element");
71  Limits::check(x1,"Int::element");
72  if (home.failed()) return;
73  for (int i = c.size(); i--; )
74  Limits::check(c[i],"Int::element");
75  ConstIntView cx1(x1);
77  (Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
78  }
79 
80  void
81  element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
82  IntConLevel icl) {
83  if (c.size() == 0)
84  throw TooFewArguments("Int::element");
85  if (home.failed()) return;
87  if ((icl == ICL_DOM) || (icl == ICL_DEF)) {
89  ::post(home,iv,x0,x1)));
90  } else {
92  ::post(home,iv,x0,x1)));
93  }
94  }
95 
96  void
97  element(Home home, const IntVarArgs& c, IntVar x0, int x1,
98  IntConLevel icl) {
99  if (c.size() == 0)
100  throw TooFewArguments("Int::element");
101  Limits::check(x1,"Int::element");
102  if (home.failed()) return;
104  ConstIntView v1(x1);
105  if ((icl == ICL_DOM) || (icl == ICL_DEF)) {
107  ::post(home,iv,x0,v1)));
108  } else {
110  ::post(home,iv,x0,v1)));
111  }
112  }
113 
114  void
115  element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
116  IntConLevel) {
117  if (c.size() == 0)
118  throw TooFewArguments("Int::element");
119  if (home.failed()) return;
122  ::post(home,iv,x0,x1)));
123  }
124 
125  void
126  element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
127  IntConLevel) {
128  if (c.size() == 0)
129  throw TooFewArguments("Int::element");
130  Limits::check(x1,"Int::element");
131  if (home.failed()) return;
133  ConstIntView v1(x1);
135  ::post(home,iv,x0,v1)));
136  }
137 
138  namespace {
139  IntVar
140  pair(Home home, IntVar x, int w, IntVar y, int h) {
141  IntVar xy(home,0,w*h-1);
142  if (Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
143  home.fail();
144  return xy;
145  }
146  }
147 
148  void
150  IntVar x, int w, IntVar y, int h, IntVar z,
151  IntConLevel icl) {
152  if (a.size() != w*h)
153  throw Int::ArgumentSizeMismatch("Int::element");
154  if (home.failed()) return;
155  element(home, a, pair(home,x,w,y,h), z, icl);
156  }
157 
158  void
160  IntVar x, int w, IntVar y, int h, BoolVar z,
161  IntConLevel icl) {
162  if (a.size() != w*h)
163  throw Int::ArgumentSizeMismatch("Int::element");
164  if (home.failed()) return;
165  element(home, a, pair(home,x,w,y,h), z, icl);
166  }
167 
168  void
169  element(Home home, const IntVarArgs& a,
170  IntVar x, int w, IntVar y, int h, IntVar z,
171  IntConLevel icl) {
172  if (a.size() != w*h)
173  throw Int::ArgumentSizeMismatch("Int::element");
174  if (home.failed()) return;
175  element(home, a, pair(home,x,w,y,h), z, icl);
176  }
177 
178  void
179  element(Home home, const BoolVarArgs& a,
180  IntVar x, int w, IntVar y, int h, BoolVar z,
181  IntConLevel icl) {
182  if (a.size() != w*h)
183  throw Int::ArgumentSizeMismatch("Int::element");
184  if (home.failed()) return;
185  element(home, a, pair(home,x,w,y,h), z, icl);
186  }
187 
188 }
189 
190 // STATISTICS: int-post