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

int.cc

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  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-02-20 10:27:10 +0100 (Wed, 20 Feb 2008) $ by $Author: tack $
00013  *     $Revision: 6241 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include "gecode/set.hh"
00041 
00042 #include "gecode/set/int.hh"
00043 #include "gecode/set/rel.hh"
00044 
00045 using namespace Gecode::Int;
00046 
00047 namespace Gecode {
00048 
00049   void
00050   rel(Space* home, SetVar s, IntRelType r, IntVar x) {
00051     if (home->failed()) return;
00052     switch(r) {
00053     case IRT_EQ:
00054       {
00055         Gecode::Int::IntView xv(x);
00056         Set::SingletonView xsingle(xv);
00057         GECODE_ES_FAIL(home,
00058                        (Set::Rel::Eq<Set::SetView,Set::SingletonView>
00059                         ::post(home,s,xsingle)));
00060 
00061       }
00062       break;
00063     case IRT_NQ:
00064       {
00065         Gecode::Set::SetView sv(s);
00066         GECODE_ME_FAIL(home, sv.cardMin(home, 1));
00067         Gecode::Int::IntView xv(x);
00068         Set::SingletonView xsingle(xv);
00069         GECODE_ES_FAIL(home,
00070                        (Set::Rel::NoSubSet<Set::SingletonView,Set::SetView>
00071                         ::post(home,xsingle,sv)));
00072 
00073       }
00074       break;
00075     case IRT_LQ:
00076       {
00077         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00078         rel(home, tmp, IRT_LQ, x);
00079         GECODE_ES_FAIL(home,Set::Int::MaxElement<Set::SetView>::post(home,s,tmp));
00080       }
00081       break;
00082     case IRT_LE:
00083       {
00084         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00085         rel(home, tmp, IRT_LE, x);
00086         GECODE_ES_FAIL(home,Set::Int::MaxElement<Set::SetView>::post(home,s,tmp));
00087       }
00088       break;
00089     case IRT_GQ:
00090       {
00091         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00092         rel(home, tmp, IRT_GQ, x);
00093         GECODE_ES_FAIL(home,Set::Int::MinElement<Set::SetView>::post(home,s,tmp));
00094       }
00095       break;
00096     case IRT_GR:
00097       {
00098         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00099         rel(home, tmp, IRT_GR, x);
00100         GECODE_ES_FAIL(home,Set::Int::MinElement<Set::SetView>::post(home,s,tmp));
00101       }
00102       break;
00103     }
00104 
00105   }
00106 
00107   void
00108   rel(Space* home, IntVar x, IntRelType r, SetVar s) {
00109     IntRelType rr;
00110     switch (r) {
00111     case IRT_LE: rr=IRT_GR; break;
00112     case IRT_LQ: rr=IRT_GQ; break;
00113     case IRT_GR: rr=IRT_LE; break;
00114     case IRT_GQ: rr=IRT_LQ; break;
00115     default: rr=r;
00116     }
00117     rel(home, s, rr, x);
00118   }
00119 
00120   void
00121   min(Space* home, SetVar s, IntVar x){
00122     if (home->failed()) return;
00123     GECODE_ES_FAIL(home,Set::Int::MinElement<Set::SetView>::post(home,s,x));
00124   }
00125   void
00126   max(Space* home, SetVar s, IntVar x){
00127     if (home->failed()) return;
00128     GECODE_ES_FAIL(home,Set::Int::MaxElement<Set::SetView>::post(home,s,x));
00129   }
00130 
00131   void
00132   match(Space* home, SetVar s, const IntVarArgs& x) {
00133     if (home->failed()) return;
00134     ViewArray<IntView> xa(home,x);
00135     GECODE_ES_FAIL(home,Set::Int::Match<Set::SetView>::post(home,s,xa));
00136   }
00137 
00138   void
00139   channel(Space* home, const IntVarArgs& x, const SetVarArgs& y) {
00140     if (home->failed()) return;
00141     ViewArray<Int::IntView> xa(home,x);
00142     ViewArray<Set::SetView> ya(home,y);
00143     GECODE_ES_FAIL(home,(Set::Int::ChannelInt<Set::SetView>
00144                          ::post(home,xa,ya)));
00145   }
00146 
00147   void
00148   channel(Space* home, const BoolVarArgs& x, SetVar y) {
00149     if (home->failed()) return;
00150     ViewArray<Int::BoolView> xv(home,x);
00151     Set::SetView yv(y);
00152     GECODE_ES_FAIL(home,(Set::Int::ChannelBool<Set::SetView>
00153                          ::post(home,xv,yv)));
00154   }
00155 
00156   void weights(Space* home, const IntArgs& elements, const IntArgs& weights,
00157                SetVar x, IntVar y) {
00158     if (home->failed()) return;
00159     Set::SetView xv(x);
00160     Int::IntView yv(y);
00161     GECODE_ES_FAIL(home,Set::Int::Weights<Set::SetView>::post(home,elements,
00162                                                               weights,x,y));
00163   }
00164 
00165   namespace {
00166     GECODE_REGISTER1(Set::Int::MinElement<Set::SetView>);
00167     GECODE_REGISTER1(Set::Int::MaxElement<Set::SetView>);
00168     GECODE_REGISTER1(Set::Int::Card<Set::SetView>);
00169     GECODE_REGISTER1(Set::Int::Match<Set::SetView>);
00170     GECODE_REGISTER1(Set::Int::ChannelInt<Set::SetView>);
00171     GECODE_REGISTER1(Set::Int::ChannelBool<Set::SetView>);
00172     GECODE_REGISTER1(Set::Int::Weights<Set::SetView>);
00173   }
00174 
00175 }
00176 
00177 // STATISTICS: set-post