/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * Christian Schulte * * Copyright: * Guido Tack, 2004 * Christian Schulte, 2004 * * Last modified: * $Date: 2011-08-18 20:26:27 +1000 (Thu, 18 Aug 2011) $ by $Author: tack $ * $Revision: 12314 $ * * 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 using namespace Gecode::Int; namespace Gecode { void rel(Home home, SetVar s, IntRelType r, IntVar x) { if (home.failed()) return; switch (r) { case IRT_EQ: { Gecode::Int::IntView xv(x); Set::SingletonView xsingle(xv); GECODE_ES_FAIL( (Set::Rel::Eq ::post(home,s,xsingle))); } break; case IRT_NQ: { Gecode::Set::SetView sv(s); GECODE_ME_FAIL( sv.cardMin(home, 1)); Gecode::Int::IntView xv(x); Set::SingletonView xsingle(xv); GECODE_ES_FAIL( (Set::Rel::NoSubset ::post(home,xsingle,sv))); } break; case IRT_LQ: { IntVar tmp(home, Int::Limits::min, Int::Limits::max); rel(home, tmp, IRT_LQ, x); GECODE_ES_FAIL(Set::Int::MaxElement::post(home,s,tmp)); } break; case IRT_LE: { IntVar tmp(home, Int::Limits::min, Int::Limits::max); rel(home, tmp, IRT_LE, x); GECODE_ES_FAIL(Set::Int::MaxElement::post(home,s,tmp)); } break; case IRT_GQ: { IntVar tmp(home, Int::Limits::min, Int::Limits::max); rel(home, tmp, IRT_GQ, x); GECODE_ES_FAIL(Set::Int::MinElement::post(home,s,tmp)); } break; case IRT_GR: { IntVar tmp(home, Int::Limits::min, Int::Limits::max); rel(home, tmp, IRT_GR, x); GECODE_ES_FAIL(Set::Int::MinElement::post(home,s,tmp)); } break; default: throw UnknownRelation("Set::rel"); } } void rel(Home home, IntVar x, IntRelType r, SetVar s) { IntRelType rr; switch (r) { case IRT_LE: rr=IRT_GR; break; case IRT_LQ: rr=IRT_GQ; break; case IRT_GR: rr=IRT_LE; break; case IRT_GQ: rr=IRT_LQ; break; default: rr=r; } rel(home, s, rr, x); } void min(Home home, SetVar s, IntVar x){ if (home.failed()) return; GECODE_ES_FAIL(Set::Int::MinElement::post(home,s,x)); } void notMin(Home home, SetVar s, IntVar x){ if (home.failed()) return; GECODE_ES_FAIL(Set::Int::NotMinElement::post(home,s,x)); } void min(Home home, SetVar s, IntVar x, BoolVar b){ if (home.failed()) return; GECODE_ES_FAIL( Set::Int::ReMinElement::post(home,s,x,b)); } void max(Home home, SetVar s, IntVar x){ if (home.failed()) return; GECODE_ES_FAIL(Set::Int::MaxElement::post(home,s,x)); } void notMax(Home home, SetVar s, IntVar x){ if (home.failed()) return; GECODE_ES_FAIL(Set::Int::NotMaxElement::post(home,s,x)); } void max(Home home, SetVar s, IntVar x, BoolVar b){ if (home.failed()) return; GECODE_ES_FAIL( Set::Int::ReMaxElement::post(home,s,x,b)); } void channelSorted(Home home, const IntVarArgs& x, SetVar y) { if (home.failed()) return; ViewArray xa(home,x); GECODE_ES_FAIL(Set::Int::Match::post(home,y,xa)); } void channel(Home home, const IntVarArgs& x, const SetVarArgs& y) { if (home.failed()) return; ViewArray > xa(home,x.size()); for (int i=x.size(); i--;) new (&xa[i]) Int::CachedView(x[i]); ViewArray > ya(home,y.size()); for (int i=y.size(); i--;) new (&ya[i]) Set::CachedView(y[i]); GECODE_ES_FAIL((Set::Int::ChannelInt::post(home,xa,ya))); } void channel(Home home, const BoolVarArgs& x, SetVar y) { if (home.failed()) return; ViewArray xv(home,x); GECODE_ES_FAIL((Set::Int::ChannelBool ::post(home,xv,y))); } void weights(Home home, IntSharedArray elements, IntSharedArray weights, SetVar x, IntVar y) { if (home.failed()) return; GECODE_ES_FAIL(Set::Int::Weights::post(home,elements, weights,x,y)); } } // STATISTICS: set-post