val-commit.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main author:
* Christian Schulte <schulte@gecode.org>
*
* 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 {
template<class _View, class _Val>
class ValCommit {
public:
typedef _View View;
typedef typename View::VarType Var;
typedef _Val Val;
public:
ValCommit(Space& home, const ValBranch<Var>& vb);
ValCommit(Space& home, ValCommit<View,Val>& vs);
bool notice(void) const;
void dispose(Space& home);
};
template<class View>
class ValCommitFunction : public
ValCommit<View,
typename BranchTraits<typename View::VarType>::ValType> {
typedef typename ValCommit<View,
typename BranchTraits<typename View::VarType>
::ValType>::Val Val;
public:
typedef typename View::VarType Var;
typedef typename BranchTraits<Var>::Commit CommitFunction;
protected:
SharedData<CommitFunction> c;
public:
ValCommitFunction(Space& home, const ValBranch<Var>& vb);
ValCommitFunction(Space& home, ValCommitFunction& vc);
ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
NGL* ngl(Space& home, unsigned int a, View x, Val n) const;
void print(const Space& home, unsigned int a, View x, int i,
const Val& n, std::ostream& o) const;
bool notice(void) const;
void dispose(Space& home);
};
// Baseclass for value commit
template<class View, class Val>
forceinline
ValCommit<View,Val>::ValCommit(Space&, const ValBranch<Var>&) {}
template<class View, class Val>
forceinline
ValCommit<View,Val>::ValCommit(Space&, ValCommit<View,Val>&) {}
template<class View, class Val>
forceinline bool
ValCommit<View,Val>::notice(void) const {
return false;
}
template<class View, class Val>
forceinline void
ValCommit<View,Val>::dispose(Space&) {}
// User-defined value selection
template<class View>
forceinline
ValCommitFunction<View>::ValCommitFunction(Space& home,
const ValBranch<Var>& vb)
: ValCommit<View,Val>(home,vb), c(vb.commit()) {
if (!c())
throw InvalidFunction("ValCommitFunction::ValCommitFunction");
}
template<class View>
forceinline
ValCommitFunction<View>::ValCommitFunction(Space& home,
ValCommitFunction<View>& vc)
: ValCommit<View,Val>(home,vc), c(vc.c) {
}
template<class View>
forceinline ModEvent
ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i,
Val n) {
typename View::VarType y(x.varimp());
GECODE_VALID_FUNCTION(c());
c()(home,a,y,i,n);
return home.failed() ? ES_FAILED : ES_OK;
}
template<class View>
forceinline NGL*
ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
return NULL;
}
template<class View>
forceinline void
ValCommitFunction<View>::print(const Space&, unsigned int,
View, int i, const Val&,
std::ostream& o) const {
o << "var[" << i << "] is user-defined.";
}
template<class View>
forceinline bool
ValCommitFunction<View>::notice(void) const {
return true;
}
template<class View>
forceinline void
ValCommitFunction<View>::dispose(Space&) {
c.~SharedData<CommitFunction>();
}
}
// STATISTICS: kernel-branch
Gecode::BranchTraits
Traits for branching.
Definition traits.hpp:55
Gecode::InvalidFunction
Exception: invalid function
Definition exception.hpp:114
Gecode::NGL
No-good literal recorded during search.
Definition core.hpp:1340
Gecode::SharedData
Class for sharing data between spaces.
Definition shared-data.hpp:38
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::ValBranch
Value branching information.
Definition val.hpp:41
Gecode::ValCommitFunction
Class for user-defined value commit.
Definition val-commit.hpp:67
Gecode::ValCommitFunction::c
SharedData< CommitFunction > c
The user-defined commit function.
Definition val-commit.hpp:78
Gecode::ValCommitFunction::ngl
NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for alternative a.
Definition val-commit.hpp:141
Gecode::ValCommitFunction::ValCommitFunction
ValCommitFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition val-commit.hpp:118
Gecode::ValCommitFunction::dispose
void dispose(Space &home)
Delete value commit.
Definition val-commit.hpp:158
Gecode::ValCommitFunction::CommitFunction
BranchTraits< Var >::Commit CommitFunction
The corresponding commit function.
Definition val-commit.hpp:75
Gecode::ValCommitFunction::ValCommitFunction
ValCommitFunction(Space &home, ValCommitFunction &vc)
Constructor for cloning during copying.
Gecode::ValCommitFunction::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed).
Definition val-commit.hpp:153
Gecode::ValCommitFunction::Var
View::VarType Var
The corresponding variable type.
Definition val-commit.hpp:73
Gecode::ValCommitFunction::commit
ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Perform user-defined commit.
Definition val-commit.hpp:132
Gecode::ValCommitFunction::print
void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const
Print on o the alternative with view x at position i and value n.
Definition val-commit.hpp:146
Gecode::ValCommit
Base class for value commit.
Definition val-commit.hpp:44
Gecode::ValCommit::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed).
Definition val-commit.hpp:107
Gecode::ValCommit::ValCommit
ValCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition val-commit.hpp:101
Gecode::ValCommit::Var
View::VarType Var
Corresponding variable type.
Definition val-commit.hpp:49
Gecode::ValCommit::dispose
void dispose(Space &home)
Delete value commit.
Definition val-commit.hpp:112
Gecode::ValCommit::Val
_Val Val
Value type.
Definition val-commit.hpp:51
Gecode::ValCommit::View
_View View
View type.
Definition val-commit.hpp:47
Gecode::ValCommit::ValCommit
ValCommit(Space &home, ValCommit< View, Val > &vs)
Constructor for cloning.
Definition val-commit.hpp:104
Gecode::View
Gecode::Space::failed
bool failed(void) const
Check whether space is failed.
Definition core.hpp:4044
Gecode
Gecode toplevel namespace
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition core.hpp:62
forceinline
#define forceinline
Definition config.hpp:187
GECODE_VALID_FUNCTION
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition macros.hpp:94