/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2002 * * 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 Int { namespace Branch { template forceinline int ValMin::val(const Space*, View x) const { return x.min(); } template forceinline ModEvent ValMin::tell(Space* home, unsigned int a, View x, int n) { return (a == 0) ? x.eq(home,n) : x.gr(home,n); } template inline Support::Symbol ValMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ValMin"); } template forceinline void ValMin::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str()); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString((std::string(">")+s.str()).c_str()); bs[1] = a1; } } template forceinline int ValMed::val(const Space*, View x) const { return x.med(); } template forceinline ModEvent ValMed::tell(Space* home, unsigned int a, View x, int n) { return (a == 0) ? x.eq(home,n) : x.nq(home,n); } template inline Support::Symbol ValMed::type(void) { return Support::Symbol("Gecode::Int::Branch::ValMed"); } template forceinline void ValMed::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str()); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString((std::string("!=")+s.str()).c_str()); bs[1] = a1; } } template forceinline int ValMax::val(const Space*, View x) const { return x.max(); } template forceinline ModEvent ValMax::tell(Space* home, unsigned int a, View x, int n) { return (a == 0) ? x.eq(home,n) : x.le(home,n); } template inline Support::Symbol ValMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ValMax"); } template forceinline void ValMax::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str()); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString((std::string("<")+s.str()).c_str()); bs[1] = a1; } } template forceinline int ValSplitMin::val(const Space*, View x) const { return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2); } template forceinline ModEvent ValSplitMin::tell(Space* home, unsigned int a, View x, int n) { return (a == 0) ? x.lq(home,n) : x.gr(home,n); } template inline Support::Symbol ValSplitMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ValSplitMin"); } template forceinline void ValSplitMin::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str()); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString((std::string(">")+s.str()).c_str()); bs[1] = a1; } } template forceinline int ValSplitMax::val(const Space*, View x) const { return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2); } template forceinline ModEvent ValSplitMax::tell(Space* home, unsigned int a, View x, int n) { return (a == 0) ? x.gr(home,n) : x.lq(home,n); } template inline Support::Symbol ValSplitMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ValSplitMax"); } template forceinline void ValSplitMax::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, int n) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); std::stringstream s; s << n; (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString((std::string(">")+s.str()).c_str()); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString((std::string("<=")+s.str()).c_str()); bs[1] = a1; } } template class SelView> void create(Space* home, ViewArray& x, IntValBranch vals) { switch (vals) { case INT_VAL_MIN: (void) new (home) ViewValBranching,ValMin >(home,x); break; case INT_VAL_MED: (void) new (home) ViewValBranching,ValMed >(home,x); break; case INT_VAL_MAX: (void) new (home) ViewValBranching,ValMax >(home,x); break; case INT_VAL_SPLIT_MIN: (void) new (home) ViewValBranching,ValSplitMin >(home,x); break; case INT_VAL_SPLIT_MAX: (void) new (home) ViewValBranching,ValSplitMax >(home,x); break; default: throw UnknownBranching("Int::branch"); } } inline Support::Symbol NoValue::type(void) { return Support::Symbol("Gecode::Int::Branch::NoValue"); } template forceinline NoValue ValZeroOne::val(const Space*, View) const { NoValue n; return n; } template forceinline ModEvent ValZeroOne::tell(Space* home, unsigned int a, View x, NoValue) { return (a == 0) ? x.zero(home) : x.one(home); } template inline Support::Symbol ValZeroOne::type(void) { return Support::Symbol("Gecode::Int::Branch::ValZeroOne"); } template forceinline void ValZeroOne::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, NoValue) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString("= 0"); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString("= 1"); bs[1] = a1; } } template forceinline NoValue ValOneZero::val(const Space*, View) const { NoValue n; return n; } template forceinline ModEvent ValOneZero::tell(Space* home, unsigned int a, View x, NoValue) { return (a == 0) ? x.one(home) : x.zero(home); } template inline Support::Symbol ValOneZero::type(void) { return Support::Symbol("Gecode::Int::Branch::ValOneZero"); } template forceinline void ValOneZero::branchingSpec(const Space* home, Reflection::VarMap& m, Reflection::BranchingSpec& bs, int alt, View x, NoValue) const { assert(alt <= 2); Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2); (*a0)[0] = x.spec(home, m); (*a0)[1] = Reflection::Arg::newString("= 1"); bs[0] = a0; if (alt == 2) { Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2); (*a1)[0] = x.spec(home, m); (*a1)[1] = Reflection::Arg::newString("= 0"); bs[1] = a1; } } }}} // STATISTICS: int-branch