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

set.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Guido Tack, 2004
00012  *     Christian Schulte, 2004
00013  *     Gabor Szokoli, 2004
00014  *
00015  *  Last modified:
00016  *     $Date: 2008-07-11 10:35:42 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00017  *     $Revision: 7339 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 #ifndef __GECODE_SET_HH__
00045 #define __GECODE_SET_HH__
00046 
00047 #include "gecode/kernel.hh"
00048 #include "gecode/int.hh"
00049 #include "gecode/iter.hh"
00050 
00051 /*
00052  * Configure linking
00053  *
00054  */
00055 #if !defined(GECODE_STATIC_LIBS) && \
00056     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00057 
00058 #ifdef GECODE_BUILD_SET
00059 #define GECODE_SET_EXPORT __declspec( dllexport )
00060 #else
00061 #define GECODE_SET_EXPORT __declspec( dllimport )
00062 #endif
00063 
00064 #else
00065 
00066 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00067 #define GECODE_SET_EXPORT __attribute__ ((visibility("default")))
00068 #else
00069 #define GECODE_SET_EXPORT
00070 #endif
00071 
00072 #endif
00073 
00085 #include "gecode/set/exception.icc"
00086 
00087 namespace Gecode { namespace Set {
00088 
00090   namespace Limits {
00092     const int max = (Gecode::Int::Limits::max / 2) - 1;
00094     const int min = -max;
00096     const unsigned int card = max-min+1;
00098     void check(int n, const char* l);
00100     void check(unsigned int n, const char* l);
00102     void check(const IntSet& s, const char* l);
00103   }
00104 
00105 }}
00106 
00107 #include "gecode/set/limits.icc"
00108 
00109 #include "gecode/set/var-imp.icc"
00110 
00111 namespace Gecode {
00112   
00113   namespace Set {
00114     class SetView;
00115   }
00116 
00122   class SetVar : public VarBase<Set::SetVarImp> {
00123     friend class SetVarArray;
00124   private:
00125     using VarBase<Set::SetVarImp>::varimp;
00127     void init(Space* home);
00136     void init(Space* home,int glbMin,int glbMax,int lubMin,int lubMax,
00137               unsigned int cardMin = 0,
00138               unsigned int cardMax = Set::Limits::card);
00147     void init(Space* home,const IntSet& glbD,int lubMin,int lubMax,
00148               unsigned int cardMin = 0,
00149               unsigned int cardMax = Set::Limits::card);
00158     void init(Space* home,int glbMin,int glbMax,const IntSet& lubD,
00159               unsigned int cardMin = 0,
00160               unsigned int cardMax = Set::Limits::card);
00169     void init(Space* home,const IntSet& glbD,const IntSet& lubD,
00170               unsigned int cardMin = 0,
00171               unsigned int cardMax = Set::Limits::card);
00172   public:
00174 
00175 
00176     SetVar(void);
00178     SetVar(const SetVar& x0);
00180     SetVar(const Set::SetView& x0);
00182     SetVar(const Reflection::Var& x0);
00183 
00185     GECODE_SET_EXPORT SetVar(Space* home);
00186 
00204     GECODE_SET_EXPORT 
00205     SetVar(Space* home,int glbMin,int glbMax,int lubMin,int lubMax,
00206            unsigned int cardMin = 0,
00207            unsigned int cardMax = Set::Limits::card);
00208 
00226     GECODE_SET_EXPORT 
00227     SetVar(Space* home,const IntSet& glbD,int lubMin,int lubMax,
00228            unsigned int cardMin = 0,
00229            unsigned int cardMax = Set::Limits::card);
00230 
00248     GECODE_SET_EXPORT 
00249     SetVar(Space* home,int glbMin,int glbMax,const IntSet& lubD,
00250            unsigned int cardMin = 0,
00251            unsigned int cardMax = Set::Limits::card);
00252 
00270     GECODE_SET_EXPORT 
00271     SetVar(Space* home,const IntSet& glbD,const IntSet& lubD,
00272            unsigned int cardMin = 0,
00273            unsigned int cardMax = Set::Limits::card);
00275 
00277 
00278 
00279     unsigned int glbSize(void) const;
00281     unsigned int lubSize(void) const;
00283     unsigned int unknownSize(void) const;
00285     unsigned int cardMin(void) const;
00287     unsigned int cardMax(void) const;
00289     int lubMin(void) const;
00291     int lubMax(void) const;
00293     int glbMin(void) const;
00295     int glbMax(void) const;
00297 
00299 
00300 
00301     bool contains(int i) const;
00303     bool notContains(int i) const;
00305     bool assigned(void) const;
00306 
00308 
00309 
00310     void update(Space* home, bool, SetVar& x);
00312   };
00313 
00319 
00321   class SetVarGlbRanges {
00322   private:
00323     Set::GlbRanges<Set::SetVarImp*> iter;
00324   public:
00326 
00327 
00328     SetVarGlbRanges(void);
00330     SetVarGlbRanges(const SetVar& x);
00332 
00334 
00335 
00336     bool operator()(void) const;
00338     void operator++(void);
00340 
00342 
00343 
00344     int min(void) const;
00346     int max(void) const;
00348     unsigned int width(void) const;
00350   };
00351 
00353   class SetVarLubRanges {
00354   private:
00355     Set::LubRanges<Set::SetVarImp*> iter;
00356   public:
00358 
00359 
00360     SetVarLubRanges(void);
00362     SetVarLubRanges(const SetVar& x);
00364 
00366 
00367 
00368     bool operator()(void) const;
00370     void operator++(void);
00372 
00374 
00375 
00376     int min(void) const;
00378     int max(void) const;
00380     unsigned int width(void) const;
00382   };
00383 
00385   class SetVarUnknownRanges {
00386   private:
00387     Set::UnknownRanges<Set::SetVarImp*> iter;
00388   public:
00390 
00391 
00392     SetVarUnknownRanges(void);
00394     SetVarUnknownRanges(const SetVar& x);
00396 
00398 
00399 
00400     bool operator()(void) const;
00402     void operator++(void);
00404 
00406 
00407 
00408     int min(void) const;
00410     int max(void) const;
00412     unsigned int width(void) const;
00414   };
00415   
00417   class SetVarGlbValues {
00418   private:
00419     Iter::Ranges::ToValues<SetVarGlbRanges> iter;
00420   public:
00422 
00423 
00424     SetVarGlbValues(void);
00426     SetVarGlbValues(const SetVar& x);
00428 
00430 
00431 
00432     bool operator()(void) const;
00434     void operator++(void);
00436 
00438 
00439 
00440     int  val(void) const;
00442   };
00443 
00445   class SetVarLubValues {
00446   private:
00447     Iter::Ranges::ToValues<SetVarLubRanges> iter;
00448   public:
00450 
00451 
00452     SetVarLubValues(void);
00454     SetVarLubValues(const SetVar& x);
00456 
00458 
00459 
00460     bool operator()(void) const;
00462     void operator++(void);
00464 
00466 
00467 
00468     int  val(void) const;
00470   };
00471 
00473   class SetVarUnknownValues {
00474   private:
00475     Iter::Ranges::ToValues<SetVarUnknownRanges> iter;
00476   public:
00478 
00479 
00480     SetVarUnknownValues(void);
00482     SetVarUnknownValues(const SetVar& x);
00484 
00486 
00487 
00488     bool operator()(void) const;
00490     void operator++(void);
00492 
00494 
00495 
00496     int  val(void) const;
00498   };
00499 
00501 
00502 }
00503 
00508 GECODE_SET_EXPORT std::ostream&
00509 operator<<(std::ostream&, const Gecode::SetVar& x);
00510 
00511 #include "gecode/set/view.icc"
00512 #include "gecode/set/propagator.icc"
00513 
00514 namespace Gecode {
00524 
00525   typedef PrimArgArray<IntSet> IntSetArgs;
00527   typedef VarArgArray<SetVar>  SetVarArgs;
00529 
00545   class SetVarArray : public VarArray<SetVar> {
00546   public:
00547     SetVarArray(void);
00548     SetVarArray(const SetVarArray&);
00550     GECODE_SET_EXPORT SetVarArray(Space* home,int n);
00557     GECODE_SET_EXPORT 
00558     SetVarArray(Space* home,int n,int glbMin,int glbMax,int lubMin,int lubMax,
00559                 unsigned int minCard = 0,
00560                 unsigned int maxCard = Set::Limits::card);
00567     GECODE_SET_EXPORT 
00568     SetVarArray(Space* home,int n,const IntSet& glb, int lubMin, int lubMax,
00569                 unsigned int minCard = 0,
00570                 unsigned int maxCard = Set::Limits::card);
00577     GECODE_SET_EXPORT 
00578     SetVarArray(Space* home,int n,int glbMin,int glbMax,const IntSet& lub,
00579                 unsigned int minCard = 0,
00580                 unsigned int maxCard = Set::Limits::card);
00587     GECODE_SET_EXPORT 
00588     SetVarArray(Space* home,int n,
00589                 const IntSet& glb,const IntSet& lub,
00590                 unsigned int minCard = 0,
00591                 unsigned int maxCard = Set::Limits::card);
00592   };
00593 
00594 }
00595 
00596 #include "gecode/set/array.icc"
00597 
00598 namespace Gecode {
00599 
00604   enum SetRelType {
00605     SRT_EQ,   
00606     SRT_NQ,   
00607     SRT_SUB,  
00608     SRT_SUP,  
00609     SRT_DISJ, 
00610     SRT_CMPL  
00611   };
00612 
00617   enum SetOpType {
00618     SOT_UNION,  
00619     SOT_DUNION, 
00620     SOT_INTER,  
00621     SOT_MINUS   
00622   };
00623 
00631 
00633   GECODE_SET_EXPORT void
00634   dom(Space* home, SetVar x, SetRelType r, int i);
00635 
00637   GECODE_SET_EXPORT void
00638   dom(Space* home, SetVar x, SetRelType r, int i, int j);
00639 
00641   GECODE_SET_EXPORT void
00642   dom(Space* home, SetVar x, SetRelType r, const IntSet& s);
00643 
00645   GECODE_SET_EXPORT void
00646   dom(Space* home, SetVar x, SetRelType r, int i, BoolVar b);
00647 
00649   GECODE_SET_EXPORT void
00650   dom(Space* home, SetVar x, SetRelType r, int i, int j, BoolVar b);
00651 
00653   GECODE_SET_EXPORT void
00654   dom(Space* home, SetVar x, SetRelType r, const IntSet& s, BoolVar b);
00655 
00657   GECODE_SET_EXPORT void
00658   cardinality(Space* home, SetVar x, unsigned int i, unsigned int j);
00659 
00661 
00662 
00670 
00672   GECODE_SET_EXPORT void
00673   rel(Space* home, SetVar x, SetRelType r, SetVar y);
00674 
00676   GECODE_SET_EXPORT void
00677   rel(Space* home, SetVar x, SetRelType r, SetVar y, BoolVar b);
00678 
00680   GECODE_SET_EXPORT void
00681   rel(Space* home, SetVar s, SetRelType r, IntVar x);
00682 
00684   GECODE_SET_EXPORT void
00685   rel(Space* home, IntVar x, SetRelType r, SetVar s);
00686 
00688   GECODE_SET_EXPORT void
00689   rel(Space* home, SetVar s, SetRelType r, IntVar x, BoolVar b);
00690 
00692   GECODE_SET_EXPORT void
00693   rel(Space* home, IntVar x, SetRelType r, SetVar s, BoolVar b);
00694 
00696   GECODE_SET_EXPORT void
00697   rel(Space* home, SetVar s, IntRelType r, IntVar x);
00698 
00700   GECODE_SET_EXPORT void
00701   rel(Space* home, IntVar x, IntRelType r, SetVar s);
00702 
00704 
00712 
00714   GECODE_SET_EXPORT void
00715   rel(Space* home, SetVar x, SetOpType op, SetVar y, SetRelType r, SetVar z);
00716 
00718   GECODE_SET_EXPORT void
00719   rel(Space* home, SetOpType op, const SetVarArgs& x, SetVar y);
00720 
00722   GECODE_SET_EXPORT void
00723   rel(Space* home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y);
00724 
00726   GECODE_SET_EXPORT void
00727   rel(Space* home, SetOpType op, const IntVarArgs& x, const IntSet& z, SetVar y);
00728 
00730   GECODE_SET_EXPORT void
00731   rel(Space* home, SetOpType op, const IntVarArgs& x, SetVar y);
00732 
00734   GECODE_SET_EXPORT void
00735   rel(Space* home, const IntSet& x, SetOpType op, SetVar y,
00736       SetRelType r, SetVar z);
00737 
00739   GECODE_SET_EXPORT void
00740   rel(Space* home, SetVar x, SetOpType op, const IntSet& y,
00741       SetRelType r, SetVar z);
00742 
00744   GECODE_SET_EXPORT void
00745   rel(Space* home, SetVar x, SetOpType op, SetVar y,
00746       SetRelType r, const IntSet& z);
00747 
00749   GECODE_SET_EXPORT void
00750   rel(Space* home, const IntSet& x, SetOpType op, SetVar y, SetRelType r,
00751       const IntSet& z);
00752 
00754   GECODE_SET_EXPORT void
00755   rel(Space* home, SetVar x, SetOpType op, const IntSet& y, SetRelType r,
00756       const IntSet& z);
00757 
00759 
00760 
00767 
00769   GECODE_SET_EXPORT void
00770   convex(Space* home, SetVar x);
00771 
00773   GECODE_SET_EXPORT void
00774   convexHull(Space* home, SetVar x, SetVar y);
00775 
00777 
00784 
00786   GECODE_SET_EXPORT void
00787   sequence(Space* home, const SetVarArgs& x);
00788 
00790   GECODE_SET_EXPORT void
00791   sequentialUnion(Space* home, const SetVarArgs& y, SetVar x);
00792 
00794 
00801 
00802 
00804   GECODE_SET_EXPORT void
00805   atmostOne(Space* home, const SetVarArgs& x, unsigned int c);
00806 
00808 
00816 
00819   GECODE_SET_EXPORT void
00820   min(Space* home, SetVar s, IntVar x);
00821   
00824   GECODE_SET_EXPORT void
00825   max(Space* home, SetVar s, IntVar x);
00826   
00828   GECODE_SET_EXPORT void
00829   match(Space* home, SetVar s, const IntVarArgs& x);
00830   
00832   GECODE_SET_EXPORT void
00833   channel(Space* home, const IntVarArgs& x,const SetVarArgs& y);
00834 
00836   GECODE_SET_EXPORT void
00837   channel(Space* home, const BoolVarArgs& x, SetVar y);
00838   
00840   GECODE_SET_EXPORT void
00841   cardinality(Space* home, SetVar s, IntVar x);
00842 
00843 
00854   GECODE_SET_EXPORT void
00855   weights(Space* home, const IntArgs& elements, const IntArgs& weights,
00856           SetVar x, IntVar y);
00857 
00859 
00873 
00881   GECODE_SET_EXPORT void
00882   elementsUnion(Space* home, const SetVarArgs& x, SetVar y, SetVar z);
00883 
00891   GECODE_SET_EXPORT void
00892   elementsUnion(Space* home, const IntSetArgs& s, SetVar y, SetVar z);
00893 
00901   GECODE_SET_EXPORT void
00902   elementsInter(Space* home, const SetVarArgs& x, SetVar y, SetVar z);
00903 
00911   GECODE_SET_EXPORT void
00912   elementsInter(Space* home, const SetVarArgs& x, SetVar y, SetVar z,
00913                const IntSet& u);
00914 
00916   GECODE_SET_EXPORT void
00917   elementsDisjoint(Space* home, const SetVarArgs& x, SetVar y);
00918 
00924   GECODE_SET_EXPORT void
00925   element(Space* home, const SetVarArgs& x, IntVar y, SetVar z);
00926 
00932   GECODE_SET_EXPORT void
00933   element(Space* home, const IntSetArgs& s, IntVar y, SetVar z);
00934 
00936 
00943   
00945   enum SetVarBranch {
00946     SET_VAR_NONE,               
00947     SET_VAR_MIN_CARD,           
00948     SET_VAR_MAX_CARD,           
00949     SET_VAR_MIN_UNKNOWN_ELEM,   
00950     SET_VAR_MAX_UNKNOWN_ELEM    
00951   };
00952   
00954   enum SetValBranch {
00955     SET_VAL_MIN,                
00956     SET_VAL_MAX                 
00957   };
00958 
00960   GECODE_SET_EXPORT void
00961   branch(Space* home, const SetVarArgs& x, 
00962          SetVarBranch vars, SetValBranch vals);
00964 
00965 }
00966 
00967 #endif
00968 
00969 // IFDEF: GECODE_HAS_SET_VARS
00970 // STATISTICS: set-post