Generated on Thu Apr 11 13:59:07 2019 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <gecode/int/cumulatives.hh>
00035 
00036 namespace Gecode {
00037 
00038   using namespace Int;
00039 
00040   namespace {
00041     ViewArray<IntView>
00042     make_view_array(Space& home, const IntVarArgs& in) {
00043       return ViewArray<Int::IntView>(home, in);
00044     }
00045 
00046     ViewArray<ConstIntView>
00047     make_view_array(Space& home, const IntArgs& in) {
00048       ViewArray<Int::ConstIntView> res(home, in.size());
00049       for (int i=0; i<in.size(); i++) {
00050         Int::Limits::check(in[i],"Int::cumulatives");
00051         res[i] = Int::ConstIntView(in[i]);
00052       }
00053 
00054       return res;
00055     }
00056 
00057     template<class In> class ViewType;
00058 
00059     template<>
00060     class ViewType<IntArgs> {
00061     public:
00062       typedef Int::ConstIntView Result;
00063     };
00064 
00065     template<>
00066     class ViewType<IntVarArgs> {
00067     public:
00068       typedef Int::IntView Result;
00069     };
00070 
00071     template<class Machine, class Processing, class Usage>
00072     void
00073     post_cumulatives(Home home, const Machine& m,
00074                      const IntVarArgs& s, const Processing& p,
00075                      const IntVarArgs& e, const Usage& u,
00076                      const IntArgs& c, bool at_most,
00077                      IntPropLevel) {
00078       if (m.size() != s.size()  ||
00079           s.size() != p.size() ||
00080           p.size() != e.size()   ||
00081           e.size() != u.size())
00082         throw Int::ArgumentSizeMismatch("Int::cumulatives");
00083       GECODE_POST;
00084 
00085       ViewArray<typename ViewType<Machine>::Result>
00086         vm  = make_view_array(home,  m);
00087       ViewArray<typename ViewType<Processing>::Result>
00088         vp = make_view_array(home, p);
00089       ViewArray<typename ViewType<Usage>::Result>
00090         vu   = make_view_array(home, u);
00091       ViewArray<IntView>
00092         vs    = make_view_array(home, s),
00093         ve    = make_view_array(home, e);
00094 
00095       SharedArray<int> c_s(c.size());
00096       for (int i=0; i<c.size(); i++)
00097         c_s[i] = c[i];
00098 
00099       // There is only the value-consistent propagator for this constraint
00100       GECODE_ES_FAIL((Int::Cumulatives::Val<
00101                            typename ViewType<Machine>::Result,
00102                            typename ViewType<Processing>::Result,
00103                            typename ViewType<Usage>::Result,
00104                            IntView>::post(home, vm,vs,vp,ve,vu,c_s,at_most)));
00105 
00106     }
00107   }
00108 
00109   void
00110   cumulatives(Home home, const IntVarArgs& m,
00111               const IntVarArgs& s, const IntVarArgs& p,
00112               const IntVarArgs& e, const IntVarArgs& u,
00113               const IntArgs& c, bool at_most,
00114               IntPropLevel cl) {
00115     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00116   }
00117 
00118   void
00119   cumulatives(Home home, const IntArgs& m,
00120               const IntVarArgs& s, const IntVarArgs& p,
00121               const IntVarArgs& e, const IntVarArgs& u,
00122               const IntArgs& c, bool at_most,
00123               IntPropLevel cl) {
00124     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00125   }
00126 
00127   void
00128   cumulatives(Home home, const IntVarArgs& m,
00129               const IntVarArgs& s, const IntArgs& p,
00130               const IntVarArgs& e, const IntVarArgs& u,
00131               const IntArgs& c, bool at_most,
00132               IntPropLevel cl) {
00133     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00134   }
00135 
00136   void
00137   cumulatives(Home home, const IntArgs& m,
00138               const IntVarArgs& s, const IntArgs& p,
00139               const IntVarArgs& e, const IntVarArgs& u,
00140               const IntArgs& c, bool at_most,
00141               IntPropLevel cl) {
00142     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00143   }
00144 
00145   void
00146   cumulatives(Home home, const IntVarArgs& m,
00147               const IntVarArgs& s, const IntVarArgs& p,
00148               const IntVarArgs& e, const IntArgs& u,
00149               const IntArgs& c, bool at_most,
00150               IntPropLevel cl) {
00151     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00152   }
00153 
00154   void
00155   cumulatives(Home home, const IntArgs& m,
00156               const IntVarArgs& s, const IntVarArgs& p,
00157               const IntVarArgs& e, const IntArgs& u,
00158               const IntArgs& c, bool at_most,
00159               IntPropLevel cl) {
00160     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00161   }
00162 
00163   void
00164   cumulatives(Home home, const IntVarArgs& m,
00165               const IntVarArgs& s, const IntArgs& p,
00166               const IntVarArgs& e, const IntArgs& u,
00167               const IntArgs& c, bool at_most,
00168               IntPropLevel cl) {
00169     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00170   }
00171 
00172   void
00173   cumulatives(Home home, const IntArgs& m,
00174               const IntVarArgs& s, const IntArgs& p,
00175               const IntVarArgs& e, const IntArgs& u,
00176               const IntArgs& c, bool at_most,
00177               IntPropLevel cl) {
00178     post_cumulatives(home, m, s, p, e, u, c, at_most, cl);
00179   }
00180 
00181 }
00182 
00183 // STATISTICS: int-post