Generated on Tue Sep 16 2014 20:36:42 for Gecode by doxygen 1.8.8
arithmetic.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, 2002
8  *
9  * Last modified:
10  * $Date: 2012-09-03 17:08:20 +0200 (Mon, 03 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13038 $
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/arithmetic.hh>
39 
40 namespace Gecode {
41 
42  void
43  abs(Home home, IntVar x0, IntVar x1, IntConLevel icl) {
44  using namespace Int;
45  if (home.failed()) return;
46  if (icl == ICL_DOM) {
48  } else {
50  }
51  }
52 
53 
54  void
55  max(Home home, IntVar x0, IntVar x1, IntVar x2,
56  IntConLevel icl) {
57  using namespace Int;
58  if (home.failed()) return;
59  if (icl == ICL_DOM) {
61  } else {
63  }
64  }
65 
66  void
67  max(Home home, const IntVarArgs& x, IntVar y,
68  IntConLevel icl) {
69  using namespace Int;
70  if (x.size() == 0)
71  throw TooFewArguments("Int::max");
72  if (home.failed()) return;
73  ViewArray<IntView> xv(home,x);
74  if (icl == ICL_DOM) {
76  } else {
78  }
79  }
80 
81  void
82  min(Home home, IntVar x0, IntVar x1, IntVar x2,
83  IntConLevel icl) {
84  using namespace Int;
85  if (home.failed()) return;
86  MinusView m0(x0); MinusView m1(x1); MinusView m2(x2);
87  if (icl == ICL_DOM) {
89  } else {
91  }
92  }
93 
94  void
95  min(Home home, const IntVarArgs& x, IntVar y,
96  IntConLevel icl) {
97  using namespace Int;
98  if (x.size() == 0)
99  throw TooFewArguments("Int::min");
100  if (home.failed()) return;
101  ViewArray<MinusView> m(home,x.size());
102  for (int i=x.size(); i--; )
103  m[i] = MinusView(x[i]);
104  MinusView my(y);
105  if (icl == ICL_DOM) {
107  } else {
109  }
110  }
111 
112 
113  void
114  mult(Home home, IntVar x0, IntVar x1, IntVar x2,
115  IntConLevel icl) {
116  using namespace Int;
117  if (home.failed()) return;
118  if (icl == ICL_DOM) {
120  } else {
122  }
123  }
124 
125 
126  void
127  divmod(Home home, IntVar x0, IntVar x1, IntVar x2, IntVar x3,
128  IntConLevel) {
129  using namespace Int;
130  if (home.failed()) return;
131 
133  GECODE_ES_FAIL(Arithmetic::MultBnd::post(home,x1,x2,prod));
135  t[0].a = 1; t[0].x = prod;
136  t[1].a = 1; t[1].x = x3;
137  int min, max;
138  Linear::estimate(t,2,0,min,max);
139  IntView x0v(x0);
140  GECODE_ME_FAIL(x0v.gq(home,min));
141  GECODE_ME_FAIL(x0v.lq(home,max));
142  t[2].a=-1; t[2].x=x0;
143  Linear::post(home,t,3,IRT_EQ,0);
144  if (home.failed()) return;
145  IntView x1v(x1);
147  Arithmetic::DivMod<IntView>::post(home,x0,x1,x3));
148  }
149 
150  void
151  div(Home home, IntVar x0, IntVar x1, IntVar x2,
152  IntConLevel) {
153  using namespace Int;
154  if (home.failed()) return;
156  (Arithmetic::DivBnd<IntView>::post(home,x0,x1,x2)));
157  }
158 
159  void
160  mod(Home home, IntVar x0, IntVar x1, IntVar x2,
161  IntConLevel icl) {
162  using namespace Int;
163  if (home.failed()) return;
165  divmod(home, x0, x1, _div, x2, icl);
166  }
167 
168  void
169  sqr(Home home, IntVar x0, IntVar x1, IntConLevel icl) {
170  using namespace Int;
171  if (home.failed()) return;
172  Arithmetic::SqrOps ops;
173  if (icl == ICL_DOM) {
175  ::post(home,x0,x1,ops));
176  } else {
178  ::post(home,x0,x1,ops));
179  }
180  }
181 
182  void
183  sqrt(Home home, IntVar x0, IntVar x1, IntConLevel icl) {
184  using namespace Int;
185  if (home.failed()) return;
186  Arithmetic::SqrOps ops;
187  if (icl == ICL_DOM) {
189  ::post(home,x0,x1,ops));
190  } else {
192  ::post(home,x0,x1,ops));
193  }
194  }
195 
196  void
197  pow(Home home, IntVar x0, int n, IntVar x1, IntConLevel icl) {
198  using namespace Int;
199  Limits::nonnegative(n,"Int::pow");
200  if (home.failed()) return;
201  if (n == 2) {
202  sqr(home, x0, x1, icl);
203  return;
204  }
205  Arithmetic::PowOps ops(n);
206  if (icl == ICL_DOM) {
208  ::post(home,x0,x1,ops));
209  } else {
211  ::post(home,x0,x1,ops));
212  }
213  }
214 
215  void
216  nroot(Home home, IntVar x0, int n, IntVar x1, IntConLevel icl) {
217  using namespace Int;
218  Limits::positive(n,"Int::nroot");
219  if (home.failed()) return;
220  if (n == 2) {
221  sqrt(home, x0, x1, icl);
222  return;
223  }
224  Arithmetic::PowOps ops(n);
225  if (icl == ICL_DOM) {
227  ::post(home,x0,x1,ops));
228  } else {
230  ::post(home,x0,x1,ops));
231  }
232  }
233 
234 }
235 
236 // STATISTICS: int-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3369
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Integer division/modulo propagator.
Definition: arithmetic.hh:791
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:935
void mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:96
void mod(Home home, IntVar x0, IntVar x1, IntVar x2, IntConLevel icl)
Post propagator for .
Definition: arithmetic.cpp:160
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
Domain consistent ternary maximum propagator.
Definition: arithmetic.hh:187
Domain consistent n-th root propagator.
Definition: arithmetic.hh:537
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
void post(Home home, Term< BoolView > *t, int n, IntRelType irt, IntView x, int c, IntConLevel)
Post propagator for linear constraint over Booleans.
Definition: bool-post.cpp:608
int a
Coefficient.
Definition: linear.hh:1313
Domain consistent n-ary maximum propagator.
Definition: arithmetic.hh:222
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:49
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n 0$.
Definition: arithmetic.cpp:126
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n 0$.
Definition: arithmetic.cpp:117
Exception: Too few arguments available in argument array
Definition: exception.hpp:70
void nonnegative(int n, const char *l)
Check whether n is in range and nonnegative, otherwise throw out of limits with information l...
Definition: limits.hpp:72
Bounds consistent power propagator.
Definition: arithmetic.hh:352
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2)
Post propagator .
Definition: mult.cpp:148
const int max
Largest allowed integer value.
Definition: int.hh:111
const int min
Smallest allowed integer value.
Definition: int.hh:113
Bounds consistent absolute value propagator.
Definition: arithmetic.hh:62
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:902
Domain consistent absolute value propagator.
Definition: arithmetic.hh:95
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:103
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:110
Operations for square and square-root propagators.
Definition: arithmetic.hh:259
Bounds consistent n-ary maximum propagator.
Definition: arithmetic.hh:162
Passing integer variables.
Definition: int.hh:634
Bounds consistent division propagator.
Definition: arithmetic.hh:761
void divmod(Home home, IntVar x0, IntVar x1, IntVar x2, IntVar x3, IntConLevel)
Post propagator for .
Definition: arithmetic.cpp:127
Domain consistent power propagator.
Definition: arithmetic.hh:411
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Integer view for integer variables.
Definition: view.hpp:129
void div(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:135
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2)
Post propagator .
Definition: mult.cpp:315
Operations for power and nroot propagators.
Definition: arithmetic.hh:284
Bounds consistent ternary maximum propagator.
Definition: arithmetic.hh:134
Minus integer view.
Definition: view.hpp:276
Integer variables.
Definition: int.hh:348
void estimate(Term< View > *t, int n, int c, int &l, int &u)
Estimate lower and upper bounds.
Definition: post.hpp:45
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:70
Class for describing linear term .
Definition: linear.hh:1310
Gecode toplevel namespace
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
Bounds consistent n-th root propagator.
Definition: arithmetic.hh:477
void positive(int n, const char *l)
Check whether n is in range and strictly positive, otherwise throw out of limits with information l...
Definition: limits.hpp:61
Domain propagation or consistency.
Definition: int.hh:938