Generated on Wed Nov 1 15:04:40 2006 for Gecode by doxygen 1.4.5

int.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004
00008  *     Christian Schulte, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $
00012  *     $Revision: 3188 $
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 #include "gecode/set.hh"
00025 
00026 #include "gecode/set/int.hh"
00027 #include "gecode/set/rel.hh"
00028 
00029 using namespace Gecode::Int;
00030 
00031 namespace Gecode {
00032 
00033   void
00034   rel(Space* home, SetVar s, IntRelType r, IntVar x) {
00035     if (home->failed()) return;
00036     switch(r) {
00037     case IRT_EQ:
00038       {
00039         Gecode::Int::IntView xv(x);
00040         Set::SingletonView xsingle(xv);
00041         GECODE_ES_FAIL(home,
00042                        (Set::Rel::Eq<Set::SetView,Set::SingletonView>
00043                         ::post(home,s,xsingle)));
00044 
00045       }
00046       break;
00047     case IRT_NQ:
00048       {
00049         Gecode::Int::IntView xv(x);
00050         Set::SingletonView xsingle(xv);
00051         GECODE_ES_FAIL(home,
00052                        (Set::Rel::Distinct<Set::SetView,Set::SingletonView>
00053                         ::post(home,s,xsingle)));
00054 
00055       }
00056       break;
00057     case IRT_LQ:
00058       {
00059         IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
00060         rel(home, tmp, IRT_LQ, x);
00061         GECODE_ES_FAIL(home,Set::Int::MaxElement::post(home,s,tmp));
00062       }
00063       break;
00064     case IRT_LE:
00065       {
00066         IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
00067         rel(home, tmp, IRT_LE, x);
00068         GECODE_ES_FAIL(home,Set::Int::MaxElement::post(home,s,tmp));
00069       }
00070       break;
00071     case IRT_GQ:
00072       {
00073         IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
00074         rel(home, tmp, IRT_GQ, x);
00075         GECODE_ES_FAIL(home,Set::Int::MinElement::post(home,s,tmp));
00076       }
00077       break;
00078     case IRT_GR:
00079       {
00080         IntVar tmp(home, Limits::Int::int_min, Limits::Int::int_max);
00081         rel(home, tmp, IRT_GR, x);
00082         GECODE_ES_FAIL(home,Set::Int::MinElement::post(home,s,tmp));
00083       }
00084       break;
00085     }
00086 
00087   }
00088 
00089   void
00090   rel(Space* home, IntVar x, IntRelType r, SetVar s) {
00091     IntRelType rr;
00092     switch (r) {
00093     case IRT_LE: rr=IRT_GR; break;
00094     case IRT_LQ: rr=IRT_GQ; break;
00095     case IRT_GR: rr=IRT_LE; break;
00096     case IRT_GQ: rr=IRT_LQ; break;
00097     default: rr=r;
00098     }
00099     rel(home, s, rr, x);
00100   }
00101 
00102   void
00103   min(Space* home, SetVar s, IntVar x){
00104     if (home->failed()) return;
00105     GECODE_ES_FAIL(home,Set::Int::MinElement::post(home,s,x));
00106   }
00107   void
00108   max(Space* home, SetVar s, IntVar x){
00109     if (home->failed()) return;
00110     GECODE_ES_FAIL(home,Set::Int::MaxElement::post(home,s,x));
00111   }
00112 
00113   void
00114   match(Space* home, SetVar s, const IntVarArgs& x) {
00115     if (home->failed()) return;
00116     ViewArray<IntView> xa(home,x);
00117     GECODE_ES_FAIL(home,Set::Int::Match::post(home,s,xa));
00118   }
00119 
00120   void
00121   channel(Space* home, const IntVarArgs& x, const SetVarArgs& y) {
00122     if (home->failed()) return;
00123     ViewArray<Int::IntView> xa(home,x);
00124     ViewArray<Set::SetView> ya(home,y);
00125     GECODE_ES_FAIL(home,Set::Int::Channel::post(home,xa,ya));
00126   }
00127 
00128   void weights(Space* home, const IntArgs& elements, const IntArgs& weights,
00129                SetVar x, IntVar y) {
00130     if (home->failed()) return;
00131     Set::SetView xv(x);
00132     Int::IntView yv(y);
00133     GECODE_ES_FAIL(home,Set::Int::Weights::post(home,elements,weights,x,y));
00134   }
00135 
00136 }
00137 
00138 // STATISTICS: set-post
00139