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

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