/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2002 * * Last modified: * $Date: 2008-02-18 05:36:02 +0100 (Mon, 18 Feb 2008) $ by $Author: schulte $ * $Revision: 6194 $ * * 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 { // Select first variable template forceinline ViewSelStatus ByNone::init(const Space*, View) { return VSS_COMMIT; } template forceinline ViewSelStatus ByNone::select(const Space*, View) { GECODE_NEVER; return VSS_NONE; } template inline Support::Symbol ByNone::type(void) { return Support::Symbol("Gecode::Int::Branch::ByNone"); } // Select variable with smallest min template forceinline ViewSelStatus ByMinMin::init(const Space*, View x) { min = x.min(); return VSS_SELECT; } template forceinline ViewSelStatus ByMinMin::select(const Space*, View x) { if (x.min() < min) { min = x.min(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByMinMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ByMinMin"); } // Select variable with largest min template forceinline ViewSelStatus ByMinMax::init(const Space*, View x) { min = x.min(); return VSS_SELECT; } template forceinline ViewSelStatus ByMinMax::select(const Space*, View x) { if (x.min() > min) { min = x.min(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByMinMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ByMinMax"); } // Select variable with smallest max template forceinline ViewSelStatus ByMaxMin::init(const Space*, View x) { max = x.max(); return VSS_SELECT; } template forceinline ViewSelStatus ByMaxMin::select(const Space*, View x) { if (x.max() < max) { max = x.max(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByMaxMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ByMaxMin"); } // Select variable with largest max template forceinline ViewSelStatus ByMaxMax::init(const Space*, View x) { max = x.max(); return VSS_SELECT; } template forceinline ViewSelStatus ByMaxMax::select(const Space*, View x) { if (x.max() > max) { max = x.max(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByMaxMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ByMaxMax"); } // Select variable with smallest size template forceinline ViewSelStatus BySizeMin::init(const Space*, View x) { size = x.size(); return (size == 2) ? VSS_COMMIT : VSS_SELECT; } template forceinline ViewSelStatus BySizeMin::select(const Space*, View x) { if (x.size() < size) { size = x.size(); return (size == 2) ? VSS_COMMIT : VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol BySizeMin::type(void) { return Support::Symbol("Gecode::Int::Branch::BySizeMin"); } // Select variable with largest size template forceinline ViewSelStatus BySizeMax::init(const Space*, View x) { size = x.size(); return VSS_SELECT; } template forceinline ViewSelStatus BySizeMax::select(const Space*, View x) { if (x.size() > size) { size = x.size(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol BySizeMax::type(void) { return Support::Symbol("Gecode::Int::Branch::BySizeMax"); } // Select variable with smallest degree (and smallest size in case of ties) template forceinline ViewSelStatus ByDegreeMin::init(const Space*, View x) { degree = x.degree(); size = x.size(); return VSS_SELECT; } template forceinline ViewSelStatus ByDegreeMin::select(const Space*, View x) { if (x.degree() < degree) { degree = x.degree(); size = x.size(); return VSS_SELECT; } else if ((x.degree() == degree) && (x.size() < size)) { size = x.size(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByDegreeMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ByDegreeMin"); } // Select variable with smallest degree (and smallest size in case of ties) template forceinline ViewSelStatus ByDegreeMax::init(const Space*, View x) { degree = x.degree(); size = x.size(); return VSS_SELECT; } template forceinline ViewSelStatus ByDegreeMax::select(const Space*, View x) { if (x.degree() > degree) { degree = x.degree(); size = x.size(); return VSS_SELECT; } else if ((x.degree() == degree) && (x.size() < size)) { size = x.size(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByDegreeMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ByDegreeMax"); } // Select variable with smallest degree template forceinline ViewSelStatus ByDegreeMinNoTies::init(const Space*, View x) { degree = x.degree(); return (degree == 0) ? VSS_COMMIT : VSS_SELECT; } template forceinline ViewSelStatus ByDegreeMinNoTies::select(const Space*, View x) { if (x.degree() < degree) { degree = x.degree(); return (degree == 0) ? VSS_COMMIT : VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByDegreeMinNoTies::type(void) { return Support::Symbol("Gecode::Int::Branch::ByDegreeMinNoTies"); } // Select variable with smallest degree template forceinline ViewSelStatus ByDegreeMaxNoTies::init(const Space*, View x) { degree = x.degree(); return VSS_SELECT; } template forceinline ViewSelStatus ByDegreeMaxNoTies::select(const Space*, View x) { if (x.degree() > degree) { degree = x.degree(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByDegreeMaxNoTies::type(void) { return Support::Symbol("Gecode::Int::Branch::ByDegreeMaxNoTies"); } // Select variable with smallest size/degree template forceinline ViewSelStatus BySizeDegreeMin::init(const Space*, View x) { sizedegree = static_cast(x.size())/static_cast(x.degree()); return VSS_SELECT; } template forceinline ViewSelStatus BySizeDegreeMin::select(const Space*, View x) { double sd = static_cast(x.size())/static_cast(x.degree()); if (sd < sizedegree) { sizedegree = sd; return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol BySizeDegreeMin::type(void) { return Support::Symbol("Gecode::Int::Branch::BySizeDegreeMin"); } // Select variable with largest size/degree template forceinline ViewSelStatus BySizeDegreeMax::init(const Space*, View x) { sizedegree = static_cast(x.size())/static_cast(x.degree()); return VSS_SELECT; } template forceinline ViewSelStatus BySizeDegreeMax::select(const Space*, View x) { double sd = static_cast(x.size())/static_cast(x.degree()); if (sd > sizedegree) { sizedegree = sd; return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol BySizeDegreeMax::type(void) { return Support::Symbol("Gecode::Int::Branch::BySizeDegreeMax"); } // Select variable with smallest min-regret template forceinline ViewSelStatus ByRegretMinMin::init(const Space*, View x) { regret = x.regret_min(); return (regret == 1) ? VSS_COMMIT : VSS_SELECT; } template forceinline ViewSelStatus ByRegretMinMin::select(const Space*, View x) { if (x.regret_min() < regret) { regret = x.regret_min(); return (regret == 1) ? VSS_COMMIT : VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByRegretMinMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ByRegretMinMin"); } // Select variable with largest min-regret template forceinline ViewSelStatus ByRegretMinMax::init(const Space*, View x) { regret = x.regret_min(); return VSS_SELECT; } template forceinline ViewSelStatus ByRegretMinMax::select(const Space*, View x) { if (x.regret_min() > regret) { regret = x.regret_min(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByRegretMinMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ByRegretMinMax"); } // Select variable with smallest max-regret template forceinline ViewSelStatus ByRegretMaxMin::init(const Space*, View x) { regret = x.regret_max(); return (regret == 1) ? VSS_COMMIT : VSS_SELECT; } template forceinline ViewSelStatus ByRegretMaxMin::select(const Space*, View x) { if (x.regret_max() < regret) { regret = x.regret_max(); return (regret == 1) ? VSS_COMMIT : VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByRegretMaxMin::type(void) { return Support::Symbol("Gecode::Int::Branch::ByRegretMaxMin"); } // Select variable with smallest min-regret template forceinline ViewSelStatus ByRegretMaxMax::init(const Space*, View x) { regret = x.regret_max(); return VSS_SELECT; } template forceinline ViewSelStatus ByRegretMaxMax::select(const Space*, View x) { if (x.regret_max() > regret) { regret = x.regret_max(); return VSS_SELECT; } return VSS_NONE; } template inline Support::Symbol ByRegretMaxMax::type(void) { return Support::Symbol("Gecode::Int::Branch::ByRegretMaxMax"); } }}} // STATISTICS: int-branch