Generated on Fri Mar 20 15:56:14 2015 for Gecode by doxygen 1.6.3

int.cpp

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: 2012-10-19 05:58:26 +0200 (Fri, 19 Oct 2012) $ by $Author: tack $
00013  *     $Revision: 13156 $
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 namespace Gecode {
00046 
00047   void
00048   rel(Home home, SetVar s, IntRelType r, IntVar x) {
00049     if (home.failed()) return;
00050     switch (r) {
00051     case IRT_EQ:
00052       {
00053         Gecode::Int::IntView xv(x);
00054         Set::SingletonView xsingle(xv);
00055         GECODE_ES_FAIL(
00056                        (Set::Rel::Eq<Set::SetView,Set::SingletonView>
00057                         ::post(home,s,xsingle)));
00058 
00059       }
00060       break;
00061     case IRT_NQ:
00062       {
00063         Gecode::Set::SetView sv(s);
00064         GECODE_ME_FAIL( sv.cardMin(home, 1));
00065         Gecode::Int::IntView xv(x);
00066         Set::SingletonView xsingle(xv);
00067         GECODE_ES_FAIL(
00068                        (Set::Rel::NoSubset<Set::SingletonView,Set::SetView>
00069                         ::post(home,xsingle,sv)));
00070 
00071       }
00072       break;
00073     case IRT_LQ:
00074       {
00075         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00076         rel(home, tmp, IRT_LQ, x);
00077         GECODE_ES_FAIL(Set::Int::MaxElement<Set::SetView>::post(home,s,tmp));
00078       }
00079       break;
00080     case IRT_LE:
00081       {
00082         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00083         rel(home, tmp, IRT_LE, x);
00084         GECODE_ES_FAIL(Set::Int::MaxElement<Set::SetView>::post(home,s,tmp));
00085       }
00086       break;
00087     case IRT_GQ:
00088       {
00089         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00090         rel(home, tmp, IRT_GQ, x);
00091         GECODE_ES_FAIL(Set::Int::MinElement<Set::SetView>::post(home,s,tmp));
00092       }
00093       break;
00094     case IRT_GR:
00095       {
00096         IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00097         rel(home, tmp, IRT_GR, x);
00098         GECODE_ES_FAIL(Set::Int::MinElement<Set::SetView>::post(home,s,tmp));
00099       }
00100       break;
00101     default:
00102       throw Int::UnknownRelation("Set::rel");
00103     }
00104 
00105   }
00106 
00107   void
00108   rel(Home 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(Home home, SetVar s, IntVar x){
00122     if (home.failed()) return;
00123     GECODE_ES_FAIL(Set::Int::MinElement<Set::SetView>::post(home,s,x));
00124   }
00125   void
00126   notMin(Home home, SetVar s, IntVar x){
00127     if (home.failed()) return;
00128     GECODE_ES_FAIL(Set::Int::NotMinElement<Set::SetView>::post(home,s,x));
00129   }
00130   void
00131   min(Home home, SetVar s, IntVar x, Reify r){
00132     if (home.failed()) return;
00133     switch (r.mode()) {
00134     case RM_EQV:
00135       GECODE_ES_FAIL((Set::Int::ReMinElement<Set::SetView,RM_EQV>
00136                      ::post(home,s,x,r.var())));
00137       break;
00138     case RM_IMP:
00139       GECODE_ES_FAIL((Set::Int::ReMinElement<Set::SetView,RM_IMP>
00140                      ::post(home,s,x,r.var())));
00141       break;
00142     case RM_PMI:
00143       GECODE_ES_FAIL((Set::Int::ReMinElement<Set::SetView,RM_PMI>
00144                      ::post(home,s,x,r.var())));
00145       break;
00146     default: throw Gecode::Int::UnknownReifyMode("Set::min");
00147     }
00148   }
00149   void
00150   max(Home home, SetVar s, IntVar x){
00151     if (home.failed()) return;
00152     GECODE_ES_FAIL(Set::Int::MaxElement<Set::SetView>::post(home,s,x));
00153   }
00154   void
00155   notMax(Home home, SetVar s, IntVar x){
00156     if (home.failed()) return;
00157     GECODE_ES_FAIL(Set::Int::NotMaxElement<Set::SetView>::post(home,s,x));
00158   }
00159   void
00160   max(Home home, SetVar s, IntVar x, Reify r){
00161     if (home.failed()) return;
00162     switch (r.mode()) {
00163     case RM_EQV:
00164       GECODE_ES_FAIL((Set::Int::ReMaxElement<Set::SetView,RM_EQV>
00165                      ::post(home,s,x,r.var())));
00166       break;
00167     case RM_IMP:
00168       GECODE_ES_FAIL((Set::Int::ReMaxElement<Set::SetView,RM_IMP>
00169                      ::post(home,s,x,r.var())));
00170       break;
00171     case RM_PMI:
00172       GECODE_ES_FAIL((Set::Int::ReMaxElement<Set::SetView,RM_PMI>
00173                      ::post(home,s,x,r.var())));
00174       break;
00175     default: throw Gecode::Int::UnknownReifyMode("Set::max");
00176     }
00177   }
00178 
00179   void weights(Home home, IntSharedArray elements, IntSharedArray weights,
00180                SetVar x, IntVar y) {
00181     if (home.failed()) return;
00182     GECODE_ES_FAIL(Set::Int::Weights<Set::SetView>::post(home,elements,
00183                                                               weights,x,y));
00184   }
00185 
00186 }
00187 
00188 // STATISTICS: set-post