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, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-08-18 09:41:50 +0200 (Thu, 18 Aug 2011) $ by $Author: tack $
00011  *     $Revision: 12311 $
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 #include <gecode/int/rel.hh>
00039 #include <gecode/int/distinct.hh>
00040 
00041 namespace Gecode { namespace Int { namespace NValues {
00042 
00043   template<class VY>
00044   forceinline
00045   GqInt<VY>::GqInt(Home home, ValSet& vs, ViewArray<IntView>& x, VY y)
00046     : IntBase<VY>(home,vs,x,y) {}
00047 
00048   template<class VY>
00049   inline ExecStatus
00050   GqInt<VY>::post(Home home, ViewArray<IntView>& x, VY y) {
00051     if (x.size() == 0) {
00052       GECODE_ME_CHECK(y.lq(home,0));
00053       return ES_OK;
00054     }
00055 
00056     x.unique(home);
00057 
00058     if (x.size() == 1) {
00059       GECODE_ME_CHECK(y.lq(home,1));
00060       return ES_OK;
00061     }
00062 
00063     GECODE_ME_CHECK(y.lq(home,x.size()));
00064 
00065     if (y.max() <= 1)
00066       return ES_OK;
00067 
00068     if (y.min() == x.size()) {
00069       assert(y.assigned());
00070       return Distinct::Dom<IntView>::post(home,x);
00071     }
00072     
00073     // Eliminate assigned views and store them into the value set
00074     ValSet vs;
00075     int n = x.size();
00076     for (int i=n; i--; )
00077       if (x[i].assigned()) {
00078         vs.add(home, x[i].val());
00079         x[i] = x[--n];
00080       }
00081 
00082     GECODE_ME_CHECK(y.lq(home,n + vs.size()));
00083 
00084     if (n == 0) {
00085       assert(vs.size() >= y.max());
00086       return ES_OK;
00087     }
00088 
00089     x.size(n);
00090 
00091     (void) new (home) GqInt<VY>(home, vs, x, y);
00092     return ES_OK;
00093   }
00094     
00095   template<class VY>
00096   forceinline
00097   GqInt<VY>::GqInt(Space& home, bool share, GqInt<VY>& p)
00098     : IntBase<VY>(home, share, p) {}
00099 
00100   template<class VY>
00101   Propagator*
00102   GqInt<VY>::copy(Space& home, bool share) {
00103     return new (home) GqInt<VY>(home, share, *this);
00104   }
00105 
00106   template<class VY>
00107   ExecStatus
00108   GqInt<VY>::propagate(Space& home, const ModEventDelta& med) {
00109     if (IntView::me(med) == ME_INT_VAL)
00110       add(home);
00111 
00112     // Eliminate subsumed views
00113     eliminate(home);
00114 
00115     GECODE_ME_CHECK(y.lq(home, x.size() + vs.size()));
00116 
00117     if (x.size() == 0)
00118       return home.ES_SUBSUMED(*this);
00119 
00120     if (vs.size() >= y.max())
00121       return home.ES_SUBSUMED(*this);
00122       
00123     GECODE_ES_CHECK(prune_upper(home,g));
00124 
00125     return ES_NOFIX;
00126   }
00127   
00128 }}}
00129 
00130 // STATISTICS: int-prop