Generated on Sun Aug 26 2012 08:42:54 for Gecode by doxygen 1.8.1.1
int.hpp
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  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2005
9  * Mikael Lagerkvist, 2006
10  *
11  * Last modified:
12  * $Date: 2010-06-03 21:11:11 +1000 (Thu, 03 Jun 2010) $ by $Author: tack $
13  * $Revision: 11013 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 namespace Test { namespace Int {
41 
42  /*
43  * Assignments
44  *
45  */
46  inline
48  : n(n0), d(d0) {}
49  inline int
50  Assignment::size(void) const {
51  return n;
52  }
53  inline
55 
56 
57  inline
59  : Assignment(n,d),
60  dsv(new Gecode::IntSetValues[static_cast<unsigned int>(n)]) {
61  for (int i=n; i--; )
62  dsv[i].init(d);
63  }
64  inline bool
66  return dsv[0]();
67  }
68  inline int
70  assert((i>=0) && (i<n));
71  return dsv[i].val();
72  }
73  inline
75  delete [] dsv;
76  }
77 
78 
79  forceinline int
81  unsigned int skip = Base::rand(d.size());
82  for (Gecode::IntSetRanges it(d); true; ++it) {
83  if (it.width() > skip)
84  return it.min() + static_cast<int>(skip);
85  skip -= it.width();
86  }
88  return 0;
89  }
90 
91  inline
93  : Assignment(n,d), vals(new int[n]), a(a0) {
94  for (int i=n; i--; )
95  vals[i] = randval();
96  }
97 
98  inline bool
100  return a>0;
101  }
102  inline int
104  assert((i>=0) && (i<n));
105  return vals[i];
106  }
107  inline
109  delete [] vals;
110  }
111 
112  forceinline int
114  unsigned int skip = Base::rand(d.size());
115  for (Gecode::IntSetRanges it(d); true; ++it) {
116  if (it.width() > skip)
117  return it.min() + static_cast<int>(skip);
118  skip -= it.width();
119  }
120  GECODE_NEVER;
121  return 0;
122  }
123 
124  inline
126  int n1, const Gecode::IntSet& d1,
127  int a0)
128  : Assignment(n0+n1,d0),vals(new int[n0+n1]),a(a0),_n1(n1),_d1(d1) {
129  for (int i=n0; i--; )
130  vals[i] = randval(d);
131  for (int i=n1; i--; )
132  vals[n0+i] = randval(_d1);
133  }
134 
135  inline bool
137  return a>0;
138  }
139 
140  inline int
142  assert((i>=0) && (i<n));
143  return vals[i];
144  }
145 
146  inline
148  delete [] vals;
149  }
150 
151  /*
152  * Tests with integer constraints
153  *
154  */
155  inline
156  Test::Test(const std::string& s, int a, const Gecode::IntSet& d,
157  bool r, Gecode::IntConLevel i)
158  : Base("Int::"+s), arity(a), dom(d), reified(r), icl(i),
159  contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
160  testsearch(true), testfix(true) {}
161 
162  inline
163  Test::Test(const std::string& s, int a, int min, int max,
164  bool r, Gecode::IntConLevel i)
165  : Base("Int::"+s), arity(a), dom(min,max), reified(r), icl(i),
166  contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
167  testsearch(true), testfix(true) {}
168 
169  inline
170  std::string
172  using namespace Gecode;
173  switch (epk) {
174  case EPK_MEMORY: return "Memory";
175  case EPK_SPEED: return "Speed";
176  default: return "Def";
177  }
178  }
179 
180  inline
181  std::string
183  using namespace Gecode;
184  switch (icl) {
185  case ICL_VAL: return "Val";
186  case ICL_BND: return "Bnd";
187  case ICL_DOM: return "Dom";
188  default: return "Def";
189  }
190  }
191 
192  inline
193  std::string
195  using namespace Gecode;
196  switch (irt) {
197  case IRT_LQ: return "Lq";
198  case IRT_LE: return "Le";
199  case IRT_GQ: return "Gq";
200  case IRT_GR: return "Gr";
201  case IRT_EQ: return "Eq";
202  case IRT_NQ: return "Nq";
203  default: ;
204  }
205  GECODE_NEVER;
206  return "NONE";
207  }
208 
209  inline std::string
211  using namespace Gecode;
212  switch (bot) {
213  case BOT_AND: return "And";
214  case BOT_OR: return "Or";
215  case BOT_IMP: return "Imp";
216  case BOT_EQV: return "Eqv";
217  case BOT_XOR: return "Xor";
218  default: GECODE_NEVER;
219  }
220  GECODE_NEVER;
221  return "NONE";
222  }
223 
224  inline
225  std::string
226  Test::str(int i) {
227  std::stringstream s;
228  s << i;
229  return s.str();
230  }
231 
232  inline
233  std::string
235  std::string s = "";
236  for (int i=0; i<x.size()-1; i++)
237  s += str(x[i]) + ",";
238  return "[" + s + str(x[x.size()-1]) + "]";
239  }
240 
241  template<class T>
242  inline bool
244  using namespace Gecode;
245  switch (r) {
246  case IRT_EQ: return x == y;
247  case IRT_NQ: return x != y;
248  case IRT_LQ: return x <= y;
249  case IRT_LE: return x < y;
250  case IRT_GR: return x > y;
251  case IRT_GQ: return x >= y;
252  default: ;
253  }
254  return false;
255  }
256 
257 
258  inline
260  : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
261  inline bool
263  return i>=0;
264  }
265  inline void
267  i--;
268  }
269  inline Gecode::IntConLevel
270  IntConLevels::icl(void) const {
271  return icls[i];
272  }
273 
274 
275  inline
277  : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
278  inline void
280  i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
281  }
282  inline bool
284  return i>=0;
285  }
286  inline void
288  i--;
289  }
290  inline Gecode::IntRelType
291  IntRelTypes::irt(void) const {
292  return irts[i];
293  }
294 
295  inline
297  : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
298  inline bool
300  return i>=0;
301  }
302  inline void
304  i--;
305  }
306  inline Gecode::BoolOpType
307  BoolOpTypes::bot(void) const {
308  return bots[i];
309  }
310 
311 }}
312 
313 // STATISTICS: test-int
314