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

int-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, 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   GqInt<VX,VY>::GqInt(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   GqInt<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     // RHS too large
00063     if (n_x < c)
00064       return ES_FAILED;
00065     // Whatever the x[i] take for values, the inequality is subsumed
00066     if (c <= 0)
00067       return ES_OK;
00068     // All views must be equal
00069     if (c == n_x)
00070       return post_true(home,x,y);
00071     (void) new (home) GqInt<VX,VY>(home,x,c+1,y,c);
00072     return ES_OK;
00073   }
00074 
00075   template<class VX, class VY>
00076   forceinline
00077   GqInt<VX,VY>::GqInt(Space& home, bool share, GqInt<VX,VY>& p)
00078     : IntBase<VX,VY>(home,share,p) {}
00079 
00080   template<class VX, class VY>
00081   Actor*
00082   GqInt<VX,VY>::copy(Space& home, bool share) {
00083     return new (home) GqInt<VX,VY>(home,share,*this);
00084   }
00085 
00086   template<class VX, class VY>
00087   ExecStatus
00088   GqInt<VX,VY>::propagate(Space& home, const ModEventDelta&) {
00089     // Eliminate decided views from subscribed views
00090     int n_x = x.size();
00091     for (int i=n_s; i--; )
00092       switch (holds(x[i],y)) {
00093       case RT_FALSE:
00094         x[i].cancel(home,*this,PC_INT_DOM);
00095         x[i]=x[--n_s]; x[n_s]=x[--n_x];
00096         break;
00097       case RT_TRUE:
00098         x[i].cancel(home,*this,PC_INT_DOM);
00099         x[i]=x[--n_s]; x[n_s]=x[--n_x]; c--;
00100         break;
00101       case RT_MAYBE:
00102         break;
00103       default:
00104         GECODE_NEVER;
00105       }
00106     x.size(n_x);
00107     if (n_x < c)
00108       return ES_FAILED;
00109     if (c <= 0)
00110       return home.ES_SUBSUMED(*this);
00111     // Eliminate decided views from unsubscribed views
00112     for (int i=n_x; i-- > n_s; )
00113       switch (holds(x[i],y)) {
00114       case RT_FALSE: x[i]=x[--n_x]; break;
00115       case RT_TRUE:  x[i]=x[--n_x]; c--; break;
00116       case RT_MAYBE: break;
00117       default:       GECODE_NEVER;
00118       }
00119     x.size(n_x);
00120     if (n_x < c)
00121       return ES_FAILED;
00122     if (c <= 0)
00123       return home.ES_SUBSUMED(*this);
00124     if (c == n_x) {
00125       // All views must be equal
00126       GECODE_ES_CHECK(post_true(home,x,y)); 
00127       return home.ES_SUBSUMED(*this);
00128     }
00129     // Now, there must be new subscriptions from x[n_s] up to x[c+1]
00130     while (n_s <= c)
00131       x[n_s++].subscribe(home,*this,PC_INT_DOM,false);
00132     return ES_FIX;
00133   }
00134 
00135 }}}
00136 
00137 // STATISTICS: int-prop