Generated on Thu Mar 22 10:39:35 2012 for Gecode by doxygen 1.6.3

int-lq.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, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-08-29 14:59:24 +0200 (Mon, 29 Aug 2011) $ by $Author: schulte $
00011  *     $Revision: 12359 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Int { namespace Count {
00039 
00040   template<class VX, class VY>
00041   forceinline
00042   LqInt<VX,VY>::LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c)
00043     : IntBase<VX,VY>(home,x,n_s,y,c) {}
00044 
00045   template<class VX, class VY>
00046   ExecStatus
00047   LqInt<VX,VY>::post(Home home, ViewArray<VX>& x, VY y, int c) {
00048     // Eliminate decided views
00049     int n_x = x.size();
00050     for (int i=n_x; i--; )
00051       switch (holds(x[i],y)) {
00052       case RT_FALSE:
00053         x[i] = x[--n_x]; break;
00054       case RT_TRUE:
00055         x[i] = x[--n_x]; c--; break;
00056       case RT_MAYBE:
00057         break;
00058       default:
00059         GECODE_NEVER;
00060       }
00061     x.size(n_x);
00062     if (c < 0)
00063       return ES_FAILED;
00064     if (c >= n_x)
00065       return ES_OK;
00066     // All views must be different
00067     if (c == 0)
00068       return post_false(home,x,y);
00069     (void) new (home) LqInt<VX,VY>(home,x,n_x-c+1,y,c);
00070     return ES_OK;
00071   }
00072 
00073   template<class VX, class VY>
00074   forceinline
00075   LqInt<VX,VY>::LqInt(Space& home, bool share, LqInt<VX,VY>& p)
00076     : IntBase<VX,VY>(home,share,p) {}
00077 
00078   template<class VX, class VY>
00079   Actor*
00080   LqInt<VX,VY>::copy(Space& home, bool share) {
00081     return new (home) LqInt<VX,VY>(home,share,*this);
00082   }
00083 
00084   template<class VX, class VY>
00085   ExecStatus
00086   LqInt<VX,VY>::propagate(Space& home, const ModEventDelta&) {
00087     // Eliminate decided views from subscribed views
00088     int n_x = x.size();
00089     for (int i=n_s; i--; )
00090       switch (holds(x[i],y)) {
00091       case RT_FALSE:
00092         x[i].cancel(home,*this,PC_INT_DOM);
00093         x[i]=x[--n_s]; x[n_s]=x[--n_x];
00094         break;
00095       case RT_TRUE:
00096         x[i].cancel(home,*this,PC_INT_DOM);
00097         x[i]=x[--n_s]; x[n_s]=x[--n_x]; c--;
00098         break;
00099       case RT_MAYBE:
00100         break;
00101       default:
00102         GECODE_NEVER;
00103       }
00104     x.size(n_x);
00105     if (c < 0)
00106       return ES_FAILED;
00107     if (c >= n_x)
00108       return home.ES_SUBSUMED(*this);
00109     // Eliminate decided views from unsubscribed views
00110     for (int i=n_x; i-- > n_s; )
00111       switch (holds(x[i],y)) {
00112       case RT_FALSE: x[i]=x[--n_x]; break;
00113       case RT_TRUE:  x[i]=x[--n_x]; c--; break;
00114       case RT_MAYBE: break;
00115       default:       GECODE_NEVER;
00116       }
00117     x.size(n_x);
00118     if (c < 0)
00119       return ES_FAILED;
00120     if (c >= n_x)
00121       return home.ES_SUBSUMED(*this);
00122     if (c == 0) {
00123       // All views must be different
00124       GECODE_ES_CHECK(post_false(home,x,y));
00125       return home.ES_SUBSUMED(*this);
00126     }
00127     // Now, there must be new subscriptions from x[n_s] up to x[n_x-c+1]
00128     int m = n_x-c;
00129     while (n_s <= m)
00130       x[n_s++].subscribe(home,*this,PC_INT_DOM,false);
00131     return ES_FIX;
00132   }
00133 
00134 }}}
00135 
00136 // STATISTICS: int-prop