Generated on Wed Mar 19 07:29:56 2008 for Gecode by doxygen 1.5.5

arithmetic.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-25 00:16:01 +0100 (Mon, 25 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6288 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include "gecode/int/arithmetic.hh"
00039 
00040 namespace Gecode {
00041 
00042   using namespace Int;
00043 
00044   void
00045   abs(Space* home, IntVar x0, IntVar x1, IntConLevel cl, PropKind) {
00046     if (home->failed()) return;
00047     switch (cl) {
00048     case ICL_DOM:
00049       GECODE_ES_FAIL(home,Arithmetic::AbsDom<IntView>::post(home,x0,x1));
00050       break;
00051     default:
00052       GECODE_ES_FAIL(home,Arithmetic::AbsBnd<IntView>::post(home,x0,x1));
00053       break;
00054     }
00055   }
00056 
00057 
00058   void
00059   max(Space* home, IntVar x0, IntVar x1, IntVar x2, IntConLevel, PropKind) {
00060     if (home->failed()) return;
00061     GECODE_ES_FAIL(home,Arithmetic::Max<IntView>::post(home,x0,x1,x2));
00062   }
00063 
00064   void
00065   max(Space* home, const IntVarArgs& x, IntVar y, IntConLevel, PropKind) {
00066     if (x.size() == 0)
00067       throw TooFewArguments("Int::max");
00068     if (home->failed()) return;
00069     ViewArray<IntView> xv(home,x);
00070     GECODE_ES_FAIL(home,Arithmetic::NaryMax<IntView>::post(home,xv,y));
00071   }
00072 
00073 
00074   void
00075   min(Space* home, IntVar x0, IntVar x1, IntVar x2, IntConLevel, PropKind) {
00076     if (home->failed()) return;
00077     MinusView m0(x0); MinusView m1(x1); MinusView m2(x2);
00078     GECODE_ES_FAIL(home,Arithmetic::Max<MinusView>::post(home,m0,m1,m2));
00079   }
00080 
00081   void
00082   min(Space* home, const IntVarArgs& x, IntVar y, IntConLevel, PropKind) {
00083     if (x.size() == 0)
00084       throw TooFewArguments("Int::min");
00085     if (home->failed()) return;
00086     ViewArray<MinusView> m(home,x.size());
00087     for (int i=x.size(); i--; )
00088       m[i].init(x[i]);
00089     MinusView my(y);
00090     GECODE_ES_FAIL(home,Arithmetic::NaryMax<MinusView>::post(home,m,my));
00091   }
00092 
00093 
00094   void
00095   mult(Space* home, IntVar x0, IntVar x1, IntVar x2, IntConLevel, PropKind) {
00096     if (home->failed()) return;
00097     GECODE_ES_FAIL(home,Arithmetic::Mult<IntView>::post(home,x0,x1,x2));
00098   }
00099 
00100 
00101   void
00102   sqr(Space* home, IntVar x0, IntVar x1, IntConLevel, PropKind) {
00103     if (home->failed()) return;
00104     GECODE_ES_FAIL(home,Arithmetic::Sqr<IntView>::post(home,x0,x1));
00105   }
00106 
00107   void
00108   sqrt(Space* home, IntVar x0, IntVar x1, IntConLevel, PropKind) {
00109     if (home->failed()) return;
00110     GECODE_ES_FAIL(home,Arithmetic::Sqrt<IntView>::post(home,x0,x1));
00111   }
00112 
00113   namespace {
00114     GECODE_REGISTER1(Arithmetic::AbsBnd<IntView>);
00115     GECODE_REGISTER1(Arithmetic::AbsDom<IntView>);
00116     GECODE_REGISTER1(Arithmetic::Max<IntView>);
00117     GECODE_REGISTER1(Arithmetic::Max<MinusView>);
00118     GECODE_REGISTER1(Arithmetic::Mult<IntView>);
00119     GECODE_REGISTER1(Arithmetic::MultZeroOne<IntView>);
00120     GECODE_REGISTER4(Arithmetic::MultPlus<double,IntView,IntView,IntView>);
00121     GECODE_REGISTER4(Arithmetic::MultPlus<double,MinusView,IntView,MinusView>);
00122     GECODE_REGISTER4(Arithmetic::MultPlus<double,MinusView,MinusView,IntView>);
00123     GECODE_REGISTER4(Arithmetic::MultPlus<int,IntView,IntView,IntView>);
00124     GECODE_REGISTER4(Arithmetic::MultPlus<int,MinusView,IntView,MinusView>);
00125     GECODE_REGISTER4(Arithmetic::MultPlus<int,MinusView,MinusView,IntView>);
00126     GECODE_REGISTER1(Arithmetic::NaryMax<IntView>);
00127     GECODE_REGISTER1(Arithmetic::NaryMax<MinusView>);
00128     GECODE_REGISTER1(Arithmetic::Sqr<IntView>);
00129     GECODE_REGISTER2(Arithmetic::SqrPlus<IntView,IntView>);
00130     GECODE_REGISTER2(Arithmetic::SqrPlus<MinusView,IntView>);
00131     GECODE_REGISTER1(Arithmetic::Sqrt<IntView>);
00132   }
00133 }
00134 
00135 // STATISTICS: int-post
00136