2 #ifndef OPENGM_INF_AND_FLIP_HXX 3 #define OPENGM_INF_AND_FLIP_HXX 26 template<
class GM,
class ACC,
class INF>
44 template<
class _GM,
class _ACC>
56 maxSubgraphSize_(maxSubgraphSize),
58 warmStartableInf_(false){
63 maxSubgraphSize_(p.maxSubgraphSize_),
65 warmStartableInf_(p.warmStartableInf_){
74 std::string
name()
const;
80 template<
class VisitorType>
84 sp_.resize(gm_.numberOfVariables());
85 sp_.assign(sp,sp+gm_.numberOfVariables());
86 spValue_=gm_.evaluate(sp_.begin());
89 const GraphicalModelType& gm_;
91 std::vector<LabelType> state_;
96 std::vector<LabelType> sp_;
103 template<
class GM,
class ACC,
class INF>
109 : gm_(gm), para_(param)
111 if(gm_.numberOfVariables() == 0) {
112 throw RuntimeError(
"The graphical model has no variables.");
114 value_ = ACC::template neutral<ValueType>();
115 bound_ = ACC::template ineutral<ValueType>();
118 template<
class GM,
class ACC,
class INF>
124 template<
class GM,
class ACC,
class INF>
131 template<
class GM,
class ACC,
class INF>
140 template<
class GM,
class ACC,
class INF>
141 template<
class VisitorType>
150 visitor.begin(*
this);
152 inf.setStartingPoint(sp_.begin());
155 value_ = gm_.evaluate(state_);
165 if(sp_.size()!=gm_.numberOfVariables())
168 if(ACC::bop(value_,spValue_))
173 std::cout <<
"start flipping ..."<<std::endl;
176 value_ = gm_.evaluate(state_);
185 template<
class GM,
class ACC,
class INF>
190 return this->
infer(visitor);
194 template<
class GM,
class ACC,
class INF>
197 std::vector<LabelType>&
arg,
202 arg.resize(gm_.numberOfVariables());
203 for(
size_t j=0; j<arg.size(); ++j) {
213 template<
class GM,
class ACC,
class INF>
219 template<
class GM,
class ACC,
class INF>
227 #endif // #ifndef OPENGM_INFANDFLIP_HXX
Parameter(const size_t maxSubgraphSize=2)
INF::template RebindGm< _GM >::type _I
const GraphicalModelType & graphicalModel() const
void setMaxSubgraphSize(const size_t)
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
set initial labeling
INF::template RebindGmAndAcc< _GM, _ACC >::type _I
visitors::TimingVisitor< InfAndFlip< GM, ACC, INF > > TimingVisitorType
InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
InfAndFlip< _GM, ACC, _I > type
ValueType value() const
return the solution (value)
visitors::EmptyVisitor< InfAndFlip< GM, ACC, INF > > EmptyVisitorType
InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
void setStartingPoint(typename std::vector< LabelType >::const_iterator sp)
set initial labeling
InfAndFlip(const GraphicalModelType &, typename InfAndFlip::Parameter param)
GraphicalModelType::ValueType ValueType
Inference algorithm interface.
ValueType bound() const
return a bound on the solution
InferenceTermination infer()
start the algorithm
InfAndFlip< _GM, _ACC, _I > type
A generalization of ICM B. Andres, J. H. Kappes, U. Koethe and Hamprecht F. A., The Lazy Flipper: MA...
static const size_t ContinueInf
visitors::VerboseVisitor< InfAndFlip< GM, ACC, INF > > VerboseVisitorType
InferenceTermination infer()
start the algorithm