val-sel.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 ValSel {
public:
typedef _View View;
typedef typename View::VarType Var;
typedef _Val Val;
public:
ValSel(Space& home, const ValBranch<Var>& vb);
ValSel(Space& home, ValSel<View,Val>& vs);
bool notice(void) const;
void dispose(Space& home);
};
template<class View>
class ValSelFunction :
public ValSel<View,
typename BranchTraits<typename View::VarType>::ValType> {
using typename ValSel<View,
typename BranchTraits<typename View::VarType>::ValType>::Var;
public:
typedef typename ValSel<View,
typename BranchTraits<typename View::VarType>
::ValType>::Val Val;
typedef typename BranchTraits<Var>::Val ValFunction;
protected:
SharedData<ValFunction> v;
public:
ValSelFunction(Space& home, const ValBranch<Var>& vb);
ValSelFunction(Space& home, ValSelFunction<View>& vs);
Val val(const Space& home, View x, int i);
bool notice(void) const;
void dispose(Space& home);
};
// Baseclass value selection
template<class View, class Val>
forceinline
ValSel<View,Val>::ValSel(Space&, const ValBranch<Var>&) {}
template<class View, class Val>
forceinline
ValSel<View,Val>::ValSel(Space&, ValSel<View,Val>&) {}
template<class View, class Val>
forceinline bool
ValSel<View,Val>::notice(void) const {
return false;
}
template<class View, class Val>
forceinline void
ValSel<View,Val>::dispose(Space&) {}
// User-defined value selection
template<class View>
forceinline
ValSelFunction<View>::ValSelFunction
(Space& home, const ValBranch<ValSelFunction<View>::Var>& vb)
: ValSel<View,Val>(home,vb), v(vb.val()) {
if (!v())
throw InvalidFunction("ValSelFunction::ValSelFunction");
}
template<class View>
forceinline
ValSelFunction<View>::ValSelFunction(Space& home, ValSelFunction<View>& vs)
: ValSel<View,Val>(home,vs), v(vs.v) {
}
template<class View>
forceinline typename ValSelFunction<View>::Val
ValSelFunction<View>::val(const Space& home, View x, int i) {
typename View::VarType y(x.varimp());
GECODE_VALID_FUNCTION(v());
return v()(home,y,i);
}
template<class View>
forceinline bool
ValSelFunction<View>::notice(void) const {
return true;
}
template<class View>
forceinline void
ValSelFunction<View>::dispose(Space&) {
v.~SharedData<ValFunction>();
}
}
// STATISTICS: kernel-branch
Gecode::BranchTraits
Traits for branching.
Definition traits.hpp:55
Gecode::InvalidFunction
Exception: invalid function
Definition exception.hpp:114
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::Val
Gecode::View
Gecode::ValSelFunction::Val
ValSel< View, typenameBranchTraits< typenameView::VarType >::ValType >::Val Val
The corresponding value type.
Definition val-sel.hpp:74
Gecode::ValSelFunction::ValFunction
BranchTraits< Var >::Val ValFunction
The corresponding value function.
Definition val-sel.hpp:76
Gecode::ValSelFunction::ValSelFunction
ValSelFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Gecode::ValSelFunction::dispose
void dispose(Space &home)
Delete value selection.
Definition val-sel.hpp:140
Gecode::ValSelFunction::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed).
Definition val-sel.hpp:135
Gecode::ValSelFunction::v
SharedData< ValFunction > v
The user-defined value function.
Definition val-sel.hpp:79
Gecode::ValSelFunction::val
Val val(const Space &home, View x, int i)
Return user-defined value of view x at position i.
Definition val-sel.hpp:128
Gecode::ValSel
Base class for value selection.
Definition val-sel.hpp:44
Gecode::ValSel::Val
_Val Val
Value type.
Definition val-sel.hpp:51
Gecode::ValSel::notice
bool notice(void) const
Whether dispose must always be called (that is, notice is needed).
Definition val-sel.hpp:104
Gecode::ValSel::View
_View View
View type.
Definition val-sel.hpp:47
Gecode::ValSel::ValSel
ValSel(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition val-sel.hpp:98
Gecode::ValSel::dispose
void dispose(Space &home)
Delete value selection.
Definition val-sel.hpp:109
Gecode::ValSel::ValSel
ValSel(Space &home, ValSel< View, Val > &vs)
Constructor for cloning.
Definition val-sel.hpp:101
Gecode::ValSel::Var
View::VarType Var
Corresponding variable type.
Definition val-sel.hpp:49
Gecode
Gecode toplevel namespace
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