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