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

view-base.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>
00037   forceinline
00038   ViewBase<VX,VY,VZ>::ViewBase(Home home,
00039                                ViewArray<VX>& x0, VY y0, VZ z0, int c0)
00040     : Propagator(home), x(x0), y(y0), z(z0), c(c0) {
00041     if (isintset(y))
00042       home.notice(*this,AP_DISPOSE);
00043     x.subscribe(home,*this,PC_INT_DOM);
00044     subscribe(home,*this,y);
00045     z.subscribe(home,*this,PC_INT_BND);
00046   }
00047 
00048   template<class VX, class VY, class VZ>
00049   forceinline
00050   ViewBase<VX,VY,VZ>::ViewBase(Space& home, ViewBase<VX,VY,VZ>& p)
00051     : Propagator(home,p), c(p.c) {
00052     x.update(home,p.x);
00053     update(y,home,p.y);
00054     z.update(home,p.z);
00055   }
00056 
00057   template<class VX, class VY, class VZ>
00058   PropCost
00059   ViewBase<VX,VY,VZ>::cost(const Space&, const ModEventDelta&) const {
00060     return PropCost::linear(PropCost::LO,x.size()+1);
00061   }
00062 
00063   template<class VX, class VY, class VZ>
00064   void
00065   ViewBase<VX,VY,VZ>::reschedule(Space& home) {
00066     x.reschedule(home,*this,PC_INT_DOM);
00067     Gecode::Int::Count::reschedule(home,*this,y);
00068     z.reschedule(home,*this,PC_INT_BND);
00069   }
00070 
00071   template<class VX, class VY, class VZ>
00072   forceinline size_t
00073   ViewBase<VX,VY,VZ>::dispose(Space& home) {
00074     if (isintset(y))
00075       home.ignore(*this,AP_DISPOSE);
00076     x.cancel(home,*this,PC_INT_DOM);
00077     cancel(home,*this,y);
00078     z.cancel(home,*this,PC_INT_BND);
00079     (void) Propagator::dispose(home);
00080     return sizeof(*this);
00081   }
00082 
00083   template<class VX, class VY, class VZ>
00084   forceinline void
00085   ViewBase<VX,VY,VZ>::count(Space& home) {
00086     int n = x.size();
00087     for (int i=n; i--; )
00088       switch (holds(x[i],y)) {
00089       case RT_FALSE:
00090         x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n];
00091         break;
00092       case RT_TRUE:
00093         x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n];
00094         c--;
00095         break;
00096       case RT_MAYBE:
00097         break;
00098       default:
00099         GECODE_NEVER;
00100       }
00101     x.size(n);
00102   }
00103 
00104   template<class VX, class VY, class VZ>
00105   forceinline int
00106   ViewBase<VX,VY,VZ>::atleast(void) const {
00107     return -c;
00108   }
00109 
00110   template<class VX, class VY, class VZ>
00111   forceinline int
00112   ViewBase<VX,VY,VZ>::atmost(void) const {
00113     return x.size()-c;
00114   }
00115 
00116   template<class VX>
00117   forceinline bool
00118   shared(const IntSet&, VX) {
00119     return false;
00120   }
00121   template<class VX, class VY, class VZ>
00122   forceinline bool
00123   ViewBase<VX,VY,VZ>::sharing(const ViewArray<VX>& x,
00124                               const VY& y, const VZ& z) {
00125     if (shared(y,z))
00126       return true;
00127     for (int i=0; i<x.size(); i++)
00128       if (shared(x[i],z))
00129         return true;
00130     return false;
00131   }
00132 
00133 }}}
00134 
00135 // STATISTICS: int-prop