Generated on Wed Jan 4 17:49:13 2006 for Gecode by doxygen 1.4.6

minimodel.hh (Revision: 2634)

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2004
00008  *     Guido Tack, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2005-11-24 11:56:33 +0100 (Thu, 24 Nov 2005) $ by $Author: schulte $
00012  *     $Revision: 2634 $
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 #ifndef __GECODE_MINIMODEL_HH__
00025 #define __GECODE_MINIMODEL_HH__
00026 
00027 #include "./kernel.hh"
00028 #include "./int.hh"
00029 #include "./int/linear.hh"
00030 
00031 #include "./minimodel/exception.icc"
00032 
00033 #include <iostream>
00034 
00035 /*
00036  * Support for DLLs under Windows
00037  *
00038  */
00039 
00040 #if !defined(GECODE_STATIC_LIBS) && \
00041     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00042 
00043 #ifdef GECODE_BUILD_MINIMODEL
00044 #define GECODE_MINIMODEL_EXPORT __declspec( dllexport )
00045 #else
00046 #define GECODE_MINIMODEL_EXPORT __declspec( dllimport )
00047 #endif
00048 
00049 #else
00050 
00051 #define GECODE_MINIMODEL_EXPORT
00052 
00053 #endif
00054 
00055 namespace Gecode {
00056 
00058   namespace MiniModel {
00059 
00061     class LinExpr {
00062     private:
00064       class Node {
00065       private:
00067         unsigned int use;
00069         Node *left, *right;
00071         int signLeft, signRight;
00073         int a;
00075         IntVar x;
00076       public:
00078         Node(int a, const IntVar& x);
00080         Node(Node* n0, int s0, Node* n1, int s1);
00081 
00083         void increment(void);
00085         GECODE_MINIMODEL_EXPORT bool decrement(void);
00086         
00088         GECODE_MINIMODEL_EXPORT int
00089         fill(Int::Linear::Term t[], int i, int s) const;
00090         
00092         static void* operator new(size_t size);
00094         static void  operator delete(void* p,size_t size);
00095       };
00096       Node* ax;       
00097     public:
00098       unsigned int n; 
00099       int c;          
00100       int sign;       
00101 
00102       LinExpr(void);
00104       LinExpr(const LinExpr& e);
00106       LinExpr(const IntVar& x, int a=1, int c=0);
00108       LinExpr(const LinExpr& e0, const LinExpr& e1, int s);
00110       LinExpr(const LinExpr& e, int c, int s);
00112       LinExpr(int a, const LinExpr& e);
00114       const LinExpr& operator=(const LinExpr& e);
00116       GECODE_MINIMODEL_EXPORT
00117       void post(Space* home, IntRelType irt) const;
00119       GECODE_MINIMODEL_EXPORT
00120       void post(Space* home, IntRelType irt, const BoolVar& b) const;
00122       GECODE_MINIMODEL_EXPORT
00123       IntVar post(Space* home) const;
00125       ~LinExpr(void);
00126     };
00127 
00129     class LinRel {
00130     private:
00132       LinExpr    e;
00134       IntRelType irt;
00136       static IntRelType neg(IntRelType irt);
00137     public:
00139       LinRel(void);
00141       LinRel(const LinExpr& l, IntRelType irt, const LinExpr& r);
00143       LinRel(const LinExpr& l, IntRelType irt, int r);
00145       LinRel(int l, IntRelType irt, const LinExpr& r);
00147       void post(Space* home, bool t=true) const;
00149       void post(Space* home, const BoolVar& b) const;
00150     };
00151 
00152   }
00153 
00154 }
00155 
00173 
00175 Gecode::MiniModel::LinExpr
00176 operator+(int,
00177           const Gecode::MiniModel::LinExpr&);
00179 Gecode::MiniModel::LinExpr
00180 operator+(const Gecode::MiniModel::LinExpr&,
00181           int);
00183 Gecode::MiniModel::LinExpr
00184 operator+(const Gecode::MiniModel::LinExpr&,
00185           const Gecode::MiniModel::LinExpr&);
00186 
00188 Gecode::MiniModel::LinExpr
00189 operator-(int,
00190           const Gecode::MiniModel::LinExpr&);
00192 Gecode::MiniModel::LinExpr
00193 operator-(const Gecode::MiniModel::LinExpr&,
00194           int);
00196 Gecode::MiniModel::LinExpr
00197 operator-(const Gecode::MiniModel::LinExpr&,
00198           const Gecode::MiniModel::LinExpr&);
00199 
00201 Gecode::MiniModel::LinExpr
00202 operator-(const Gecode::MiniModel::LinExpr&);
00203 
00204 
00206 Gecode::MiniModel::LinExpr
00207 operator*(int, const Gecode::IntVar&);
00209 Gecode::MiniModel::LinExpr
00210 operator*(const Gecode::IntVar&, int);
00212 Gecode::MiniModel::LinExpr
00213 operator*(const Gecode::MiniModel::LinExpr&, int);
00215 Gecode::MiniModel::LinExpr
00216 operator*(int, const Gecode::MiniModel::LinExpr&);
00217 
00218 
00220 Gecode::MiniModel::LinRel
00221 operator==(int l,
00222            const Gecode::MiniModel::LinExpr& r);
00224 Gecode::MiniModel::LinRel
00225 operator==(const Gecode::MiniModel::LinExpr& l,
00226            int r);
00228 Gecode::MiniModel::LinRel
00229 operator==(const Gecode::MiniModel::LinExpr& l,
00230            const Gecode::MiniModel::LinExpr& r);
00231 
00233 Gecode::MiniModel::LinRel
00234 operator!=(int l,
00235            const Gecode::MiniModel::LinExpr& r);
00237 Gecode::MiniModel::LinRel
00238 operator!=(const Gecode::MiniModel::LinExpr& l,
00239            int r);
00241 Gecode::MiniModel::LinRel
00242 operator!=(const Gecode::MiniModel::LinExpr& l,
00243            const Gecode::MiniModel::LinExpr& r);
00244 
00246 Gecode::MiniModel::LinRel
00247 operator<(int l,
00248           const Gecode::MiniModel::LinExpr& r);
00250 Gecode::MiniModel::LinRel
00251 operator<(const Gecode::MiniModel::LinExpr& l,
00252           int r);
00254 Gecode::MiniModel::LinRel
00255 operator<(const Gecode::MiniModel::LinExpr& l,
00256           const Gecode::MiniModel::LinExpr& r);
00257 
00259 Gecode::MiniModel::LinRel
00260 operator<=(int l,
00261            const Gecode::MiniModel::LinExpr& r);
00263 Gecode::MiniModel::LinRel
00264 operator<=(const Gecode::MiniModel::LinExpr& l,
00265            int r);
00267 Gecode::MiniModel::LinRel
00268 operator<=(const Gecode::MiniModel::LinExpr& l,
00269            const Gecode::MiniModel::LinExpr& r);
00270 
00272 Gecode::MiniModel::LinRel
00273 operator>(int l,
00274           const Gecode::MiniModel::LinExpr& r);
00276 Gecode::MiniModel::LinRel
00277 operator>(const Gecode::MiniModel::LinExpr& l,
00278           int r);
00280 Gecode::MiniModel::LinRel
00281 operator>(const Gecode::MiniModel::LinExpr& l,
00282           const Gecode::MiniModel::LinExpr& r);
00283 
00285 Gecode::MiniModel::LinRel
00286 operator>=(int l,
00287            const Gecode::MiniModel::LinExpr& r);
00289 Gecode::MiniModel::LinRel
00290 operator>=(const Gecode::MiniModel::LinExpr& l,
00291            int r);
00293 Gecode::MiniModel::LinRel
00294 operator>=(const Gecode::MiniModel::LinExpr& l,
00295            const Gecode::MiniModel::LinExpr& r);
00296 
00298 
00299 namespace Gecode {
00300 
00301   namespace MiniModel {
00302 
00304     class BoolExpr {
00305     public:
00307       enum NodeType {
00308         BT_VAR, 
00309         BT_NOT, 
00310         BT_AND, 
00311         BT_OR,  
00312         BT_IMP, 
00313         BT_XOR, 
00314         BT_EQV, 
00315         BT_RLIN 
00316       };
00318       class Node {
00319       public:
00321         unsigned int use;
00323         unsigned int same;
00325         NodeType t;
00327         Node *l, *r;
00329         BoolVar x;
00331         LinRel rl;
00332 
00334         Node(void);
00336         GECODE_MINIMODEL_EXPORT bool decrement(void);
00338         GECODE_MINIMODEL_EXPORT int post(Space* home, NodeType t, 
00339                                          BoolVarArgs& b, int i) const;
00341         GECODE_MINIMODEL_EXPORT void post(Space* home, BoolVar b) const;
00343         GECODE_MINIMODEL_EXPORT BoolVar post(Space* home) const;
00345         GECODE_MINIMODEL_EXPORT void post(Space* home, bool t) const;
00346         
00348         static void* operator new(size_t size);
00350         static void  operator delete(void* p,size_t size);
00351       };
00352     private:
00354       Node* n;
00355     public:
00357       BoolExpr(const BoolExpr& e);
00359       BoolExpr(const BoolExpr& l, NodeType t, const BoolExpr& r);
00361       BoolExpr(const BoolVar& x);
00363       BoolExpr(const BoolExpr& e, NodeType t);
00365       BoolExpr(const LinRel& rl);
00367       BoolVar post(Space* home) const;
00369       void post(Space* home, bool t) const;
00370 
00372       const BoolExpr& operator=(const BoolExpr& e);
00374       ~BoolExpr(void);
00375     };
00376 
00378     class BoolRel {
00379     private:
00381       BoolExpr e;
00383       bool t;
00384     public:
00386       BoolRel(const BoolExpr& e, bool t);
00388       void post(Space* home) const;
00389     };
00390   }
00391 
00392 }
00393 
00408 
00410 Gecode::MiniModel::BoolExpr
00411 operator!(const Gecode::MiniModel::BoolExpr&);
00412 
00414 Gecode::MiniModel::BoolExpr
00415 operator&&(const Gecode::MiniModel::BoolExpr&,
00416            const Gecode::MiniModel::BoolExpr&);
00417 
00419 Gecode::MiniModel::BoolExpr
00420 operator||(const Gecode::MiniModel::BoolExpr&,
00421            const Gecode::MiniModel::BoolExpr&);
00422 
00424 Gecode::MiniModel::BoolExpr
00425 operator^(const Gecode::MiniModel::BoolExpr&,
00426           const Gecode::MiniModel::BoolExpr&);
00427 
00429 Gecode::MiniModel::BoolExpr
00430 operator~(const Gecode::MiniModel::LinExpr&);
00431 
00432 namespace Gecode {
00433 
00435   MiniModel::BoolExpr
00436   eqv(const MiniModel::BoolExpr&,
00437       const MiniModel::BoolExpr&);
00439   MiniModel::BoolExpr
00440   imp(const MiniModel::BoolExpr&,
00441       const MiniModel::BoolExpr&);
00442 
00444   MiniModel::BoolRel
00445   tt(const MiniModel::BoolExpr&);
00446   
00448   MiniModel::BoolRel
00449   ff(const MiniModel::BoolExpr&);
00450 
00451 }
00452 
00454 
00455 namespace Gecode { 
00456 
00463 
00464   IntVar post(Space* home, const MiniModel::LinExpr& e);
00466   IntVar post(Space* home, const IntVar& x);
00468   IntVar post(Space* home, int n);
00469 
00471   void post(Space* home, const MiniModel::LinRel& r);
00473   void post(Space* home, bool r);
00474 
00476   BoolVar post(Space* home, const MiniModel::BoolExpr& e);
00478   BoolVar post(Space* home, const BoolVar& b);
00480   void post(Space* home, const MiniModel::BoolRel& r);
00482   
00483 }
00484 
00485 #include "minimodel/lin-expr.icc"
00486 #include "minimodel/lin-rel.icc"
00487 #include "minimodel/bool-expr.icc"
00488 #include "minimodel/bool-rel.icc"
00489 
00490 namespace Gecode {
00491   
00528   GECODE_MINIMODEL_EXPORT void
00529   producer_consumer(Space *home, 
00530                     const IntVarArgs& produce_date, const IntArgs& produce_amount,
00531                     const IntVarArgs& consume_date, const IntArgs& consume_amount,
00532                     int initial, IntConLevel icl=ICL_DEF);
00533   
00534 
00557   GECODE_MINIMODEL_EXPORT void
00558   cumulative(Space *home, const IntVarArgs& start, const IntVarArgs& duration,
00559              const IntVarArgs& height, int limit, bool at_most = true, 
00560              IntConLevel cl=ICL_DEF);
00561 
00566   GECODE_MINIMODEL_EXPORT void
00567   cumulative(Space *home, const IntVarArgs& start, const IntArgs& duration,
00568              const IntVarArgs& height, int limit, bool at_most = true, 
00569              IntConLevel cl=ICL_DEF);
00570 
00575   GECODE_MINIMODEL_EXPORT void
00576   cumulative(Space *home, const IntVarArgs& start, const IntVarArgs& duration,
00577              const IntArgs& height, int limit, bool at_most = true, 
00578              IntConLevel cl=ICL_DEF);
00579 
00584   GECODE_MINIMODEL_EXPORT void
00585   cumulative(Space *home, const IntVarArgs& start, const IntArgs& duration,
00586              const IntArgs& height, int limit, bool at_most = true, 
00587              IntConLevel cl=ICL_DEF);
00588   
00605   GECODE_MINIMODEL_EXPORT void
00606   serialized(Space *home, const IntVarArgs& start, const IntVarArgs& duration,
00607              IntConLevel cl=ICL_DEF);
00608   
00609 
00614   GECODE_MINIMODEL_EXPORT void
00615   serialized(Space *home, const IntVarArgs& start, const IntArgs& duration,
00616              IntConLevel cl=ICL_DEF);
00617   
00618 
00620   
00621 }
00622 
00631 namespace Gecode { namespace MiniModel {
00632   
00642   template <class A>
00643   class Matrix {
00644   public:
00646     typedef typename ArrayTraits<A>::value_type value_type;
00648     typedef typename ArrayTraits<A>::args_type  args_type;
00649     
00657     class Slice {
00658       args_type _r;     
00659       unsigned int _fc, 
00660         _tc,            
00661         _fr,            
00662         _tr;            
00663     public:
00664       Slice(Matrix<A>& a, 
00665             unsigned int fc, unsigned int tc, 
00666             unsigned int fr, unsigned int tr);
00667 
00668       operator args_type(void);
00669       operator Matrix<args_type>(void);
00670     };
00671 
00672   private:
00674     typedef typename ArrayTraits<A>::storage_type storage_type;
00675     storage_type _a; 
00676     unsigned int _w, 
00677       _h;            
00678     
00679   public:
00689     Matrix(A a, unsigned int w, unsigned int h);
00690 
00700     Matrix(A a, unsigned int n);
00701     
00703     unsigned int const width(void);
00705     unsigned int const height(void);
00707     args_type const get_array(void);
00708 
00714     value_type& operator()(unsigned int c, unsigned int r);
00715     
00725     Slice slice(unsigned int fc, unsigned int tc, 
00726                 unsigned int fr, unsigned int tr);
00727     
00729     args_type row(int r);
00730     
00732     args_type col(int c);
00733   };
00734 }}
00735 
00736 #include "minimodel/matrix.icc"
00738 
00739 #endif
00740 
00741 // STATISTICS: minimodel-any
00742