Generated on Thu Mar 22 10:39:36 2012 for Gecode by doxygen 1.6.3

cumulatives.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Mikael Lagerkvist, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-07-13 14:17:55 +0200 (Wed, 13 Jul 2011) $ by $Author: tack $
00011  *     $Revision: 12188 $
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/cumulatives.hh>
00039 
00040 namespace Gecode {
00041 
00042   using namespace Int;
00043 
00044   namespace {
00045     ViewArray<IntView>
00046     make_view_array(Space& home, const IntVarArgs& in) {
00047       return ViewArray<Int::IntView>(home, in);
00048     }
00049 
00050     ViewArray<ConstIntView>
00051     make_view_array(Space& home, const IntArgs& in) {
00052       ViewArray<Int::ConstIntView> res(home, in.size());
00053       for (int i = in.size(); i--; ) {
00054         Int::Limits::check(in[i],"Int::cumulatives");
00055         res[i] = Int::ConstIntView(in[i]);
00056       }
00057 
00058       return res;
00059     }
00060 
00061     template<class In> class ViewType;
00062 
00063     template<>
00064     class ViewType<IntArgs> {
00065     public:
00066       typedef Int::ConstIntView Result;
00067     };
00068 
00069     template<>
00070     class ViewType<IntVarArgs> {
00071     public:
00072       typedef Int::IntView Result;
00073     };
00074 
00075     template<class Machine, class Processing, class Usage>
00076     void
00077     post_cumulatives(Home home, const Machine& m,
00078                      const IntVarArgs& s, const Processing& p,
00079                      const IntVarArgs& e, const Usage& u,
00080                      const IntArgs& c, bool at_most,
00081                      IntConLevel) {
00082       if (m.size() != s.size()  ||
00083           s.size() != p.size() ||
00084           p.size() != e.size()   ||
00085           e.size() != u.size())
00086         throw Int::ArgumentSizeMismatch("Int::cumulatives");
00087       if (home.failed()) return;
00088 
00089       ViewArray<typename ViewType<Machine>::Result>
00090         vm  = make_view_array(home,  m);
00091       ViewArray<typename ViewType<Processing>::Result>
00092         vp = make_view_array(home, p);
00093       ViewArray<typename ViewType<Usage>::Result>
00094         vu   = make_view_array(home, u);
00095       ViewArray<IntView>
00096         vs    = make_view_array(home, s),
00097         ve    = make_view_array(home, e);
00098 
00099       SharedArray<int> c_s(c.size());
00100       for (int i=c.size(); i--;)
00101         c_s[i] = c[i];
00102 
00103       // There is only the value-consistent propagator for this constraint
00104       GECODE_ES_FAIL((Int::Cumulatives::Val<
00105                            typename ViewType<Machine>::Result,
00106                            typename ViewType<Processing>::Result,
00107                            typename ViewType<Usage>::Result,
00108                            IntView>::post(home, vm,vs,vp,ve,vu,c_s,at_most)));
00109 
00110     }
00111   }
00112 
00113   void
00114   cumulatives(Home home, const IntVarArgs& m,
00115               const IntVarArgs& s, const IntVarArgs& p,
00116               const IntVarArgs& e, const IntVarArgs& u,
00117               const IntArgs& c, bool at_most,
00118               IntConLevel cl) {
00119     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00120   }
00121 
00122   void
00123   cumulatives(Home home, const IntArgs& m,
00124               const IntVarArgs& s, const IntVarArgs& p,
00125               const IntVarArgs& e, const IntVarArgs& u,
00126               const IntArgs& c, bool at_most,
00127               IntConLevel cl) {
00128     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00129   }
00130 
00131   void
00132   cumulatives(Home home, const IntVarArgs& m,
00133               const IntVarArgs& s, const IntArgs& p,
00134               const IntVarArgs& e, const IntVarArgs& u,
00135               const IntArgs& c, bool at_most,
00136               IntConLevel cl) {
00137     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00138   }
00139 
00140   void
00141   cumulatives(Home home, const IntArgs& m,
00142               const IntVarArgs& s, const IntArgs& p,
00143               const IntVarArgs& e, const IntVarArgs& u,
00144               const IntArgs& c, bool at_most,
00145               IntConLevel cl) {
00146     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00147   }
00148 
00149   void
00150   cumulatives(Home home, const IntVarArgs& m,
00151               const IntVarArgs& s, const IntVarArgs& p,
00152               const IntVarArgs& e, const IntArgs& u,
00153               const IntArgs& c, bool at_most,
00154               IntConLevel cl) {
00155     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00156   }
00157 
00158   void
00159   cumulatives(Home home, const IntArgs& m,
00160               const IntVarArgs& s, const IntVarArgs& p,
00161               const IntVarArgs& e, const IntArgs& u,
00162               const IntArgs& c, bool at_most,
00163               IntConLevel cl) {
00164     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00165   }
00166 
00167   void
00168   cumulatives(Home home, const IntVarArgs& m,
00169               const IntVarArgs& s, const IntArgs& p,
00170               const IntVarArgs& e, const IntArgs& u,
00171               const IntArgs& c, bool at_most,
00172               IntConLevel cl) {
00173     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00174   }
00175 
00176   void
00177   cumulatives(Home home, const IntArgs& m,
00178               const IntVarArgs& s, const IntArgs& p,
00179               const IntVarArgs& e, const IntArgs& u,
00180               const IntArgs& c, bool at_most,
00181               IntConLevel cl) {
00182     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00183   }
00184 
00185 }
00186 
00187 // STATISTICS: int-post