Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
6.2 kB · 240 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * * Copyright: * Christian Schulte, 2011 * * 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/int/nvalues.hh>#include <gecode/int/rel.hh>
namespace Gecode {
void nvalues(Home home, const IntVarArgs& x, IntRelType irt, int y, IntPropLevel) { using namespace Int; Limits::check(y,"Int::nvalues"); // Due to the quadratic Boolean matrix used in propagation long long int n = x.size(); Limits::check(n*n,"Int::nvalues");
GECODE_POST;
ViewArray<IntView> xv(home,x);
switch (irt) { case IRT_EQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::EqInt<ConstIntView>::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<IntView>::post(home,xv,z)); } break; case IRT_LE: y--; // Fall through case IRT_LQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::LqInt<ConstIntView>::post(home,xv,yv)); } break; case IRT_GR: y++; // Fall through case IRT_GQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::GqInt<ConstIntView>::post(home,xv,yv)); } break; default: throw UnknownRelation("Int::nvalues"); } }
void nvalues(Home home, const IntVarArgs& x, IntRelType irt, IntVar y, IntPropLevel) { using namespace Int; // Due to the quadratic Boolean matrix used in propagation long long int n = x.size(); Limits::check(n*n,"Int::nvalues");
GECODE_POST;
if (y.assigned()) { nvalues(home, x, irt, y.val()); return; }
ViewArray<IntView> xv(home,x);
switch (irt) { case IRT_EQ: GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,y)); break; case IRT_NQ: { IntVar z(home,0,x.size()); GECODE_ES_FAIL((Rel::Nq<IntView,IntView>::post(home,y,z))); GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,z)); } break; case IRT_LE: { OffsetView z(y,-1); GECODE_ES_FAIL(NValues::LqInt<OffsetView>::post(home,xv,z)); } break; case IRT_LQ: GECODE_ES_FAIL(NValues::LqInt<IntView>::post(home,xv,y)); break; case IRT_GR: { OffsetView z(y,1); GECODE_ES_FAIL(NValues::GqInt<OffsetView>::post(home,xv,z)); } break; case IRT_GQ: GECODE_ES_FAIL(NValues::GqInt<IntView>::post(home,xv,y)); break; default: throw UnknownRelation("Int::nvalues"); } }
void nvalues(Home home, const BoolVarArgs& x, IntRelType irt, int y, IntPropLevel) { using namespace Int; Limits::check(y,"Int::nvalues");
GECODE_POST;
Region region; ViewArray<BoolView> xv(region,x);
switch (irt) { case IRT_EQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::EqBool<ConstIntView>::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<IntView>::post(home,xv,z)); } break; case IRT_LE: y--; // Fall through case IRT_LQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::LqBool<ConstIntView>::post(home,xv,yv)); } break; case IRT_GR: y++; // Fall through case IRT_GQ: { ConstIntView yv(y); GECODE_ES_FAIL(NValues::GqBool<ConstIntView>::post(home,xv,yv)); } break; default: throw UnknownRelation("Int::nvalues"); } }
void nvalues(Home home, const BoolVarArgs& x, IntRelType irt, IntVar y, IntPropLevel) { using namespace Int;
GECODE_POST;
if (y.assigned()) { nvalues(home, x, irt, y.val()); return; }
Region region; ViewArray<BoolView> xv(region,x);
switch (irt) { case IRT_EQ: GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,y)); break; case IRT_NQ: { IntVar z(home,0,2); GECODE_ES_FAIL((Rel::Nq<IntView,IntView>::post(home,y,z))); GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,z)); } break; case IRT_LE: { OffsetView z(y,-1); GECODE_ES_FAIL(NValues::LqBool<OffsetView>::post(home,xv,z)); } break; case IRT_LQ: GECODE_ES_FAIL(NValues::LqBool<IntView>::post(home,xv,y)); break; case IRT_GR: { OffsetView z(y,1); GECODE_ES_FAIL(NValues::GqBool<OffsetView>::post(home,xv,z)); } break; case IRT_GQ: GECODE_ES_FAIL(NValues::GqBool<IntView>::post(home,xv,y)); break; default: throw UnknownRelation("Int::nvalues"); } }
}
// STATISTICS: int-post