/* -*- 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: 2007-08-09 15:30:21 +0200 (Thu, 09 Aug 2007) $ by $Author: tack $ * $Revision: 4790 $ * * 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 "gecode/set.hh" #include "gecode/set/rel.hh" #include "gecode/set/rel-op.hh" namespace Gecode { namespace Set { namespace RelOp { template forceinline void rel_eq(Space* home, View0 x0, SetOpType op, View1 x1, Res x2) { switch(op) { case SOT_DUNION: { EmptyView emptyset; GECODE_ES_FAIL(home,(SuperOfInter ::post(home, x0, x1, emptyset))); // fall through to SOT_UNION } case SOT_UNION: { GECODE_ES_FAIL(home, (Union ::post(home, x0, x1, x2))); } break; case SOT_INTER: { GECODE_ES_FAIL(home,(Intersection ::post(home, x0,x1,x2))); } break; case SOT_MINUS: { ComplementView cx1(x1); GECODE_ES_FAIL(home, (Intersection,Res> ::post(home,x0,cx1,x2))); } break; } } template forceinline void rel_sub(Space* home, View0 x0, SetOpType op, View1 x1, View2 x2) { switch(op) { case SOT_DUNION: { EmptyView emptyset; GECODE_ES_FAIL(home,(SuperOfInter ::post(home, x0, x1, emptyset))); // fall through to SOT_UNION } case SOT_UNION: { SetVar tmp(home); GECODE_ES_FAIL(home, (Rel::SubSet::post(home,tmp,x2))); GECODE_ES_FAIL(home, (Union ::post(home, x0, x1, tmp))); } break; case SOT_INTER: { GECODE_ES_FAIL(home,(SuperOfInter ::post(home, x0,x1,x2))); } break; case SOT_MINUS: { ComplementView cx1(x1); GECODE_ES_FAIL(home, (SuperOfInter,View2> ::post(home,x0,cx1,x2))); } break; } } template forceinline void rel_sup(Space* home, View0 x0, SetOpType op, View1 x1, View2 x2) { switch(op) { case SOT_DUNION: { EmptyView emptyset; GECODE_ES_FAIL(home,(SuperOfInter ::post(home, x0, x1, emptyset))); // fall through to SOT_UNION } case SOT_UNION: { GECODE_ES_FAIL(home, (SubOfUnion ::post(home, x0, x1, x2))); } break; case SOT_INTER: { SetVar tmp(home); GECODE_ES_FAIL(home, (Rel::SubSet::post(home,x2,tmp))); GECODE_ES_FAIL(home,(Intersection ::post(home, x0,x1,tmp))); } break; case SOT_MINUS: { SetVar tmp(home); GECODE_ES_FAIL(home, (Rel::SubSet::post(home,x2,tmp))); ComplementView cx1(x1); GECODE_ES_FAIL(home, (Intersection,SetView> ::post(home,x0,cx1,tmp))); } break; } } template forceinline void rel_op_post_nocompl(Space* 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_NQ: { SetVar tmp(home); GECODE_ES_FAIL(home, (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(home,(SuperOfInter ::post(home, z, tmp, emptyset))); rel_eq(home, x, op, y, tmp); } break; default: GECODE_NEVER; } } template forceinline void rel_op_post(Space* home, View0 x, SetOpType op, View1 y, SetRelType r, View2 z) { if (home->failed()) return; if (r == SRT_CMPL) { ComplementView cz(z); rel_eq >(home, x, op, y, cz); } else { rel_op_post_nocompl(home, x, op, y, r, z); } } }}} // STATISTICS: set-prop