Generated on Fri Oct 19 11:25:02 2018 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  *  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>
00037   forceinline
00038   LqInt<VX,VY>::LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c)
00039     : IntBase<VX,VY>(home,x,n_s,y,c) {}
00040 
00041   template<class VX, class VY>
00042   ExecStatus
00043   LqInt<VX,VY>::post(Home home, ViewArray<VX>& x, VY y, int c) {
00044     // Eliminate decided views
00045     int n_x = x.size();
00046     for (int i=n_x; i--; )
00047       switch (holds(x[i],y)) {
00048       case RT_FALSE:
00049         x[i] = x[--n_x]; break;
00050       case RT_TRUE:
00051         x[i] = x[--n_x]; c--; break;
00052       case RT_MAYBE:
00053         break;
00054       default:
00055         GECODE_NEVER;
00056       }
00057     x.size(n_x);
00058     if (c < 0)
00059       return ES_FAILED;
00060     if (c >= n_x)
00061       return ES_OK;
00062     // All views must be different
00063     if (c == 0)
00064       return post_false(home,x,y);
00065     (void) new (home) LqInt<VX,VY>(home,x,n_x-c+1,y,c);
00066     return ES_OK;
00067   }
00068 
00069   template<class VX, class VY>
00070   forceinline
00071   LqInt<VX,VY>::LqInt(Space& home, LqInt<VX,VY>& p)
00072     : IntBase<VX,VY>(home,p) {}
00073 
00074   template<class VX, class VY>
00075   Actor*
00076   LqInt<VX,VY>::copy(Space& home) {
00077     return new (home) LqInt<VX,VY>(home,*this);
00078   }
00079 
00080   template<class VX, class VY>
00081   ExecStatus
00082   LqInt<VX,VY>::propagate(Space& home, const ModEventDelta&) {
00083     // Eliminate decided views from subscribed views
00084     int n_x = x.size();
00085     for (int i=n_s; i--; )
00086       switch (holds(x[i],y)) {
00087       case RT_FALSE:
00088         x[i].cancel(home,*this,PC_INT_DOM);
00089         x[i]=x[--n_s]; x[n_s]=x[--n_x];
00090         break;
00091       case RT_TRUE:
00092         x[i].cancel(home,*this,PC_INT_DOM);
00093         x[i]=x[--n_s]; x[n_s]=x[--n_x]; c--;
00094         break;
00095       case RT_MAYBE:
00096         break;
00097       default:
00098         GECODE_NEVER;
00099       }
00100     x.size(n_x);
00101     if (c < 0)
00102       return ES_FAILED;
00103     if (c >= n_x)
00104       return home.ES_SUBSUMED(*this);
00105     // Eliminate decided views from unsubscribed views
00106     for (int i=n_x; i-- > n_s; )
00107       switch (holds(x[i],y)) {
00108       case RT_FALSE: x[i]=x[--n_x]; break;
00109       case RT_TRUE:  x[i]=x[--n_x]; c--; break;
00110       case RT_MAYBE: break;
00111       default:       GECODE_NEVER;
00112       }
00113     x.size(n_x);
00114     if (c < 0)
00115       return ES_FAILED;
00116     if (c >= n_x)
00117       return home.ES_SUBSUMED(*this);
00118     if (c == 0) {
00119       // All views must be different
00120       GECODE_ES_CHECK(post_false(home,x,y));
00121       return home.ES_SUBSUMED(*this);
00122     }
00123     // Now, there must be new subscriptions from x[n_s] up to x[n_x-c+1]
00124     int m = n_x-c;
00125     while (n_s <= m)
00126       x[n_s++].subscribe(home,*this,PC_INT_DOM,false);
00127     return ES_FIX;
00128   }
00129 
00130 }}}
00131 
00132 // STATISTICS: int-prop