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

var-imp.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  *  Contributing authors:
00007  *     Guido Tack <tack@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2002
00011  *     Guido Tack, 2004
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 <cmath>
00039 
00040 namespace Gecode { namespace Int {
00041 
00042   class IntVarImp;
00043   class BoolVarImp;
00044 
00051   class IntDelta : public Delta {
00052     friend class IntVarImp;
00053     friend class BoolVarImp;
00054   private:
00055     int _min; 
00056     int _max; 
00057   public:
00059     IntDelta(void);
00061     IntDelta(int min, int max);
00063     IntDelta(int min);
00064   private:
00066     int min(void) const;
00068     int max(void) const;
00070     unsigned int width(void) const;
00072     bool any(void) const;
00073   };
00074 
00075 }}
00076 
00077 #include <gecode/int/var-imp/delta.hpp>
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 new(size_t s, void* p);
00173       static void  operator delete(void*);
00175       static void  operator delete(void*, Space&);
00177       static void  operator delete(void*, void*);
00179     };
00180 
00188     RangeList dom;
00190     RangeList* _lst;
00192     RangeList* fst(void) const;
00194     void fst(RangeList* f);
00196     RangeList* lst(void) const;
00198     void lst(RangeList* l);
00200     unsigned int holes;
00201 
00202   protected:
00204     IntVarImp(Space& home, IntVarImp& x);
00205   public:
00207     IntVarImp(Space& home, int min, int max);
00209     IntVarImp(Space& home, const IntSet& d);
00210 
00212 
00213 
00214     int min(void) const;
00216     int max(void) const;
00218     int val(void) const;
00220     GECODE_INT_EXPORT int med(void) const;
00221 
00223     unsigned int size(void) const;
00225     unsigned int width(void) const;
00227     unsigned int regret_min(void) const;
00229     unsigned int regret_max(void) const;
00231 
00232   private:
00234     GECODE_INT_EXPORT bool in_full(int n) const;
00235 
00236   public:
00238 
00239 
00240     bool range(void) const;
00242     bool assigned(void) const;
00243 
00245     bool in(int n) const;
00247     bool in(long long int n) const;
00249 
00250   protected:
00252 
00253 
00254     const RangeList* ranges_fwd(void) const;
00256     const RangeList* ranges_bwd(void) const;
00258 
00259   private:
00261     bool closer_min(int b) const;
00263 
00264 
00265     GECODE_INT_EXPORT ModEvent lq_full(Space& home, int n);
00267     GECODE_INT_EXPORT ModEvent gq_full(Space& home, int n);
00269     GECODE_INT_EXPORT ModEvent eq_full(Space& home, int n);
00271     GECODE_INT_EXPORT ModEvent nq_full(Space& home, int n);
00273   public:
00275 
00276 
00277     ModEvent lq(Space& home, int n);
00279     ModEvent lq(Space& home, long long int n);
00280 
00282     ModEvent gq(Space& home, int n);
00284     ModEvent gq(Space& home, long long int n);
00285 
00287     ModEvent nq(Space& home, int n);
00289     ModEvent nq(Space& home, long long int n);
00290 
00292     ModEvent eq(Space& home, int n);
00294     ModEvent eq(Space& home, long long int n);
00296 
00313 
00314     template<class I>
00315     ModEvent narrow_r(Space& home, I& i, bool depends=true);
00317     template<class I>
00318     ModEvent inter_r(Space& home, I& i, bool depends=true);
00320     template<class I>
00321     ModEvent minus_r(Space& home, I& i, bool depends=true);
00323     template<class I>
00324     ModEvent narrow_v(Space& home, I& i, bool depends=true);
00326     template<class I>
00327     ModEvent inter_v(Space& home, I& i, bool depends=true);
00329     template<class I>
00330     ModEvent minus_v(Space& home, I& i, bool depends=true);
00332 
00334 
00335 
00343     GECODE_INT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00345     GECODE_INT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc);
00354     GECODE_INT_EXPORT void subscribe(Space& home, Advisor& a, bool fail);
00356 
00358 
00359 
00360     static ModEventDelta med(ModEvent me);
00362 
00363 
00364   private:
00366     GECODE_INT_EXPORT IntVarImp* perform_copy(Space& home);
00367   public:
00369 
00370 
00371     IntVarImp* copy(Space& home);
00373 
00375 
00376 
00377     static int min(const Delta& d);
00379     static int max(const Delta& d);
00381     static unsigned int width(const Delta& d);
00383     static bool any(const Delta& d);
00385   };
00386 
00387 
00392   class IntVarImpFwd {
00393   private:
00395     const IntVarImp::RangeList* p;
00397     const IntVarImp::RangeList* c;
00398   public:
00400 
00401 
00402     IntVarImpFwd(void);
00404     IntVarImpFwd(const IntVarImp* x);
00406     void init(const IntVarImp* x);
00408 
00410 
00411 
00412     bool operator ()(void) const;
00414     void operator ++(void);
00416 
00418 
00419 
00420     int min(void) const;
00422     int max(void) const;
00424     unsigned int width(void) const;
00426   };
00427 
00435   class IntVarImpBwd {
00436   private:
00438     const IntVarImp::RangeList* n;
00440     const IntVarImp::RangeList* c;
00441   public:
00443 
00444 
00445     IntVarImpBwd(void);
00447     IntVarImpBwd(const IntVarImp* x);
00449     void init(const IntVarImp* x);
00451 
00453 
00454 
00455     bool operator ()(void) const;
00457     void operator ++(void);
00459 
00461 
00462 
00463     int min(void) const;
00465     int max(void) const;
00467     unsigned int width(void) const;
00469   };
00470 
00471 }}
00472 
00473 #include <gecode/int/var-imp/int.hpp>
00474 
00475 namespace Gecode {
00476 
00477   class IntVar;
00478   class BoolVar;
00479 }
00480 
00481 namespace Gecode { namespace Int {
00482 
00484   typedef unsigned int BoolStatus;
00485 
00491   class BoolVarImp : public BoolVarImpBase {
00492     friend class ::Gecode::BoolVar;
00493   private:
00505     GECODE_INT_EXPORT static BoolVarImp s_one;
00506     GECODE_INT_EXPORT static BoolVarImp s_zero;
00507 
00509     BoolVarImp(Space& home, BoolVarImp& x);
00511     BoolVarImp(int n);
00512   public:
00514     BoolVarImp(Space& home, int min, int max);
00515 
00517 
00518 
00519     static const int BITS = 2;
00521     static const BoolStatus ZERO = 0;
00523     static const BoolStatus ONE  = 3;
00525     static const BoolStatus NONE = 2;
00527     BoolStatus status(void) const;
00529 
00531 
00532 
00533     int min(void) const;
00535     int max(void) const;
00537     int val(void) const;
00539     int med(void) const;
00540 
00542     unsigned int size(void) const;
00544     unsigned int width(void) const;
00546     unsigned int regret_min(void) const;
00548     unsigned int regret_max(void) const;
00550 
00552 
00553 
00554     bool zero(void) const;
00556     bool one(void) const;
00558     bool none(void) const;
00560 
00562 
00563 
00564     bool range(void) const;
00566     bool assigned(void) const;
00567 
00569     bool in(int n) const;
00571     bool in(long long int n) const;
00573 
00575 
00576 
00577     ModEvent lq(Space& home, int n);
00579     ModEvent lq(Space& home, long long int n);
00580 
00582     ModEvent gq(Space& home, int n);
00584     ModEvent gq(Space& home, long long int n);
00585 
00587     ModEvent nq(Space& home, int n);
00589     ModEvent nq(Space& home, long long int n);
00590 
00592     ModEvent eq(Space& home, int n);
00594     ModEvent eq(Space& home, long long int n);
00596 
00613 
00614     template<class I>
00615     ModEvent narrow_r(Space& home, I& i, bool depends=true);
00617     template<class I>
00618     ModEvent inter_r(Space& home, I& i, bool depends=true);
00620     template<class I>
00621     ModEvent minus_r(Space& home, I& i, bool depends=true);
00623     template<class I>
00624     ModEvent narrow_v(Space& home, I& i, bool depends=true);
00626     template<class I>
00627     ModEvent inter_v(Space& home, I& i, bool depends=true);
00629     template<class I>
00630     ModEvent minus_v(Space& home, I& i, bool depends=true);
00632 
00634 
00635 
00636     ModEvent zero(Space& home);
00638     ModEvent one(Space& home);
00640     GECODE_INT_EXPORT ModEvent zero_none(Space& home);
00642     GECODE_INT_EXPORT ModEvent one_none(Space& home);
00644 
00645   public:
00647 
00648 
00658     GECODE_INT_EXPORT void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
00665     void cancel(Space& home, Propagator& p, PropCond pc);
00674     GECODE_INT_EXPORT void subscribe(Space& home, Advisor& a, bool fail);
00676     void cancel(Space& home, Advisor& a, bool fail);
00678 
00680 
00681 
00688     static void schedule(Space& home, Propagator& p, ModEvent me);
00690     GECODE_INT_EXPORT void reschedule(Space& home, Propagator& p, PropCond pc);
00692     static ModEventDelta med(ModEvent me);
00694 
00696 
00697 
00698     static ModEvent modevent(const Delta& d);
00700     static int min(const Delta& d);
00702     static int max(const Delta& d);
00704     static unsigned int width(const Delta& d);
00706     static bool any(const Delta& d);
00708     static bool zero(const Delta& d);
00710     static bool one(const Delta& d);
00712 
00714 
00715 
00716     BoolVarImp* copy(Space& home);
00718 
00719   };
00720 
00721 }}
00722 
00723 #include <gecode/int/var-imp/bool.hpp>
00724 
00725 // STATISTICS: int-var
00726