Generated on Thu Jul 6 07:06:47 2006 for Gecode by doxygen 1.4.7

imp.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004
00008  *     Christian Schulte, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $
00012  *     $Revision: 3188 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
00021  *
00022  */
00023 
00024 #include "gecode/set.hh"
00025 
00026 namespace Gecode { namespace Set {
00027 
00028   /*
00029    * "Standard" tell operations
00030    *
00031    */
00032   ModEvent
00033   SetVarImp::cardMin_full(Space* home,unsigned int newMin) {
00034     ModEvent me = ME_SET_CARD;
00035     if (_cardMin == _cardMax)
00036       me = checkLubCardAssigned(home,ME_SET_CARD);
00037     if (!me_failed(me))
00038       notify(home, me);
00039     return me;
00040   }
00041 
00042   ModEvent
00043   SetVarImp::cardMax_full(Space* home,unsigned int newMax) {
00044     ModEvent me = ME_SET_CARD;
00045     if (_cardMin == _cardMax)
00046       me = checkGlbCardAssigned(home,ME_SET_CARD);
00047     if (!me_failed(me))
00048       notify(home, me);
00049     return me;
00050   }
00051 
00052   ModEvent
00053   SetVarImp::processLubChange(Space* home) {
00054     if (!boundsConsistent()) {
00055       return ME_SET_FAILED;
00056     }
00057     ModEvent me;
00058     if (_cardMax > lub.size()) {
00059       _cardMax = lub.size();
00060       if (cardMin() > cardMax())
00061         return ME_SET_FAILED;
00062       if (assigned()) {
00063         lub.linkTo(home, glb);
00064         me = ME_SET_VAL;
00065       } else {
00066         me = checkLubCardAssigned(home, ME_SET_CLUB);
00067       }
00068     } else {
00069       me = checkLubCardAssigned(home, ME_SET_LUB);
00070     }
00071     if (!me_failed(me))
00072       notify(home, me);
00073     return me;
00074   }
00075 
00076   ModEvent
00077   SetVarImp::processGlbChange(Space* home) {
00078     if (!boundsConsistent())
00079       return ME_SET_FAILED;
00080     ModEvent me;
00081     if (_cardMin < glb.size()) {
00082       _cardMin = glb.size();
00083       if (cardMin() > cardMax())
00084         return ME_SET_FAILED;
00085       if (assigned()) {
00086         lub.linkTo(home, glb);
00087         me = ME_SET_VAL;
00088       } else {
00089         me = checkGlbCardAssigned(home, ME_SET_CGLB);
00090       }
00091     } else {
00092       me = checkGlbCardAssigned(home, ME_SET_GLB);
00093     }
00094     if (me!=ME_SET_FAILED)
00095       notify(home, me);
00096     return me;
00097   }
00098 
00099   /*
00100    * Copying variables
00101    *
00102    */
00103 
00104   forceinline
00105   SetVarImp::SetVarImp(Space* home, bool share, SetVarImp& x)
00106     : Variable<VTI_SET,PC_SET_ANY>(home,share,x),
00107       _cardMin(x._cardMin), _cardMax(x._cardMax) {
00108     lub.update(home, x.lub);
00109     if (x.assigned()) {
00110       glb.linkTo(home,lub);
00111     } else {
00112       glb.update(home,x.glb);
00113     }
00114   }
00115 
00116 
00117   SetVarImp*
00118   SetVarImp::perform_copy(Space* home, bool share) {
00119     return new (home) SetVarImp(home,share,*this);
00120   }
00121 
00122 
00123   /*
00124    * Finite Integer Set variable processor
00125    *
00126    */
00127 
00128   forceinline
00129   SetVarImp::Processor::Processor(void) {
00130     // Combination of modification events
00131     mec(ME_SET_CARD, ME_SET_LUB,  ME_SET_CLUB);
00132     mec(ME_SET_CARD, ME_SET_GLB,  ME_SET_CGLB);
00133     mec(ME_SET_CARD, ME_SET_BB,   ME_SET_CBB);
00134     mec(ME_SET_CARD, ME_SET_CLUB, ME_SET_CLUB);
00135     mec(ME_SET_CARD, ME_SET_CGLB, ME_SET_CGLB);
00136     mec(ME_SET_CARD, ME_SET_CBB,  ME_SET_CBB);
00137 
00138     mec(ME_SET_LUB,  ME_SET_GLB,  ME_SET_BB);
00139     mec(ME_SET_LUB,  ME_SET_BB,   ME_SET_BB);
00140     mec(ME_SET_LUB,  ME_SET_CLUB, ME_SET_CLUB);
00141     mec(ME_SET_LUB,  ME_SET_CGLB, ME_SET_CBB);
00142     mec(ME_SET_LUB,  ME_SET_CBB,  ME_SET_CBB);
00143 
00144     mec(ME_SET_GLB,  ME_SET_BB,   ME_SET_BB);
00145     mec(ME_SET_GLB,  ME_SET_CLUB, ME_SET_CBB);
00146     mec(ME_SET_GLB,  ME_SET_CGLB, ME_SET_CGLB);
00147     mec(ME_SET_GLB,  ME_SET_CBB,  ME_SET_CBB);
00148 
00149     mec(ME_SET_BB,   ME_SET_CLUB, ME_SET_CBB);
00150     mec(ME_SET_BB,   ME_SET_CGLB, ME_SET_CBB);
00151     mec(ME_SET_BB,   ME_SET_CBB,  ME_SET_CBB);
00152 
00153     mec(ME_SET_CLUB, ME_SET_CGLB, ME_SET_CBB);
00154     mec(ME_SET_CLUB, ME_SET_CBB,  ME_SET_CBB);
00155 
00156     mec(ME_SET_CGLB, ME_SET_CBB,  ME_SET_CBB);
00157 
00158     // Mapping between modification events and propagation conditions
00159     mepc(ME_SET_CARD, PC_SET_CARD); mepc(ME_SET_CARD, PC_SET_CGLB);
00160     mepc(ME_SET_CARD, PC_SET_CLUB); mepc(ME_SET_CARD, PC_SET_ANY);
00161 
00162     mepc(ME_SET_LUB,  PC_SET_CLUB); mepc(ME_SET_LUB,  PC_SET_ANY);
00163 
00164     mepc(ME_SET_GLB,  PC_SET_CGLB); mepc(ME_SET_GLB,  PC_SET_ANY);
00165 
00166     mepc(ME_SET_BB,   PC_SET_CGLB); mepc(ME_SET_BB,   PC_SET_CLUB);
00167     mepc(ME_SET_BB,   PC_SET_ANY);
00168 
00169     mepc(ME_SET_CLUB, PC_SET_CARD); mepc(ME_SET_CLUB, PC_SET_CGLB);
00170     mepc(ME_SET_CLUB, PC_SET_CLUB); mepc(ME_SET_CLUB, PC_SET_ANY);
00171 
00172     mepc(ME_SET_CGLB, PC_SET_CARD); mepc(ME_SET_CGLB, PC_SET_CGLB);
00173     mepc(ME_SET_CGLB, PC_SET_CLUB); mepc(ME_SET_CGLB, PC_SET_ANY);
00174 
00175     mepc(ME_SET_CBB,  PC_SET_CARD); mepc(ME_SET_CBB,  PC_SET_CGLB);
00176     mepc(ME_SET_CBB,  PC_SET_CLUB); mepc(ME_SET_CBB,  PC_SET_ANY);
00177     // Transfer to kernel
00178     enter();
00179   }
00180 
00181   SetVarImp::Processor SetVarImp::svp;
00182 
00183 
00184   /*
00185    * Subscribing to variables
00186    *
00187    */
00188 
00189   void
00190   SetVarImp::subscribe(Space* home, Propagator* p, PropCond pc) {
00191     Variable<VTI_SET,PC_SET_ANY>::subscribe(home,p,pc,
00192                                             assigned(), ME_SET_CBB);
00193   }
00194 
00195 }}
00196 
00197 // STATISTICS: set-var
00198