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