/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * Christian Schulte * * Contributing authors: * Gabor Szokoli * * Copyright: * Guido Tack, 2004 * Christian Schulte, 2004 * Gabor Szokoli, 2004 * * Last modified: * $Date: 2008-02-16 10:42:26 +0100 (Sat, 16 Feb 2008) $ by $Author: tack $ * $Revision: 6185 $ * * 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. * */ namespace Gecode { namespace Set { namespace Branch { forceinline int ValMin::val(const Space*, SetView x) const { UnknownRanges unknown(x); return unknown.min(); } forceinline ModEvent ValMin::tell(Space* home, unsigned int a, SetView x, int v) { return (a == 0) ? x.include(home,v) : x.exclude(home,v); } inline Support::Symbol ValMin::type(void) { return Support::Symbol("Gecode::Set::Branch::ValMin"); } forceinline void ValMin::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, SetView x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str()); (*a0)[1] = x.spec(home, m); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str()); (*a1)[1] = x.spec(home, m); bs[1] = a1; } } forceinline int ValMax::val(const Space*, SetView x) const { int maxElem = 0; UnknownRanges unknown(x); while (unknown()) { maxElem = unknown.max(); ++unknown; } return maxElem; } forceinline ModEvent ValMax::tell(Space* home, unsigned int a, SetView x, int v) { return (a == 0) ? x.include(home,v) : x.exclude(home,v); } inline Support::Symbol ValMax::type(void) { return Support::Symbol("Gecode::Set::Branch::ValMax"); } forceinline void ValMax::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, SetView x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str()); (*a0)[1] = x.spec(home, m); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str()); (*a1)[1] = x.spec(home, m); bs[1] = a1; } } template static void create(Space* home, ViewArray& x, SetValBranch vals) { switch (vals) { case SET_VAL_MIN: (void) new (home) ViewValBranching(home,x); break; case SET_VAL_MAX: (void) new (home) ViewValBranching(home,x); break; default: throw UnknownBranching("Set::branch"); } } }}} // STATISTICS: set-branch