Generated on Mon Aug 25 11:35:34 2008 for Gecode by doxygen 1.5.6

var-imp.icc

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  *  Contributing authors:
00007  *     Guido Tack <tack@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2002
00011  *     Guido Tack, 2004
00012  *
00013  *  Last modified:
00014  *     $Date: 2008-07-11 10:14:37 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00015  *     $Revision: 7316 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 #include <cmath>
00043 
00044 namespace Gecode { namespace Int {
00045 
00046   class IntVarImp;
00047   class BoolVarImp;
00048 
00055   class IntDelta : public Delta {
00056     friend class IntVarImp;
00057     friend class BoolVarImp;
00058   private:
00059     int _min; 
00060     int _max; 
00061   public:
00063     IntDelta(bool any=true);
00065     IntDelta(int min, int max);
00066   private:
00068     int min(void) const;
00070     int max(void) const;
00072     bool any(void) const;
00073   };
00074 
00075 }}
00076 
00077 #include "gecode/int/var-imp/delta.icc"
00078 
00079 namespace Gecode { namespace Int {
00080 
00081   class IntVarImpFwd;
00082   class IntVarImpBwd;
00083 
00089   class IntVarImp : public IntVarImpBase {
00090     friend class IntVarImpFwd;
00091     friend class IntVarImpBwd;
00092   protected:
00102     class RangeList : public FreeList {
00103     protected:
00105       int _min;
00107       int _max;
00108     public:
00110 
00111 
00112       RangeList(void);
00114       RangeList(int min, int max);
00116       RangeList(int min, int max, RangeList* p, RangeList* n);
00118 
00120 
00121 
00122       int min(void) const;
00124       int max(void) const;
00126       unsigned int width(void) const;
00127 
00129       RangeList* next(const RangeList* p) const;
00131       RangeList* prev(const RangeList* n) const;
00133 
00135 
00136 
00137       void min(int n);
00139       void max(int n);
00140 
00142       void prevnext(RangeList* p, RangeList* n);
00144       void next(RangeList* o, RangeList* n);
00146       void prev(RangeList* o, RangeList* n);
00148       void fix(RangeList* n);
00150 
00152 
00153 
00158       void dispose(Space* home, RangeList* p, RangeList* l);
00164       void dispose(Space* home, RangeList* l);
00166       void dispose(Space* home);
00167 
00169       static void* operator new(size_t s, Space* home);
00171       static void  operator delete(void*);
00173       static void  operator delete(void*, Space*);
00175     };
00176 
00184     RangeList dom;
00186     RangeList* _lst;
00188     RangeList* fst(void) const;
00190     void fst(RangeList* f);
00192     RangeList* lst(void) const;
00194     void lst(RangeList* l);
00196     unsigned int holes;
00197 
00198   protected:
00200     IntVarImp(Space* home, bool share, IntVarImp& x);
00201   public:
00203     IntVarImp(Space* home, int min, int max);
00205     IntVarImp(Space* home, const IntSet& d);
00206 
00208 
00209 
00210     int min(void) const;
00212     int max(void) const;
00214     int val(void) const;
00216     GECODE_INT_EXPORT int med(void) const;
00217 
00219     unsigned int size(void) const;
00221     unsigned int width(void) const;
00223     unsigned int regret_min(void) const;
00225     unsigned int regret_max(void) const;
00227 
00228   private:
00230     GECODE_INT_EXPORT bool in_full(int n) const;
00231 
00232   public:
00234 
00235 
00236     bool range(void) const;
00238     bool assigned(void) const;
00239 
00241     bool in(int n) const;
00243     bool in(double n) const;
00245 
00246   protected:
00248 
00249 
00250     const RangeList* ranges_fwd(void) const;
00252     const RangeList* ranges_bwd(void) const;
00254 
00255   private:
00257     bool closer_min(int b) const;
00259 
00260 
00261     GECODE_INT_EXPORT ModEvent lq_full(Space* home, int n);
00263     GECODE_INT_EXPORT ModEvent gq_full(Space* home, int n);
00265     GECODE_INT_EXPORT ModEvent eq_full(Space* home, int n);
00267     GECODE_INT_EXPORT ModEvent nq_full(Space* home, int n);
00269   public:
00271 
00272 
00273     ModEvent lq(Space* home, int n);
00275     ModEvent lq(Space* home, double n);
00276 
00278     ModEvent gq(Space* home, int n);
00280     ModEvent gq(Space* home, double n);
00281 
00283     ModEvent nq(Space* home, int n);
00285     ModEvent nq(Space* home, double n);
00286 
00288     ModEvent eq(Space* home, int n);
00290     ModEvent eq(Space* home, double n);
00292 
00309 
00310     template <class I> 
00311     ModEvent narrow_r(Space* home, I& i, bool depends=true);
00313     template <class I> 
00314     ModEvent inter_r(Space* home, I& i, bool depends=true);
00316     template <class I> 
00317     ModEvent minus_r(Space* home, I& i, bool depends=true);
00319     template <class I> 
00320     ModEvent narrow_v(Space* home, I& i, bool depends=true);
00322     template <class I> 
00323     ModEvent inter_v(Space* home, I& i, bool depends=true);
00325     template <class I> 
00326     ModEvent minus_v(Space* home, I& i, bool depends=true);
00328 
00330 
00331 
00339     void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00341     void cancel(Space* home, Propagator* p, PropCond pc);
00343     void subscribe(Space* home, Advisor* a);
00345     void cancel(Space* home, Advisor* a);
00347 
00349 
00350 
00351     static ModEventDelta med(ModEvent me);
00353 
00354 
00355   private:
00357     GECODE_INT_EXPORT IntVarImp* perform_copy(Space* home, bool share);
00358   public:
00360 
00361 
00362     IntVarImp* copy(Space* home, bool share);
00364 
00366 
00367 
00368     GECODE_INT_EXPORT Reflection::Arg*
00369     spec(const Space* home, Reflection::VarMap& m) const;
00371     static GECODE_INT_EXPORT VarImpBase*
00372     create(Space* home, Reflection::VarSpec& spec);
00374     static GECODE_INT_EXPORT void
00375     constrain(Space* home, VarImpBase* v, Reflection::VarSpec& spec);
00377 
00379 
00380 
00381     static ModEvent modevent(const Delta* d);
00383     int min(const Delta* d) const;
00385     int max(const Delta* d) const;
00387     bool any(const Delta* d) const;
00389   };
00390 
00391 
00396   class IntVarImpFwd {
00397   private:
00399     const IntVarImp::RangeList* p;
00401     const IntVarImp::RangeList* c;
00402   public:
00404 
00405 
00406     IntVarImpFwd(void);
00408     IntVarImpFwd(const IntVarImp* x);
00410     void init(const IntVarImp* x);
00412 
00414 
00415 
00416     bool operator()(void) const;
00418     void operator++(void);
00420 
00422 
00423 
00424     int min(void) const;
00426     int max(void) const;
00428     unsigned int width(void) const;
00430   };
00431 
00439   class IntVarImpBwd {
00440   private:
00442     const IntVarImp::RangeList* n;
00444     const IntVarImp::RangeList* c;
00445   public:
00447 
00448 
00449     IntVarImpBwd(void);
00451     IntVarImpBwd(const IntVarImp* x);
00453     void init(const IntVarImp* x);
00455 
00457 
00458 
00459     bool operator()(void) const;
00461     void operator++(void);
00463 
00465 
00466 
00467     int min(void) const;
00469     int max(void) const;
00471     unsigned int width(void) const;
00473   };
00474 
00475 }}
00476 
00477 #include "gecode/int/var-imp/int.icc"
00478 
00479 namespace Gecode {
00480   
00481   class IntVar;
00482   
00484   template <>
00485   class VarImpVarTraits<Int::IntVarImp> {
00486   public:
00487     typedef IntVar Var;
00488   };
00489   
00490   class BoolVar;
00491 }
00492 
00493 namespace Gecode { namespace Int {
00494 
00496   typedef unsigned int BoolStatus;
00497 
00503   class BoolVarImp : public BoolVarImpBase {
00504     friend class ::Gecode::BoolVar;
00505   private:
00517     GECODE_INT_EXPORT static BoolVarImp s_one;
00518     GECODE_INT_EXPORT static BoolVarImp s_zero;
00519 
00521     BoolVarImp(Space* home, bool share, BoolVarImp& x);
00523     BoolVarImp(int n);
00524   public:
00526     BoolVarImp(Space* home, int min, int max);
00527 
00529 
00530 
00531     static const int BITS = 2;
00533     static const BoolStatus ZERO = 0;
00535     static const BoolStatus ONE  = 3;
00537     static const BoolStatus NONE = 2;
00539     BoolStatus status(void) const;
00541 
00543 
00544 
00545     int min(void) const;
00547     int max(void) const;
00549     int val(void) const;
00551     int med(void) const;
00552 
00554     unsigned int size(void) const;
00556     unsigned int width(void) const;
00558     unsigned int regret_min(void) const;
00560     unsigned int regret_max(void) const;
00562 
00564 
00565 
00566     bool zero(void) const;
00568     bool one(void) const;
00570     bool none(void) const;
00572 
00574 
00575 
00576     bool range(void) const;
00578     bool assigned(void) const;
00579 
00581     bool in(int n) const;
00583     bool in(double n) const;
00585 
00587 
00588 
00589     ModEvent lq(Space* home, int n);
00591     ModEvent lq(Space* home, double n);
00592 
00594     ModEvent gq(Space* home, int n);
00596     ModEvent gq(Space* home, double n);
00597 
00599     ModEvent nq(Space* home, int n);
00601     ModEvent nq(Space* home, double n);
00602 
00604     ModEvent eq(Space* home, int n);
00606     ModEvent eq(Space* home, double n);
00608 
00625 
00626     template <class I> 
00627     ModEvent narrow_r(Space* home, I& i, bool depends=true);
00629     template <class I> 
00630     ModEvent inter_r(Space* home, I& i, bool depends=true);
00632     template <class I> 
00633     ModEvent minus_r(Space* home, I& i, bool depends=true);
00635     template <class I> 
00636     ModEvent narrow_v(Space* home, I& i, bool depends=true);
00638     template <class I> 
00639     ModEvent inter_v(Space* home, I& i, bool depends=true);
00641     template <class I> 
00642     ModEvent minus_v(Space* home, I& i, bool depends=true);
00644 
00646 
00647 
00648     ModEvent zero(Space* home);
00650     ModEvent one(Space* home);
00652     GECODE_INT_EXPORT ModEvent zero_none(Space* home);
00654     GECODE_INT_EXPORT ModEvent one_none(Space* home);
00656 
00657   public:
00659 
00660 
00670     void subscribe(Space* home, Propagator* p, PropCond pc, bool process=true);
00677     void cancel(Space* home, Propagator* p, PropCond pc);
00679     void subscribe(Space* home, Advisor* a);
00681     void cancel(Space* home, Advisor* a);
00683 
00685 
00686 
00693     static void schedule(Space* home, Propagator* p, ModEvent me);
00695     static ModEventDelta med(ModEvent me);
00697 
00699 
00700 
00701     static ModEvent modevent(const Delta* d);
00703     int min(const Delta* d) const;
00705     int max(const Delta* d) const;
00707     bool any(const Delta* d) const;
00709 
00711 
00712 
00713     BoolVarImp* copy(Space* home, bool share);
00715     
00717 
00718 
00719     GECODE_INT_EXPORT Reflection::Arg*
00720     spec(const Space* home, Reflection::VarMap& m) const;
00722     static GECODE_INT_EXPORT VarImpBase*
00723     create(Space* home, Reflection::VarSpec& spec);
00725     static GECODE_INT_EXPORT void
00726     constrain(Space* home, VarImpBase* v, Reflection::VarSpec& spec);
00728     
00729   };
00730 
00731 }}
00732 
00733 #include "gecode/int/var-imp/bool.icc"
00734 
00735 namespace Gecode {
00737   template <>
00738   class VarImpVarTraits<Int::BoolVarImp> {
00739   public:
00740     typedef BoolVar Var;
00741   };
00742 }
00743 
00744 // STATISTICS: int-var
00745