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

minimodel.hh

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *     Guido Tack <tack@gecode.org>
00005  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2004
00009  *     Guido Tack, 2004
00010  *     Mikael Lagerkvist, 2005
00011  *
00012  *  Last modified:
00013  *     $Date: 2006-06-07 11:11:07 +0200 (Wed, 07 Jun 2006) $ by $Author: zayenz $
00014  *     $Revision: 3271 $
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  See the file "LICENSE" for information on usage and
00021  *  redistribution of this file, and for a
00022  *     DISCLAIMER OF ALL WARRANTIES.
00023  *
00024  */
00025 
00026 #ifndef __GECODE_MINIMODEL_HH__
00027 #define __GECODE_MINIMODEL_HH__
00028 
00029 #include "gecode/kernel.hh"
00030 #include "gecode/int.hh"
00031 #include "gecode/int/linear.hh"
00032 
00033 #include "gecode/minimodel/exception.icc"
00034 
00035 #include <iostream>
00036 
00037 /*
00038  * Support for DLLs under Windows
00039  *
00040  */
00041 
00042 #if !defined(GECODE_STATIC_LIBS) && \
00043     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00044 
00045 #ifdef GECODE_BUILD_MINIMODEL
00046 #define GECODE_MINIMODEL_EXPORT __declspec( dllexport )
00047 #else
00048 #define GECODE_MINIMODEL_EXPORT __declspec( dllimport )
00049 #endif
00050 
00051 #else
00052 
00053 #define GECODE_MINIMODEL_EXPORT
00054 
00055 #endif
00056 
00057 namespace Gecode {
00058 
00060   namespace MiniModel {
00061 
00063     class LinExpr {
00064     private:
00066       class Node {
00067       private:
00069         unsigned int use;
00071         Node *left, *right;
00073         int signLeft, signRight;
00075         int a;
00077         IntVar x;
00078       public:
00080         Node(int a, const IntVar& x);
00082         Node(Node* n0, int s0, Node* n1, int s1);
00083 
00085         void increment(void);
00087         GECODE_MINIMODEL_EXPORT bool decrement(void);
00088         
00090         GECODE_MINIMODEL_EXPORT int
00091         fill(Int::Linear::Term t[], int i, int s) const;
00092         
00094         static void* operator new(size_t size);
00096         static void  operator delete(void* p,size_t size);
00097       };
00098       Node* ax;       
00099     public:
00100       unsigned int n; 
00101       int c;          
00102       int sign;       
00103 
00104       LinExpr(void);
00106       LinExpr(const LinExpr& e);
00108       LinExpr(const IntVar& x, int a=1, int c=0);
00110       LinExpr(const LinExpr& e0, const LinExpr& e1, int s);
00112       LinExpr(const LinExpr& e, int c, int s);
00114       LinExpr(int a, const LinExpr& e);
00116       const LinExpr& operator=(const LinExpr& e);
00118       GECODE_MINIMODEL_EXPORT
00119       void post(Space* home, IntRelType irt, IntConLevel icl) const;
00121       GECODE_MINIMODEL_EXPORT
00122       void post(Space* home, IntRelType irt, const BoolVar& b) const;
00124       GECODE_MINIMODEL_EXPORT
00125       IntVar post(Space* home, IntConLevel icl) const;
00127       ~LinExpr(void);
00128     };
00129 
00131     class LinRel {
00132     private:
00134       LinExpr    e;
00136       IntRelType irt;
00138       static IntRelType neg(IntRelType irt);
00139     public:
00141       LinRel(void);
00143       LinRel(const LinExpr& l, IntRelType irt, const LinExpr& r);
00145       LinRel(const LinExpr& l, IntRelType irt, int r);
00147       LinRel(int l, IntRelType irt, const LinExpr& r);
00149       void post(Space* home, bool t, IntConLevel icl) const;
00151       void post(Space* home, const BoolVar& b) const;
00152     };
00153 
00154   }
00155 
00156 }
00157 
00175 
00177 Gecode::MiniModel::LinExpr
00178 operator+(int,
00179           const Gecode::MiniModel::LinExpr&);
00181 Gecode::MiniModel::LinExpr
00182 operator+(const Gecode::MiniModel::LinExpr&,
00183           int);
00185 Gecode::MiniModel::LinExpr
00186 operator+(const Gecode::MiniModel::LinExpr&,
00187           const Gecode::MiniModel::LinExpr&);
00188 
00190 Gecode::MiniModel::LinExpr
00191 operator-(int,
00192           const Gecode::MiniModel::LinExpr&);
00194 Gecode::MiniModel::LinExpr
00195 operator-(const Gecode::MiniModel::LinExpr&,
00196           int);
00198 Gecode::MiniModel::LinExpr
00199 operator-(const Gecode::MiniModel::LinExpr&,
00200           const Gecode::MiniModel::LinExpr&);
00201 
00203 Gecode::MiniModel::LinExpr
00204 operator-(const Gecode::MiniModel::LinExpr&);
00205 
00206 
00208 Gecode::MiniModel::LinExpr
00209 operator*(int, const Gecode::IntVar&);
00211 Gecode::MiniModel::LinExpr
00212 operator*(const Gecode::IntVar&, int);
00214 Gecode::MiniModel::LinExpr
00215 operator*(const Gecode::MiniModel::LinExpr&, int);
00217 Gecode::MiniModel::LinExpr
00218 operator*(int, const Gecode::MiniModel::LinExpr&);
00219 
00220 
00222 Gecode::MiniModel::LinRel
00223 operator==(int l,
00224            const Gecode::MiniModel::LinExpr& r);
00226 Gecode::MiniModel::LinRel
00227 operator==(const Gecode::MiniModel::LinExpr& l,
00228            int r);
00230 Gecode::MiniModel::LinRel
00231 operator==(const Gecode::MiniModel::LinExpr& l,
00232            const Gecode::MiniModel::LinExpr& r);
00233 
00235 Gecode::MiniModel::LinRel
00236 operator!=(int l,
00237            const Gecode::MiniModel::LinExpr& r);
00239 Gecode::MiniModel::LinRel
00240 operator!=(const Gecode::MiniModel::LinExpr& l,
00241            int r);
00243 Gecode::MiniModel::LinRel
00244 operator!=(const Gecode::MiniModel::LinExpr& l,
00245            const Gecode::MiniModel::LinExpr& r);
00246 
00248 Gecode::MiniModel::LinRel
00249 operator<(int l,
00250           const Gecode::MiniModel::LinExpr& r);
00252 Gecode::MiniModel::LinRel
00253 operator<(const Gecode::MiniModel::LinExpr& l,
00254           int r);
00256 Gecode::MiniModel::LinRel
00257 operator<(const Gecode::MiniModel::LinExpr& l,
00258           const Gecode::MiniModel::LinExpr& r);
00259 
00261 Gecode::MiniModel::LinRel
00262 operator<=(int l,
00263            const Gecode::MiniModel::LinExpr& r);
00265 Gecode::MiniModel::LinRel
00266 operator<=(const Gecode::MiniModel::LinExpr& l,
00267            int r);
00269 Gecode::MiniModel::LinRel
00270 operator<=(const Gecode::MiniModel::LinExpr& l,
00271            const Gecode::MiniModel::LinExpr& r);
00272 
00274 Gecode::MiniModel::LinRel
00275 operator>(int l,
00276           const Gecode::MiniModel::LinExpr& r);
00278 Gecode::MiniModel::LinRel
00279 operator>(const Gecode::MiniModel::LinExpr& l,
00280           int r);
00282 Gecode::MiniModel::LinRel
00283 operator>(const Gecode::MiniModel::LinExpr& l,
00284           const Gecode::MiniModel::LinExpr& r);
00285 
00287 Gecode::MiniModel::LinRel
00288 operator>=(int l,
00289            const Gecode::MiniModel::LinExpr& r);
00291 Gecode::MiniModel::LinRel
00292 operator>=(const Gecode::MiniModel::LinExpr& l,
00293            int r);
00295 Gecode::MiniModel::LinRel
00296 operator>=(const Gecode::MiniModel::LinExpr& l,
00297            const Gecode::MiniModel::LinExpr& r);
00298 
00300 
00301 namespace Gecode {
00302 
00303   namespace MiniModel {
00304 
00306     class BoolExpr {
00307     public:
00309       enum NodeType {
00310         BT_VAR, 
00311         BT_NOT, 
00312         BT_AND, 
00313         BT_OR,  
00314         BT_IMP, 
00315         BT_XOR, 
00316         BT_EQV, 
00317         BT_RLIN 
00318       };
00320       class Node {
00321       public:
00323         unsigned int use;
00325         unsigned int same;
00327         NodeType t;
00329         Node *l, *r;
00331         BoolVar x;
00333         LinRel rl;
00334 
00336         Node(void);
00338         GECODE_MINIMODEL_EXPORT bool decrement(void);
00340         GECODE_MINIMODEL_EXPORT int post(Space* home, NodeType t, 
00341                                          BoolVarArgs& b, int i) const;
00343         GECODE_MINIMODEL_EXPORT void post(Space* home, BoolVar b) const;
00345         GECODE_MINIMODEL_EXPORT BoolVar post(Space* home) const;
00347         GECODE_MINIMODEL_EXPORT void post(Space* home, bool t) const;
00348         
00350         static void* operator new(size_t size);
00352         static void  operator delete(void* p,size_t size);
00353       };
00354     private:
00356       Node* n;
00357     public:
00359       BoolExpr(const BoolExpr& e);
00361       BoolExpr(const BoolExpr& l, NodeType t, const BoolExpr& r);
00363       BoolExpr(const BoolVar& x);
00365       BoolExpr(const BoolExpr& e, NodeType t);
00367       BoolExpr(const LinRel& rl);
00369       BoolVar post(Space* home) const;
00371       void post(Space* home, bool t) const;
00372 
00374       const BoolExpr& operator=(const BoolExpr& e);
00376       ~BoolExpr(void);
00377     };
00378 
00380     class BoolRel {
00381     private:
00383       BoolExpr e;
00385       bool t;
00386     public:
00388       BoolRel(const BoolExpr& e, bool t);
00390       void post(Space* home) const;
00391     };
00392   }
00393 
00394 }
00395 
00410 
00412 Gecode::MiniModel::BoolExpr
00413 operator!(const Gecode::MiniModel::BoolExpr&);
00414 
00416 Gecode::MiniModel::BoolExpr
00417 operator&&(const Gecode::MiniModel::BoolExpr&,
00418            const Gecode::MiniModel::BoolExpr&);
00419 
00421 Gecode::MiniModel::BoolExpr
00422 operator||(const Gecode::MiniModel::BoolExpr&,
00423            const Gecode::MiniModel::BoolExpr&);
00424 
00426 Gecode::MiniModel::BoolExpr
00427 operator^(const Gecode::MiniModel::BoolExpr&,
00428           const Gecode::MiniModel::BoolExpr&);
00429 
00431 Gecode::MiniModel::BoolExpr
00432 operator~(const Gecode::MiniModel::LinExpr&);
00433 
00434 namespace Gecode {
00435 
00437   MiniModel::BoolExpr
00438   eqv(const MiniModel::BoolExpr&,
00439       const MiniModel::BoolExpr&);
00441   MiniModel::BoolExpr
00442   imp(const MiniModel::BoolExpr&,
00443       const MiniModel::BoolExpr&);
00444 
00446   MiniModel::BoolRel
00447   tt(const MiniModel::BoolExpr&);
00448   
00450   MiniModel::BoolRel
00451   ff(const MiniModel::BoolExpr&);
00452 
00453 }
00454 
00456 
00457 namespace Gecode { 
00458 
00465 
00466   IntVar post(Space* home, const MiniModel::LinExpr& e, 
00467               IntConLevel icl=ICL_DEF);
00469   IntVar post(Space* home, const IntVar& x,
00470               IntConLevel icl=ICL_DEF);
00472   IntVar post(Space* home, int n,
00473               IntConLevel icl=ICL_DEF);
00474 
00476   void post(Space* home, const MiniModel::LinRel& r,
00477             IntConLevel icl=ICL_DEF);
00479   void post(Space* home, bool r,
00480             IntConLevel icl=ICL_DEF);
00481 
00483   BoolVar post(Space* home, const MiniModel::BoolExpr& e,
00484                IntConLevel icl=ICL_DEF);
00486   BoolVar post(Space* home, const BoolVar& b,
00487                IntConLevel icl=ICL_DEF);
00489   void post(Space* home, const MiniModel::BoolRel& r,
00490             IntConLevel icl=ICL_DEF);
00492   
00493 }
00494 
00495 #include "gecode/minimodel/lin-expr.icc"
00496 #include "gecode/minimodel/lin-rel.icc"
00497 #include "gecode/minimodel/bool-expr.icc"
00498 #include "gecode/minimodel/bool-rel.icc"
00499 
00500 namespace Gecode {
00501 
00508 
00509   GECODE_MINIMODEL_EXPORT IntVar 
00510   abs(Space* home, IntVar x, IntConLevel icl=ICL_DEF);
00512   GECODE_MINIMODEL_EXPORT IntVar 
00513   min(Space* home, IntVar x, IntVar y, IntConLevel icl=ICL_DEF);
00515   GECODE_MINIMODEL_EXPORT IntVar 
00516   min(Space* home, const IntVarArgs& x, IntConLevel icl=ICL_DEF);
00518   GECODE_MINIMODEL_EXPORT IntVar
00519   max(Space* home, IntVar x, IntVar y, IntConLevel icl=ICL_DEF);
00521   GECODE_MINIMODEL_EXPORT IntVar 
00522   max(Space* home, const IntVarArgs& x, IntConLevel icl=ICL_DEF);
00524   GECODE_MINIMODEL_EXPORT IntVar
00525   mult(Space* home, IntVar x, IntVar y, IntConLevel icl=ICL_DEF);
00527   GECODE_MINIMODEL_EXPORT IntVar
00528   sqr(Space* home, IntVar x, IntConLevel icl=ICL_DEF);
00530   GECODE_MINIMODEL_EXPORT IntVar
00531   plus(Space* home, IntVar x, IntVar y, IntConLevel icl=ICL_DEF);
00533   GECODE_MINIMODEL_EXPORT IntVar
00534   minus(Space* home, IntVar x, IntVar y, IntConLevel icl=ICL_DEF);
00536   
00537 }
00538 
00539 namespace Gecode {
00540   
00577   GECODE_MINIMODEL_EXPORT void
00578   producer_consumer(Space *home, 
00579                     const IntVarArgs& produce_date, const IntArgs& produce_amount,
00580                     const IntVarArgs& consume_date, const IntArgs& consume_amount,
00581                     int initial, IntConLevel icl=ICL_DEF);
00582   
00583 
00606   GECODE_MINIMODEL_EXPORT void
00607   cumulative(Space *home, const IntVarArgs& start, const IntVarArgs& duration,
00608              const IntVarArgs& height, int limit, bool at_most = true, 
00609              IntConLevel cl=ICL_DEF);
00610 
00615   GECODE_MINIMODEL_EXPORT void
00616   cumulative(Space *home, const IntVarArgs& start, const IntArgs& duration,
00617              const IntVarArgs& height, int limit, bool at_most = true, 
00618              IntConLevel cl=ICL_DEF);
00619 
00624   GECODE_MINIMODEL_EXPORT void
00625   cumulative(Space *home, const IntVarArgs& start, const IntVarArgs& duration,
00626              const IntArgs& height, int limit, bool at_most = true, 
00627              IntConLevel cl=ICL_DEF);
00628 
00633   GECODE_MINIMODEL_EXPORT void
00634   cumulative(Space *home, const IntVarArgs& start, const IntArgs& duration,
00635              const IntArgs& height, int limit, bool at_most = true, 
00636              IntConLevel cl=ICL_DEF);
00637   
00654   GECODE_MINIMODEL_EXPORT void
00655   serialized(Space *home, const IntVarArgs& start, const IntVarArgs& duration,
00656              IntConLevel cl=ICL_DEF);
00657   
00658 
00663   GECODE_MINIMODEL_EXPORT void
00664   serialized(Space *home, const IntVarArgs& start, const IntArgs& duration,
00665              IntConLevel cl=ICL_DEF);
00666   
00667 
00669   
00670 }
00671 
00680 namespace Gecode { namespace MiniModel {
00681   
00692   template <class A>
00693   class Matrix {
00694   public:
00696     typedef typename ArrayTraits<A>::value_type value_type;
00698     typedef typename ArrayTraits<A>::args_type  args_type;
00699     
00707     class Slice {
00708       args_type _r;     
00709       unsigned int _fc, 
00710         _tc,            
00711         _fr,            
00712         _tr;            
00713     public:
00714       Slice(Matrix<A>& a, 
00715             unsigned int fc, unsigned int tc, 
00716             unsigned int fr, unsigned int tr);
00717 
00718       operator args_type(void);
00719       operator Matrix<args_type>(void);
00720     };
00721 
00722   private:
00724     typedef typename ArrayTraits<A>::storage_type storage_type;
00725     storage_type _a; 
00726     unsigned int _w, 
00727       _h;            
00728     
00729   public:
00742     Matrix(A a, unsigned int w, unsigned int h);
00743 
00756     Matrix(A a, unsigned int n);
00757     
00759     unsigned int width(void) const;
00761     unsigned int height(void) const;
00763     args_type const get_array(void);
00764 
00770     value_type& operator()(unsigned int c, unsigned int r);
00771     
00781     Slice slice(unsigned int fc, unsigned int tc, 
00782                 unsigned int fr, unsigned int tr);
00783     
00785     args_type row(int r);
00786     
00788     args_type col(int c);
00789   };
00790 }}
00791 
00792 #include "gecode/minimodel/matrix.icc"
00794 
00795 #endif
00796 
00797 // STATISTICS: minimodel-any
00798