var.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* 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.
*
*/
#include <functional>
namespace Gecode {
typedef std::function<double(const Space& home, double w, double b)>
BranchTbl;
template<class Var>
class VarBranch {
public:
typedef typename BranchTraits<Var>::Merit MeritFunction;
protected:
BranchTbl _tbl;
Rnd _rnd;
double _decay;
AFC _afc;
Action _act;
CHB _chb;
MeritFunction _mf;
public:
VarBranch(void);
VarBranch(BranchTbl t);
VarBranch(Rnd r);
VarBranch(double d, BranchTbl t);
VarBranch(AFC a, BranchTbl t);
VarBranch(Action a, BranchTbl t);
VarBranch(CHB c, BranchTbl t);
VarBranch(MeritFunction f, BranchTbl t);
BranchTbl tbl(void) const;
Rnd rnd(void) const;
double decay(void) const;
AFC afc(void) const;
void afc(AFC a);
Action action(void) const;
void action(Action a);
CHB chb(void) const;
void chb(CHB chb);
MeritFunction merit(void) const;
};
// Variable branching
template<class Var>
inline
VarBranch<Var>::VarBranch(void)
: _tbl(nullptr), _decay(1.0) {}
template<class Var>
inline
VarBranch<Var>::VarBranch(BranchTbl t)
: _tbl(t), _decay(1.0) {}
template<class Var>
inline
VarBranch<Var>::VarBranch(double d, BranchTbl t)
: _tbl(t), _decay(d) {}
template<class Var>
inline
VarBranch<Var>::VarBranch(AFC a, BranchTbl t)
: _tbl(t), _decay(1.0), _afc(a) {
if (!_afc)
throw UninitializedAFC("VarBranch<Var>::VarBranch");
}
template<class Var>
inline
VarBranch<Var>::VarBranch(Action a, BranchTbl t)
: _tbl(t), _decay(1.0), _act(a) {
if (!_act)
throw UninitializedAction("VarBranch<Var>::VarBranch");
}
template<class Var>
inline
VarBranch<Var>::VarBranch(CHB c, BranchTbl t)
: _tbl(t), _decay(1.0), _chb(c) {
if (!_chb)
throw UninitializedCHB("VarBranch<Var>::VarBranch");
}
template<class Var>
inline
VarBranch<Var>::VarBranch(Rnd r)
: _tbl(nullptr), _rnd(r), _decay(1.0) {
if (!_rnd)
throw UninitializedRnd("VarBranch<Var>::VarBranch");
}
template<class Var>
inline
VarBranch<Var>::VarBranch(MeritFunction f, BranchTbl t)
: _tbl(t), _decay(1.0), _mf(f) {}
template<class Var>
inline BranchTbl
VarBranch<Var>::tbl(void) const {
return _tbl;
}
template<class Var>
inline Rnd
VarBranch<Var>::rnd(void) const {
return _rnd;
}
template<class Var>
inline double
VarBranch<Var>::decay(void) const {
return _decay;
}
template<class Var>
inline AFC
VarBranch<Var>::afc(void) const {
return _afc;
}
template<class Var>
inline void
VarBranch<Var>::afc(AFC a) {
_afc=a;
}
template<class Var>
inline Action
VarBranch<Var>::action(void) const {
return _act;
}
template<class Var>
inline void
VarBranch<Var>::action(Action a) {
_act=a;
}
template<class Var>
inline CHB
VarBranch<Var>::chb(void) const {
return _chb;
}
template<class Var>
inline void
VarBranch<Var>::chb(CHB chb) {
_chb=chb;
}
template<class Var>
inline typename VarBranch<Var>::MeritFunction
VarBranch<Var>::merit(void) const {
return _mf;
}
}
// STATISTICS: kernel-branch
Gecode::AFC
Class for AFC (accumulated failure count) management.
Definition afc.hpp:40
Gecode::Action
Class for action management.
Definition action.hpp:42
Gecode::BranchTraits
Traits for branching.
Definition traits.hpp:55
Gecode::CHB
Class for CHB management.
Definition chb.hpp:46
Gecode::Rnd
Random number generator.
Definition rnd.hpp:42
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::UninitializedAFC
Exception: uninitialized AFC
Definition exception.hpp:121
Gecode::UninitializedAction
Exception: uninitialized action
Definition exception.hpp:128
Gecode::UninitializedCHB
Exception: uninitialized CHB
Definition exception.hpp:135
Gecode::UninitializedRnd
Exception: uninitialized random number generator
Definition exception.hpp:142
Gecode::VarBranch::action
Action action(void) const
Return action.
Definition var.hpp:198
Gecode::VarBranch::VarBranch
VarBranch(void)
Initialize.
Definition var.hpp:116
Gecode::VarBranch::decay
double decay(void) const
Return decay factor.
Definition var.hpp:180
Gecode::VarBranch::tbl
BranchTbl tbl(void) const
Return tie-break limit function.
Definition var.hpp:168
Gecode::VarBranch::merit
MeritFunction merit(void) const
Return merit function.
Definition var.hpp:222
Gecode::VarBranch::_tbl
BranchTbl _tbl
Tie-breaking limit function.
Definition var.hpp:61
Gecode::VarBranch::MeritFunction
BranchTraits< Var >::Merit MeritFunction
Corresponding merit function.
Definition var.hpp:58
Gecode::VarBranch::_afc
AFC _afc
AFC information.
Definition var.hpp:67
Gecode::VarBranch::afc
AFC afc(void) const
Return AFC.
Definition var.hpp:186
Gecode::VarBranch::rnd
Rnd rnd(void) const
Return random number generator.
Definition var.hpp:174
Gecode::VarBranch::chb
CHB chb(void) const
Return CHB.
Definition var.hpp:210
Gecode::VarBranch::_mf
MeritFunction _mf
Merit function.
Definition var.hpp:73
Gecode::VarBranch::_rnd
Rnd _rnd
Random number generator.
Definition var.hpp:63
Gecode::VarBranch::_chb
CHB _chb
CHB information.
Definition var.hpp:71
Gecode::VarBranch::_act
Action _act
Action information.
Definition var.hpp:69
Gecode::VarBranch::_decay
double _decay
Decay information for AFC and action.
Definition var.hpp:65
Gecode::BranchTbl
std::function< double(const Space &home, double w, double b)> BranchTbl
Tie-break limit function.
Definition var.hpp:48
Gecode
Gecode toplevel namespace