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