Generated on Mon Jul 6 18:09:18 2009 for Gecode by doxygen 1.5.9

rel-op.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: 2009-03-02 10:08:11 +0100 (Mon, 02 Mar 2009) $ by $Author: schulte $
00014  *     $Revision: 8320 $
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 IllegalOperation("Set::rel");
00074       break;
00075     default:
00076       throw UnknownOperation("Set::rel");
00077     }
00078   }
00079 
00080   void
00081   rel(Space& home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y) {
00082     if (home.failed()) return;
00083     Set::Limits::check(z, "Set::rel");
00084     ViewArray<SetView> xa(home,x);
00085     switch (op) {
00086     case SOT_UNION:
00087       GECODE_ES_FAIL(home,(RelOp::UnionN<SetView,SetView>::post(home, xa, z, y)));
00088       break;
00089     case SOT_DUNION:
00090       GECODE_ES_FAIL(home,
00091                      (RelOp::PartitionN<SetView,SetView>::post(home, xa, z, y)));
00092       break;
00093     case SOT_INTER:
00094       {
00095         GECODE_ES_FAIL(home,
00096                        (RelOp::IntersectionN<SetView,SetView>
00097                         ::post(home, xa, z, y)));
00098       }
00099       break;
00100     case SOT_MINUS:
00101       throw IllegalOperation("Set::rel");
00102       break;
00103     default:
00104       throw UnknownOperation("Set::rel");
00105     }
00106   }
00107 
00108   void
00109   rel(Space& home, SetOpType op, const IntVarArgs& x, SetVar y) {
00110     if (home.failed()) return;
00111     ViewArray<SingletonView> xa(home,x.size());
00112     for (int i=x.size(); i--;) {
00113       Int::IntView iv(x[i]);
00114       SingletonView sv(iv);
00115       xa[i] = sv;
00116     }
00117 
00118     switch (op) {
00119     case SOT_UNION:
00120       GECODE_ES_FAIL(home,(RelOp::UnionN<SingletonView,SetView>
00121                            ::post(home, xa, y)));
00122       break;
00123     case SOT_DUNION:
00124       GECODE_ES_FAIL(home,(RelOp::PartitionN<SingletonView,SetView>
00125                            ::post(home, xa, y)));
00126       break;
00127     case SOT_INTER:
00128       GECODE_ES_FAIL(home,
00129                      (RelOp::IntersectionN<SingletonView,SetView>
00130                       ::post(home, xa, y)));
00131       break;
00132     case SOT_MINUS:
00133       throw IllegalOperation("Set::rel");
00134       break;
00135     default:
00136       throw UnknownOperation("Set::rel");
00137     }
00138   }
00139 
00140   void
00141   rel(Space& home, SetOpType op, const IntVarArgs& x, const IntSet& z, 
00142       SetVar y) {
00143     if (home.failed()) return;
00144     Set::Limits::check(z, "Set::rel");
00145     ViewArray<SingletonView> xa(home,x.size());
00146     for (int i=x.size(); i--;) {
00147       Int::IntView iv(x[i]);
00148       SingletonView sv(iv);
00149       xa[i] = sv;
00150     }
00151 
00152     switch (op) {
00153     case SOT_UNION:
00154       GECODE_ES_FAIL(home,(RelOp::UnionN<SingletonView,SetView>
00155                            ::post(home, xa, z, y)));
00156       break;
00157     case SOT_DUNION:
00158       GECODE_ES_FAIL(home,(RelOp::PartitionN<SingletonView,SetView>
00159                            ::post(home, xa, z, y)));
00160       break;
00161     case SOT_INTER:
00162       GECODE_ES_FAIL(home,
00163                      (RelOp::IntersectionN<SingletonView,SetView>
00164                       ::post(home, xa, z, y)));
00165       break;
00166     case SOT_MINUS:
00167       throw IllegalOperation("set::rel");
00168       break;
00169     default:
00170       throw UnknownOperation("Set::rel");
00171     }
00172   }
00173 
00174 }
00175 
00176 // STATISTICS: set-post