Generated on Thu Apr 11 13:59:06 2019 for Gecode by doxygen 1.6.3

view-gq.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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2003
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 namespace Gecode { namespace Int { namespace Count {
00035 
00036   template<class VX, class VY, class VZ, bool shr, bool dom>
00037   forceinline
00038   GqView<VX,VY,VZ,shr,dom>::GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c)
00039     : ViewBase<VX,VY,VZ>(home,x,y,z,c) {}
00040 
00041   template<class VX, class VY, class VZ, bool shr, bool dom>
00042   ExecStatus
00043   GqView<VX,VY,VZ,shr,dom>::post(Home home,
00044                                  ViewArray<VX>& x, VY y, VZ z, int c) {
00045     GECODE_ME_CHECK(z.lq(home,x.size()-c));
00046     if (isval(y) && z.assigned())
00047       return GqInt<VX,VY>::post(home,x,y,z.val()+c);
00048     if (sharing(x,y,z))
00049       (void) new (home) GqView<VX,VY,VZ,true,dom>(home,x,y,z,c);
00050     else
00051       (void) new (home) GqView<VX,VY,VZ,false,dom>(home,x,y,z,c);
00052     return ES_OK;
00053   }
00054 
00055   template<class VX, class VY, class VZ, bool shr, bool dom>
00056   forceinline
00057   GqView<VX,VY,VZ,shr,dom>::GqView(Space& home, GqView<VX,VY,VZ,shr,dom>& p)
00058     : ViewBase<VX,VY,VZ>(home,p) {}
00059 
00060   template<class VX, class VY, class VZ, bool shr, bool dom>
00061   Actor*
00062   GqView<VX,VY,VZ,shr,dom>::copy(Space& home) {
00063     return new (home) GqView<VX,VY,VZ,shr,dom>(home,*this);
00064   }
00065 
00066   template<class VX, class VY, class VZ, bool shr, bool dom>
00067   ExecStatus
00068   GqView<VX,VY,VZ,shr,dom>::propagate(Space& home, const ModEventDelta&) {
00069     count(home);
00070 
00071     GECODE_ME_CHECK(z.lq(home,atmost()));
00072 
00073     if (z.min() == atmost()) {
00074       GECODE_ES_CHECK(post_true(home,x,y));
00075       return home.ES_SUBSUMED(*this);
00076     }
00077     if (x.size() == 0)
00078       return home.ES_SUBSUMED(*this);
00079 
00080     if (z.assigned() && (!dom ||isval(y))) {
00081       VY yc(y);
00082       GECODE_REWRITE(*this,(GqInt<VX,VY>::post(home(*this),x,yc,z.val()+c)));
00083     }
00084 
00085     if (dom && !isval(y) && (z.min() > 0)) {
00086       /*
00087        * Only if the propagator is at fixpoint here, continue
00088        * when things are shared: the reason is that prune
00089        * requires that the views in x overlap with y!
00090        */
00091       if (shr && (VX::me(Propagator::modeventdelta()) != ME_INT_NONE))
00092         return ES_NOFIX;
00093 
00094       GECODE_ES_CHECK(prune(home,x,y));
00095 
00096       return ES_NOFIX;
00097     }
00098 
00099     return shr ? ES_NOFIX : ES_FIX;
00100   }
00101 
00102 }}}
00103 
00104 // STATISTICS: int-prop