/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2011 * * Last modified: * $Date: 2011-08-22 00:27:00 +1000 (Mon, 22 Aug 2011) $ by $Author: schulte $ * $Revision: 12319 $ * * 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 namespace Gecode { void nvalues(Home home, const IntVarArgs& x, IntRelType r, int y, IntConLevel) { using namespace Int; Limits::check(y,"Int::nvalues"); // Due to the quadratic Boolean matrix used in propagation Limits::check(static_cast(x.size())*static_cast(x.size()), "Int::nvalues"); if (home.failed()) return; ViewArray xv(home,x); switch (r) { case IRT_EQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::EqInt::post(home,xv,yv)); } break; case IRT_NQ: { IntVar z(home,0,x.size()); GECODE_ME_FAIL(IntView(z).nq(home,y)); GECODE_ES_FAIL(NValues::EqInt::post(home,xv,z)); } break; case IRT_LE: y--; // Fall through case IRT_LQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::LqInt::post(home,xv,yv)); } break; case IRT_GR: y++; // Fall through case IRT_GQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::GqInt::post(home,xv,yv)); } break; default: throw UnknownRelation("Int::nvalues"); } } void nvalues(Home home, const IntVarArgs& x, IntRelType r, IntVar y, IntConLevel) { using namespace Int; // Due to the quadratic Boolean matrix used in propagation Limits::check(static_cast(x.size())*static_cast(x.size()), "Int::nvalues"); if (home.failed()) return; if (y.assigned()) { nvalues(home, x, r, y.val()); return; } ViewArray xv(home,x); switch (r) { case IRT_EQ: GECODE_ES_FAIL(NValues::EqInt::post(home,xv,y)); break; case IRT_NQ: { IntVar z(home,0,x.size()); GECODE_ES_FAIL(Rel::Nq::post(home,y,z)); GECODE_ES_FAIL(NValues::EqInt::post(home,xv,z)); } break; case IRT_LE: { OffsetView z(y,-1); GECODE_ES_FAIL(NValues::LqInt::post(home,xv,z)); } break; case IRT_LQ: GECODE_ES_FAIL(NValues::LqInt::post(home,xv,y)); break; case IRT_GR: { OffsetView z(y,1); GECODE_ES_FAIL(NValues::GqInt::post(home,xv,z)); } break; case IRT_GQ: GECODE_ES_FAIL(NValues::GqInt::post(home,xv,y)); break; default: throw UnknownRelation("Int::nvalues"); } } void nvalues(Home home, const BoolVarArgs& x, IntRelType r, int y, IntConLevel) { using namespace Int; Limits::check(y,"Int::nvalues"); if (home.failed()) return; Region region(home); ViewArray xv(region,x); switch (r) { case IRT_EQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::EqBool::post(home,xv,yv)); } break; case IRT_NQ: { IntVar z(home,0,2); GECODE_ME_FAIL(IntView(z).nq(home,y)); GECODE_ES_FAIL(NValues::EqBool::post(home,xv,z)); } break; case IRT_LE: y--; // Fall through case IRT_LQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::LqBool::post(home,xv,yv)); } break; case IRT_GR: y++; // Fall through case IRT_GQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::GqBool::post(home,xv,yv)); } break; default: throw UnknownRelation("Int::nvalues"); } } void nvalues(Home home, const BoolVarArgs& x, IntRelType r, IntVar y, IntConLevel) { using namespace Int; if (home.failed()) return; if (y.assigned()) { nvalues(home, x, r, y.val()); return; } Region region(home); ViewArray xv(region,x); switch (r) { case IRT_EQ: GECODE_ES_FAIL(NValues::EqBool::post(home,xv,y)); break; case IRT_NQ: { IntVar z(home,0,2); GECODE_ES_FAIL(Rel::Nq::post(home,y,z)); GECODE_ES_FAIL(NValues::EqBool::post(home,xv,z)); } break; case IRT_LE: { OffsetView z(y,-1); GECODE_ES_FAIL(NValues::LqBool::post(home,xv,z)); } break; case IRT_LQ: GECODE_ES_FAIL(NValues::LqBool::post(home,xv,y)); break; case IRT_GR: { OffsetView z(y,1); GECODE_ES_FAIL(NValues::GqBool::post(home,xv,z)); } break; case IRT_GQ: GECODE_ES_FAIL(NValues::GqBool::post(home,xv,y)); break; default: throw UnknownRelation("Int::nvalues"); } } } // STATISTICS: int-post