Generated on Thu Mar 22 10:39:36 2012 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: 2011-07-13 22:44:50 +0200 (Wed, 13 Jul 2011) $ by $Author: tack $
00013  *     $Revision: 12202 $
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>
00043   forceinline
00044   ManProp<ManTask,Cap>::ManProp(Home home, Cap c0, TaskArray<ManTask>& t)
00045     : TaskProp<ManTask,Int::PC_INT_DOM>(home,t), c(c0) {
00046     c.subscribe(home,*this,Int::PC_INT_BND);
00047   }
00048 
00049   template<class ManTask, class Cap>
00050   forceinline
00051   ManProp<ManTask,Cap>::ManProp(Space& home, bool shared, 
00052                                 ManProp<ManTask,Cap>& p) 
00053     : TaskProp<ManTask,Int::PC_INT_DOM>(home,shared,p) {
00054     c.update(home,shared,p.c);
00055   }
00056 
00057   template<class ManTask, class Cap>
00058   forceinline ExecStatus 
00059   ManProp<ManTask,Cap>::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>
00074           ::post(home,mt);
00075       } else {
00076         (void) new (home) ManProp<ManTask,Cap>(home,c,t);
00077       }
00078     }
00079     return ES_OK;
00080   }
00081 
00082   template<class ManTask, class Cap>
00083   Actor* 
00084   ManProp<ManTask,Cap>::copy(Space& home, bool share) {
00085     return new (home) ManProp<ManTask,Cap>(home,share,*this);
00086   }
00087 
00088   template<class ManTask, class Cap>  
00089   forceinline size_t 
00090   ManProp<ManTask,Cap>::dispose(Space& home) {
00091     (void) TaskProp<ManTask,Int::PC_INT_DOM>::dispose(home);
00092     c.cancel(home,*this,PC_INT_BND);
00093     return sizeof(*this);
00094   }
00095 
00096   template<class ManTask, class Cap>
00097   ExecStatus 
00098   ManProp<ManTask,Cap>::propagate(Space& home, const ModEventDelta& med) {
00099     // Only bounds changes?
00100     if (Int::IntView::me(med) != Int::ME_INT_DOM)
00101       GECODE_ES_CHECK(overload(home,c.max(),t));
00102     GECODE_ES_CHECK(edgefinding(home,c.max(),t));
00103     bool subsumed;
00104     ExecStatus es = basic(home,subsumed,c,t);
00105     GECODE_ES_CHECK(es);
00106     if (subsumed)
00107       return home.ES_SUBSUMED(*this);
00108     if (Cap::varderived() && c.assigned() && c.val()==1) {
00109       // Check that tasks do not overload resource
00110       for (int i=t.size(); i--; )
00111         if (t[i].c() > 1)
00112           return ES_FAILED;
00113       // Rewrite to unary resource constraint
00114       TaskArray<typename TaskTraits<ManTask>::UnaryTask> ut(home,t.size());
00115       for (int i=t.size(); i--;)
00116         ut[i]=t[i];
00117       GECODE_REWRITE(*this,
00118         (Unary::ManProp<typename TaskTraits<ManTask>::UnaryTask>
00119           ::post(home(*this),ut)));
00120     } else {
00121       return es;
00122     }
00123   }
00124 
00125 }}}
00126 
00127 // STATISTICS: int-prop