/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main author: * Christian Schulte * * Copyright: * Christian Schulte, 2012 * * 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 { /** * \defgroup TaskBranchValSelCommit Generic value selection and value commit for brancher based on view and value selection * * \ingroup TaskBranchViewVal */ //@{ /// Base class for value selection and commit template class ValSelCommitBase { public: /// View type typedef View_ View; /// Corresponding variable type typedef typename View::VarType Var; /// Value type typedef Val_ Val; public: /// Constructor for initialization ValSelCommitBase(Space& home, const ValBranch& vb); /// Constructor for cloning ValSelCommitBase(Space& home, ValSelCommitBase& vsc); /// Return value of view \a x at position \a i virtual Val val(const Space& home, View x, int i) = 0; /// Commit view \a x at position \a i to value \a n for alternative \a a virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n) = 0; /// Create no-good literal for choice \a c and alternative \a a virtual NGL* ngl(Space& home, unsigned int a, View x, Val n) const = 0; /// Print on \a o branch for alternative \a a, view \a x at position \a i, and value \a n virtual void print(const Space& home, unsigned int a, View x, int i, const Val& n, std::ostream& o) const = 0; /// Perform cloning virtual ValSelCommitBase* copy(Space& home) = 0; /// Whether dispose must always be called (that is, notice is needed) virtual bool notice(void) const = 0; /// Delete value selection virtual void dispose(Space& home) = 0; /// Unused destructor virtual ~ValSelCommitBase(void); /// \name Memory management //@{ /// Allocate memory from space static void* operator new(size_t s, Space& home); /// Return memory to space static void operator delete(void* p, Space& home); /// Needed for exceptions static void operator delete(void* p); //@} }; /// Class for value selection and commit template class ValSelCommit : public ValSelCommitBase { protected: typedef typename ValSelCommitBase::Var Var; typedef typename ValSelCommitBase::Val Val; typedef typename ValSelCommitBase::View View; /// The value selection object used ValSel s; /// The commit object used ValCommit c; public: /// Constructor for initialization ValSelCommit(Space& home, const ValBranch& vb); /// Constructor for cloning ValSelCommit(Space& home, ValSelCommit& vsc); /// Return value of view \a x at position \a i virtual Val val(const Space& home, View x, int i); /// Commit view \a x at position \a i to value \a n for alternative \a a virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n); /// Create no-good literal for choice \a c and alternative \a a virtual NGL* ngl(Space& home, unsigned int a, View x, Val n) const; /// Print on \a o branch for alternative \a a, view \a x at position \a i, and value \a n virtual void print(const Space& home, unsigned int a, View x, int i, const Val& n, std::ostream& o) const; /// Perform cloning virtual ValSelCommit* copy(Space& home); /// Whether dispose must always be called (that is, notice is needed) virtual bool notice(void) const; /// Delete value selection virtual void dispose(Space& home); }; //@} template forceinline ValSelCommitBase::ValSelCommitBase(Space&, const ValBranch&) {} template forceinline ValSelCommitBase:: ValSelCommitBase(Space&, ValSelCommitBase&) {} template ValSelCommitBase::~ValSelCommitBase(void) {} template forceinline void ValSelCommitBase::operator delete(void*) {} template forceinline void ValSelCommitBase::operator delete(void*, Space&) {} template forceinline void* ValSelCommitBase::operator new(size_t s, Space& home) { return home.ralloc(s); } template forceinline ValSelCommit::ValSelCommit(Space& home, const ValBranch& vb) : ValSelCommitBase(home,vb), s(home,vb), c(home,vb) {} template forceinline ValSelCommit::ValSelCommit(Space& home, ValSelCommit& vsc) : ValSelCommitBase(home,vsc), s(home,vsc.s), c(home,vsc.c) {} template typename ValSelCommit::Val ValSelCommit::val(const Space& home, View x, int i) { return s.val(home,x,i); } template ModEvent ValSelCommit::commit(Space& home, unsigned int a, View x, int i, Val n) { return c.commit(home,a,x,i,n); } template NGL* ValSelCommit::ngl(Space& home, unsigned int a, View x, Val n) const { return c.ngl(home, a, x, n); } template void ValSelCommit::print(const Space& home, unsigned int a, View x, int i, const Val& n, std::ostream& o) const { c.print(home,a,x,i,n,o); } template ValSelCommit* ValSelCommit::copy(Space& home) { return new (home) ValSelCommit(home,*this); } template bool ValSelCommit::notice(void) const { return s.notice() || c.notice(); } template void ValSelCommit::dispose(Space& home) { s.dispose(home); c.dispose(home); } } // STATISTICS: kernel-branch