Generated on Tue May 22 09:39:57 2018 for Gecode by doxygen 1.6.3

man-prop.hpp

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  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2009
00009  *     Guido Tack, 2010
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 namespace Gecode { namespace Int { namespace Cumulative {
00037 
00038   template<class ManTask, class Cap, class PL>
00039   forceinline
00040   ManProp<ManTask,Cap,PL>::ManProp(Home home, Cap c0, TaskArray<ManTask>& t)
00041     : TaskProp<ManTask,PL>(home,t), c(c0) {
00042     c.subscribe(home,*this,PC_INT_BND);
00043   }
00044 
00045   template<class ManTask, class Cap, class PL>
00046   forceinline
00047   ManProp<ManTask,Cap,PL>::ManProp(Space& home, ManProp<ManTask,Cap,PL>& p)
00048     : TaskProp<ManTask,PL>(home,p) {
00049     c.update(home,p.c);
00050   }
00051 
00052   template<class ManTask, class Cap, class PL>
00053   ExecStatus
00054   ManProp<ManTask,Cap,PL>::post(Home home, Cap c, TaskArray<ManTask>& t) {
00055     // Capacity must be nonnegative
00056     GECODE_ME_CHECK(c.gq(home, 0));
00057     // Check that tasks do not overload resource
00058     for (int i=t.size(); i--; )
00059       if (t[i].c() > c.max())
00060         return ES_FAILED;
00061     if (t.size() == 1)
00062       GECODE_ME_CHECK(c.gq(home, t[0].c()));
00063     if (t.size() > 1) {
00064       if (c.assigned() && c.val()==1) {
00065         TaskArray<typename TaskTraits<ManTask>::UnaryTask> mt(home,t.size());
00066         for (int i=t.size(); i--; )
00067           mt[i]=t[i];
00068         return Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask,PL>
00069           ::post(home,mt);
00070       } else {
00071         (void) new (home) ManProp<ManTask,Cap,PL>(home,c,t);
00072       }
00073     }
00074     return ES_OK;
00075   }
00076 
00077   template<class ManTask, class Cap, class PL>
00078   Actor*
00079   ManProp<ManTask,Cap,PL>::copy(Space& home) {
00080     return new (home) ManProp<ManTask,Cap,PL>(home,*this);
00081   }
00082 
00083   template<class ManTask, class Cap, class PL>
00084   forceinline size_t
00085   ManProp<ManTask,Cap,PL>::dispose(Space& home) {
00086     (void) TaskProp<ManTask,PL>::dispose(home);
00087     c.cancel(home,*this,PC_INT_BND);
00088     return sizeof(*this);
00089   }
00090 
00091   template<class ManTask, class Cap, class PL>
00092   ExecStatus
00093   ManProp<ManTask,Cap,PL>::propagate(Space& home, const ModEventDelta& med) {
00094     // Only bounds changes?
00095     if (IntView::me(med) != ME_INT_DOM)
00096       GECODE_ES_CHECK(overload(home,c.max(),t));
00097 
00098     if (PL::advanced)
00099       GECODE_ES_CHECK(edgefinding(home,c.max(),t));
00100 
00101     if (PL::basic)
00102       GECODE_ES_CHECK(timetabling(home,*this,c,t));
00103 
00104     if (Cap::varderived() && c.assigned() && (c.val() == 1)) {
00105       // Check that tasks do not overload resource
00106       for (int i=t.size(); i--; )
00107         if (t[i].c() > 1)
00108           return ES_FAILED;
00109       // Rewrite to unary resource constraint
00110       TaskArray<typename TaskTraits<ManTask>::UnaryTask> ut(home,t.size());
00111       for (int i=t.size(); i--;)
00112         ut[i]=t[i];
00113       GECODE_REWRITE(*this,
00114         (Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask,PL>
00115           ::post(home(*this),ut)));
00116     }
00117 
00118     if (!PL::basic && c.assigned())
00119       GECODE_ES_CHECK(subsumed(home,*this,c.val(),t));
00120 
00121     return ES_NOFIX;
00122   }
00123 
00124 }}}
00125 
00126 // STATISTICS: int-prop