/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Contributing authors: * Gabor Szokoli * * Copyright: * Guido Tack, 2004, 2005 * * Last modified: * $Date: 2011-08-25 00:34:16 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $ * $Revision: 12346 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include #include #include namespace Gecode { namespace Set { namespace RelOp { template forceinline void rel_eq(Home home, View0 x0, SetOpType op, View1 x1, Res x2) { switch(op) { case SOT_DUNION: { EmptyView emptyset; GECODE_ES_FAIL((SuperOfInter ::post(home, x0, x1, emptyset))); // fall through to SOT_UNION } case SOT_UNION: { GECODE_ES_FAIL( (Union ::post(home, x0, x1, x2))); } break; case SOT_INTER: { GECODE_ES_FAIL((Intersection ::post(home, x0,x1,x2))); } break; case SOT_MINUS: { ComplementView cx1(x1); GECODE_ES_FAIL( (Intersection,Res> ::post(home,x0,cx1,x2))); } break; } } template forceinline void rel_sub(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) { switch(op) { case SOT_DUNION: { EmptyView emptyset; GECODE_ES_FAIL((SuperOfInter ::post(home, x0, x1, emptyset))); // fall through to SOT_UNION } case SOT_UNION: { SetVar tmp(home); GECODE_ES_FAIL( (Rel::Subset::post(home,tmp,x2))); GECODE_ES_FAIL( (Union ::post(home, x0, x1, tmp))); } break; case SOT_INTER: { GECODE_ES_FAIL((SuperOfInter ::post(home, x0,x1,x2))); } break; case SOT_MINUS: { ComplementView cx1(x1); GECODE_ES_FAIL( (SuperOfInter,View2> ::post(home,x0,cx1,x2))); } break; } } template forceinline void rel_sup(Home home, View0 x0, SetOpType op, View1 x1, View2 x2) { switch(op) { case SOT_DUNION: { EmptyView emptyset; GECODE_ES_FAIL((SuperOfInter ::post(home, x0, x1, emptyset))); // fall through to SOT_UNION } case SOT_UNION: { GECODE_ES_FAIL( (SubOfUnion ::post(home, x0, x1, x2))); } break; case SOT_INTER: { SetVar tmp(home); GECODE_ES_FAIL( (Rel::Subset::post(home,x2,tmp))); GECODE_ES_FAIL((Intersection ::post(home, x0,x1,tmp))); } break; case SOT_MINUS: { SetVar tmp(home); GECODE_ES_FAIL( (Rel::Subset::post(home,x2,tmp))); ComplementView cx1(x1); GECODE_ES_FAIL( (Intersection,SetView> ::post(home,x0,cx1,tmp))); } break; } } template forceinline void rel_op_post_lex(Home home, SetView x0, SetRelType r, View x1) { switch (r) { case SRT_LQ: GECODE_ES_FAIL((Rel::Lq::post(home,x0,x1))); break; case SRT_LE: GECODE_ES_FAIL((Rel::Lq::post(home,x0,x1))); break; case SRT_GQ: GECODE_ES_FAIL((Rel::Lq::post(home,x1,x0))); break; case SRT_GR: GECODE_ES_FAIL((Rel::Lq::post(home,x1,x0))); break; default: throw UnknownRelation("Set::rel"); } } template forceinline void rel_op_post_nocompl(Home home, View0 x, SetOpType op, View1 y, SetRelType r, View2 z) { if (home.failed()) return; switch(r) { case SRT_EQ: rel_eq(home, x, op, y, z); break; case SRT_LQ: case SRT_LE: case SRT_GQ: case SRT_GR: { SetVar tmp(home,IntSet::empty,Set::Limits::min,Set::Limits::max); rel_eq(home, x, op, y, tmp); rel_op_post_lex(home,tmp,r,z); } break; case SRT_NQ: { SetVar tmp(home); GECODE_ES_FAIL( (Rel::Distinct ::post(home,tmp,z))); rel_eq(home, x, op, y, tmp); } break; case SRT_SUB: rel_sub(home, x, op, y, z); break; case SRT_SUP: rel_sup(home, x, op, y, z); break; case SRT_DISJ: { SetVar tmp(home); EmptyView emptyset; GECODE_ES_FAIL((SuperOfInter ::post(home, z, tmp, emptyset))); rel_eq(home, x, op, y, tmp); } break; default: GECODE_NEVER; } } GECODE_SET_EXPORT void post_nocompl(Home home, SetView x, SetOpType op, SetView y, SetRelType r, SetView z); GECODE_SET_EXPORT void post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, SetRelType r, SetView z); GECODE_SET_EXPORT void post_nocompl(Home home, SetView x, SetOpType op, SetView y, SetRelType r, ConstSetView z); GECODE_SET_EXPORT void post_nocompl(Home home, ConstSetView x, SetOpType op, SetView y, SetRelType r, ConstSetView z); GECODE_SET_EXPORT void post_compl(Home home, SetView x, SetOpType op, SetView y, SetView z); GECODE_SET_EXPORT void post_compl(Home home, ConstSetView x, SetOpType op, SetView y, SetView z); GECODE_SET_EXPORT void post_compl(Home home, SetView x, SetOpType op, SetView y, ConstSetView z); GECODE_SET_EXPORT void post_compl(Home home, ConstSetView x, SetOpType op, SetView y, ConstSetView z); }}} // STATISTICS: set-prop