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

rel-op.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  *
00006  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004, 2005
00011  *
00012  *  Last modified:
00013  *     $Date: 2008-02-01 11:29:52 +0100 (Fri, 01 Feb 2008) $ by $Author: tack $
00014  *     $Revision: 6032 $
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-op.hh"
00042 
00043 namespace Gecode {
00044   using namespace Gecode::Set;
00045   using namespace Gecode::Set::Rel;
00046   using namespace Gecode::Set::RelOp;
00047 
00048   void
00049   rel(Space* home, SetVar x, SetOpType op, SetVar y, SetRelType r, SetVar z) {
00050     rel_op_post<SetView,SetView,SetView>(home, x, op, y, r, z);
00051   }
00052 
00053   void
00054   rel(Space* home, SetOpType op, const SetVarArgs& x, SetVar y) {
00055     if (home->failed()) return;
00056     ViewArray<SetView> xa(home,x);
00057     switch(op) {
00058     case SOT_UNION:
00059       GECODE_ES_FAIL(home,(RelOp::UnionN<SetView,SetView>::post(home, xa, y)));
00060       break;
00061     case SOT_DUNION:
00062       GECODE_ES_FAIL(home,
00063                      (RelOp::PartitionN<SetView,SetView>::post(home, xa, y)));
00064       break;
00065     case SOT_INTER:
00066       {
00067         GECODE_ES_FAIL(home,
00068                        (RelOp::IntersectionN<SetView,SetView>
00069                         ::post(home, xa, y)));
00070       }
00071       break;
00072     case SOT_MINUS:
00073       throw InvalidRelation("rel minus");
00074       break;
00075     }
00076   }
00077 
00078   void
00079   rel(Space* home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y) {
00080     if (home->failed()) return;
00081     Set::Limits::check(z, "Set::rel");
00082     ViewArray<SetView> xa(home,x);
00083     switch(op) {
00084     case SOT_UNION:
00085       GECODE_ES_FAIL(home,(RelOp::UnionN<SetView,SetView>::post(home, xa, z, y)));
00086       break;
00087     case SOT_DUNION:
00088       GECODE_ES_FAIL(home,
00089                      (RelOp::PartitionN<SetView,SetView>::post(home, xa, z, y)));
00090       break;
00091     case SOT_INTER:
00092       {
00093         GECODE_ES_FAIL(home,
00094                        (RelOp::IntersectionN<SetView,SetView>
00095                         ::post(home, xa, z, y)));
00096       }
00097       break;
00098     case SOT_MINUS:
00099       throw InvalidRelation("rel minus");
00100       break;
00101     }
00102   }
00103 
00104   void
00105   rel(Space* home, SetOpType op, const IntVarArgs& x, SetVar y) {
00106     if (home->failed()) return;
00107     ViewArray<SingletonView> xa(home,x.size());
00108     for (int i=x.size(); i--;) {
00109       Int::IntView iv(x[i]);
00110       SingletonView sv(iv);
00111       xa[i] = sv;
00112     }
00113       
00114     switch(op) {
00115     case SOT_UNION:
00116       GECODE_ES_FAIL(home,(RelOp::UnionN<SingletonView,SetView>
00117                            ::post(home, xa, y)));
00118       break;
00119     case SOT_DUNION:
00120       GECODE_ES_FAIL(home,(RelOp::PartitionN<SingletonView,SetView>
00121                            ::post(home, xa, y)));
00122       break;
00123     case SOT_INTER:
00124       GECODE_ES_FAIL(home,
00125                      (RelOp::IntersectionN<SingletonView,SetView>
00126                       ::post(home, xa, y)));
00127       break;
00128     case SOT_MINUS:
00129       throw InvalidRelation("rel minus");
00130       break;
00131     }
00132   }
00133 
00134   void
00135   rel(Space* home, SetOpType op, const IntVarArgs& x, const IntSet& z, SetVar y) {
00136     if (home->failed()) return;
00137     Set::Limits::check(z, "Set::rel");
00138     ViewArray<SingletonView> xa(home,x.size());
00139     for (int i=x.size(); i--;) {
00140       Int::IntView iv(x[i]);
00141       SingletonView sv(iv);
00142       xa[i] = sv;
00143     }
00144       
00145     switch(op) {
00146     case SOT_UNION:
00147       GECODE_ES_FAIL(home,(RelOp::UnionN<SingletonView,SetView>
00148                            ::post(home, xa, z, y)));
00149       break;
00150     case SOT_DUNION:
00151       GECODE_ES_FAIL(home,(RelOp::PartitionN<SingletonView,SetView>
00152                            ::post(home, xa, z, y)));
00153       break;
00154     case SOT_INTER:
00155       GECODE_ES_FAIL(home,
00156                      (RelOp::IntersectionN<SingletonView,SetView>
00157                       ::post(home, xa, z, y)));
00158       break;
00159     case SOT_MINUS:
00160       throw InvalidRelation("rel minus");
00161       break;
00162     }
00163   }
00164 
00165   namespace {
00166 
00167     GECODE_REGISTER3(RelOp::Union<SingletonView, SingletonView, SetView>);
00168     GECODE_REGISTER3(RelOp::Union<SetView, SetView, ComplementView<SetView> >);
00169     GECODE_REGISTER3(RelOp::Union<SetView, SetView, SetView>);
00170 
00171     GECODE_REGISTER2(Set::RelOp::UnionN<SetView,SetView>);
00172     GECODE_REGISTER2(Set::RelOp::UnionN<SingletonView,SetView>);
00173 
00174     GECODE_REGISTER3(RelOp::Intersection<SingletonView, SingletonView, SetView>);
00175     GECODE_REGISTER3(RelOp::Intersection<SetView, ComplementView<SetView>, SetView>);
00176     GECODE_REGISTER3(RelOp::Intersection<SetView, ComplementView<SetView>, ComplementView<SetView> >);
00177     GECODE_REGISTER3(RelOp::Intersection<SetView, SetView, ComplementView<SetView> >);
00178     GECODE_REGISTER3(RelOp::Intersection<SetView, SetView, SetView>);
00179 
00180     GECODE_REGISTER2(Set::RelOp::IntersectionN<SetView,SetView>);
00181     GECODE_REGISTER2(Set::RelOp::IntersectionN<SingletonView,SetView>);
00182 
00183     GECODE_REGISTER2(Set::RelOp::PartitionN<SetView,SetView>);
00184     GECODE_REGISTER2(Set::RelOp::PartitionN<SingletonView,SetView>);
00185 
00186     GECODE_REGISTER3(RelOp::SubOfUnion<SetView, SetView, SetView>);
00187 
00188     GECODE_REGISTER3(RelOp::SuperOfInter<SetView, SingletonView, EmptyView>);
00189     GECODE_REGISTER3(RelOp::SuperOfInter<SetView, ComplementView<SetView>, SetView>);
00190     GECODE_REGISTER3(RelOp::SuperOfInter<SetView, SetView, EmptyView>);
00191     GECODE_REGISTER3(RelOp::SuperOfInter<SetView, SetView, SetView>);
00192 
00193   }
00194 
00195 }
00196 
00197 // STATISTICS: set-post