Generated on Tue Apr 18 10:21:40 2017 for Gecode by doxygen 1.6.3

rel.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  *
00006  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004, 2005
00011  *
00012  *  Last modified:
00013  *     $Date: 2017-03-10 10:15:56 +0100 (Fri, 10 Mar 2017) $ by $Author: schulte $
00014  *     $Revision: 15566 $
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  Permission is hereby granted, free of charge, to any person obtaining
00021  *  a copy of this software and associated documentation files (the
00022  *  "Software"), to deal in the Software without restriction, including
00023  *  without limitation the rights to use, copy, modify, merge, publish,
00024  *  distribute, sublicense, and/or sell copies of the Software, and to
00025  *  permit persons to whom the Software is furnished to do so, subject to
00026  *  the following conditions:
00027  *
00028  *  The above copyright notice and this permission notice shall be
00029  *  included in all copies or substantial portions of the Software.
00030  *
00031  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00032  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00033  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00034  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00035  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00036  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00037  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00038  *
00039  */
00040 
00041 #include <gecode/set/rel.hh>
00042 #include <gecode/set/rel-op.hh>
00043 #include <gecode/set/int.hh>
00044 
00045 namespace Gecode { namespace Set {
00046 
00047   template<class View0, class View1>
00048   void
00049   rel_post(Home home, View0 x0, SetRelType r, View1 x1) {
00050     using namespace Set::Rel;
00051     using namespace Set::RelOp;
00052     GECODE_POST;
00053     switch (r) {
00054     case SRT_EQ:
00055       GECODE_ES_FAIL((Eq<View0,View1>::post(home,x0,x1)));
00056       break;
00057     case SRT_NQ:
00058       GECODE_ES_FAIL((Distinct<View0,View1>::post(home,x0,x1)));
00059       break;
00060     case SRT_SUB:
00061       GECODE_ES_FAIL((Subset<View0,View1>::post(home, x0,x1)));
00062       break;
00063     case SRT_SUP:
00064       GECODE_ES_FAIL((Subset<View1,View0>::post(home, x1,x0)));
00065       break;
00066     case SRT_DISJ:
00067       {
00068         EmptyView emptyset;
00069         GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00070                         ::post(home, x0, x1, emptyset)));
00071       }
00072       break;
00073     case SRT_CMPL:
00074       {
00075         ComplementView<View0> cx0(x0);
00076         GECODE_ES_FAIL((Eq<ComplementView<View0>, View1>
00077                         ::post(home, cx0, x1)));
00078       }
00079       break;
00080     case SRT_LQ:
00081       GECODE_ES_FAIL((Lq<View0,View1,false>::post(home,x0,x1)));
00082       break;
00083     case SRT_LE:
00084       GECODE_ES_FAIL((Lq<View0,View1,true>::post(home,x0,x1)));
00085       break;
00086     case SRT_GQ:
00087       GECODE_ES_FAIL((Lq<View1,View0,false>::post(home,x1,x0)));
00088       break;
00089     case SRT_GR:
00090       GECODE_ES_FAIL((Lq<View1,View0,true>::post(home,x1,x0)));
00091       break;
00092     default:
00093       throw UnknownRelation("Set::rel");
00094     }
00095   }
00096 
00097   template<class View0, class View1, ReifyMode rm>
00098   void
00099   rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
00100     using namespace Set::Rel;
00101     using namespace Set::RelOp;
00102     GECODE_POST;
00103     switch (r) {
00104     case SRT_EQ:
00105       GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::BoolView,rm>
00106                       ::post(home, x,y,b)));
00107       break;
00108     case SRT_NQ:
00109       {
00110         Gecode::Int::NegBoolView notb(b);
00111         switch (rm) {
00112         case RM_EQV:
00113           GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_EQV>
00114                          ::post(home,x,y,notb)));
00115           break;
00116         case RM_IMP:
00117           GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_PMI>
00118                          ::post(home,x,y,notb)));
00119           break;
00120         case RM_PMI:
00121           GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_IMP>
00122                          ::post(home,x,y,notb)));
00123           break;
00124         default: throw Gecode::Int::UnknownReifyMode("Set::rel");
00125         }
00126       }
00127       break;
00128     case SRT_SUB:
00129       GECODE_ES_FAIL((ReSubset<View0,View1,Gecode::Int::BoolView,rm>::post(home, x,y,b)));
00130       break;
00131     case SRT_SUP:
00132       GECODE_ES_FAIL((ReSubset<View1,View0,Gecode::Int::BoolView,rm>::post(home, y,x,b)));
00133       break;
00134     case SRT_DISJ:
00135       {
00136         // x||y <=> b is equivalent to
00137         // ( y <= complement(x) ) <=> b
00138 
00139         ComplementView<View0> xc(x);
00140         GECODE_ES_FAIL((ReSubset<View1,ComplementView<View0>,
00141                         Gecode::Int::BoolView,rm>
00142                         ::post(home, y, xc, b)));
00143       }
00144       break;
00145     case SRT_CMPL:
00146       {
00147         ComplementView<View0> xc(x);
00148         GECODE_ES_FAIL((ReEq<ComplementView<View0>,View1,
00149                         Gecode::Int::BoolView,rm>
00150                         ::post(home, xc, y, b)));
00151       }
00152       break;
00153     case SRT_LQ:
00154       GECODE_ES_FAIL((ReLq<View0,View1,rm,false>::post(home,x,y,b)));
00155       break;
00156     case SRT_LE:
00157       GECODE_ES_FAIL((ReLq<View0,View1,rm,true>::post(home,x,y,b)));
00158       break;
00159     case SRT_GQ:
00160       GECODE_ES_FAIL((ReLq<View1,View0,rm,false>::post(home,y,x,b)));
00161       break;
00162     case SRT_GR:
00163       GECODE_ES_FAIL((ReLq<View1,View0,rm,true>::post(home,y,x,b)));
00164       break;
00165     default:
00166       throw UnknownRelation("Set::rel");
00167     }
00168   }
00169 
00170 }}
00171 
00172 namespace Gecode {
00173 
00174   void
00175   rel(Home home, SetVar x, SetRelType r, SetVar y) {
00176     using namespace Set;
00177     rel_post<SetView,SetView>(home,x,r,y);
00178   }
00179 
00180   void
00181   rel(Home home, SetVar s, SetRelType r, IntVar x) {
00182     using namespace Set;
00183     Gecode::Int::IntView xv(x);
00184     SingletonView xsingle(xv);
00185     rel_post<SetView,SingletonView>(home,s,r,xv);
00186   }
00187 
00188   void
00189   rel(Home home, IntVar x, SetRelType r, SetVar s) {
00190     using namespace Set;
00191     switch (r) {
00192     case SRT_SUB:
00193       rel(home, s, SRT_SUP, x);
00194       break;
00195     case SRT_SUP:
00196       rel(home, s, SRT_SUB, x);
00197       break;
00198     default:
00199       rel(home, s, r, x);
00200     }
00201   }
00202 
00203   void
00204   rel(Home home, SetVar x, SetRelType rt, SetVar y, Reify r) {
00205     using namespace Set;
00206     switch (r.mode()) {
00207     case RM_EQV:
00208       rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
00209       break;
00210     case RM_IMP:
00211       rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
00212       break;
00213     case RM_PMI:
00214       rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
00215       break;
00216     default: throw Gecode::Int::UnknownReifyMode("Set::rel");
00217     }
00218   }
00219 
00220   void
00221   rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
00222     using namespace Set;
00223     Gecode::Int::IntView xv(x);
00224     SingletonView xsingle(xv);
00225     switch (r.mode()) {
00226     case RM_EQV:
00227       rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
00228       break;
00229     case RM_IMP:
00230       rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
00231       break;
00232     case RM_PMI:
00233       rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
00234       break;
00235     default: throw Gecode::Int::UnknownReifyMode("Set::rel");
00236     }
00237   }
00238 
00239   void
00240   rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
00241     using namespace Set;
00242     switch (rt) {
00243     case SRT_SUB:
00244       rel(home, s, SRT_SUP, x, r);
00245       break;
00246     case SRT_SUP:
00247       rel(home, s, SRT_SUB, x, r);
00248       break;
00249     default:
00250       rel(home, s, rt, x, r);
00251     }
00252   }
00253 
00254 }
00255 
00256 // STATISTICS: set-post