Generated on Thu Apr 11 13:59:20 2019 for Gecode by doxygen 1.6.3

set.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2004
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include <gecode/set.hh>
00037 
00038 
00039 namespace Gecode { namespace Set {
00040 
00041   /*
00042    * "Standard" tell operations
00043    *
00044    */
00045   ModEvent
00046   SetVarImp::cardMin_full(Space& home) {
00047     ModEvent me = ME_SET_CARD;
00048     if (cardMin() == lub.size()) {
00049       glb.become(home, lub);
00050       me = ME_SET_VAL;
00051     }
00052     SetDelta d;
00053     return notify(home, me, d);
00054   }
00055 
00056   ModEvent
00057   SetVarImp::cardMax_full(Space& home) {
00058     ModEvent me = ME_SET_CARD;
00059     if (cardMax() == glb.size()) {
00060       lub.become(home, glb);
00061       me = ME_SET_VAL;
00062     }
00063     SetDelta d;
00064     return notify(home, me, d);
00065   }
00066 
00067   ModEvent
00068   SetVarImp::processLubChange(Space& home, SetDelta& d) {
00069     ModEvent me = ME_SET_LUB;
00070     if (cardMax() > lub.size()) {
00071       lub.card(lub.size());
00072       if (cardMin() > cardMax()) {
00073         glb.become(home, lub);
00074         glb.card(glb.size());
00075         lub.card(glb.size());
00076         return fail(home);
00077       }
00078       me = ME_SET_CLUB;
00079     }
00080     if (cardMax() == lub.size() && cardMin() == cardMax()) {
00081       glb.become(home, lub);
00082       me = ME_SET_VAL;
00083       assert(d.glbMin() == 1);
00084       assert(d.glbMax() == 0);
00085     }
00086     return notify(home, me, d);
00087   }
00088 
00089   ModEvent
00090   SetVarImp::processGlbChange(Space& home, SetDelta& d) {
00091     ModEvent me = ME_SET_GLB;
00092     if (cardMin() < glb.size()) {
00093       glb.card(glb.size());
00094       if (cardMin() > cardMax()) {
00095         glb.become(home, lub);
00096         glb.card(glb.size());
00097         lub.card(glb.size());
00098         return fail(home);
00099       }
00100       me = ME_SET_CGLB;
00101     }
00102     if (cardMin() == glb.size() && cardMin() == cardMax()) {
00103       lub.become(home, glb);
00104       me = ME_SET_VAL;
00105       assert(d.lubMin() == 1);
00106       assert(d.lubMax() == 0);
00107     }
00108     return notify(home, me, d);
00109   }
00110 
00111   /*
00112    * Copying variables
00113    *
00114    */
00115 
00116   forceinline
00117   SetVarImp::SetVarImp(Space& home, SetVarImp& x)
00118     : SetVarImpBase(home,x) {
00119     lub.update(home, x.lub);
00120     glb.card(x.cardMin());
00121     lub.card(x.cardMax());
00122     if (x.assigned()) {
00123       glb.become(home,lub);
00124     } else {
00125       glb.update(home,x.glb);
00126     }
00127   }
00128 
00129 
00130   SetVarImp*
00131   SetVarImp::perform_copy(Space& home) {
00132     return new (home) SetVarImp(home,*this);
00133   }
00134 
00135   /*
00136    * Dependencies
00137    *
00138    */
00139   void
00140   SetVarImp::subscribe(Space& home, Propagator& p, PropCond pc,
00141                        bool schedule) {
00142     SetVarImpBase::subscribe(home,p,pc,assigned(),schedule);
00143   }
00144   void
00145   SetVarImp::subscribe(Space& home, Advisor& a, bool fail) {
00146     SetVarImpBase::subscribe(home,a,assigned(),fail);
00147   }
00148   void
00149   SetVarImp::reschedule(Space& home, Propagator& p, PropCond pc) {
00150     SetVarImpBase::reschedule(home,p,pc,assigned());
00151   }
00152 
00153 
00154 }}
00155 
00156 // STATISTICS: set-var
00157