2 #ifndef OPENGM_INF_AND_FLIP_HXX
3 #define OPENGM_INF_AND_FLIP_HXX
26 template<
class GM,
class ACC,
class INF>
51 std::string
name()
const;
57 template<
class VisitorType>
61 sp_.resize(gm_.numberOfVariables());
62 sp_.assign(sp,sp+gm_.numberOfVariables());
63 spValue_=gm_.evaluate(sp_.begin());
66 const GraphicalModelType& gm_;
68 std::vector<LabelType> state_;
73 std::vector<LabelType> sp_;
80 template<
class GM,
class ACC,
class INF>
86 : gm_(gm), para_(param)
88 if(gm_.numberOfVariables() == 0) {
89 throw RuntimeError(
"The graphical model has no variables.");
91 value_ = ACC::template neutral<ValueType>();
92 bound_ = ACC::template ineutral<ValueType>();
95 template<
class GM,
class ACC,
class INF>
101 template<
class GM,
class ACC,
class INF>
108 template<
class GM,
class ACC,
class INF>
117 template<
class GM,
class ACC,
class INF>
118 template<
class VisitorType>
124 INF inf(gm_,para_.subPara_);
127 visitor.begin(*
this);
128 if(para_.warmStartableInf_ && !(sp_.size()==0))
129 inf.setStartingPoint(sp_.begin());
132 value_ = gm_.evaluate(state_);
140 if(para_.maxSubgraphSize_>0){
142 if(sp_.size()!=gm_.numberOfVariables())
145 if(ACC::bop(value_,spValue_))
150 std::cout <<
"start flipping ..."<<std::endl;
153 value_ = gm_.evaluate(state_);
162 template<
class GM,
class ACC,
class INF>
167 return this->infer(visitor);
171 template<
class GM,
class ACC,
class INF>
174 std::vector<LabelType>& arg,
179 arg.resize(gm_.numberOfVariables());
180 for(
size_t j=0; j<arg.size(); ++j) {
190 template<
class GM,
class ACC,
class INF>
196 template<
class GM,
class ACC,
class INF>
204 #endif // #ifndef OPENGM_INFANDFLIP_HXX
Parameter(const size_t maxSubgraphSize=2)
void setMaxSubgraphSize(const size_t)
InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
set initial labeling
ValueType value() const
return the solution (value)
ValueType bound() const
return a bound on the solution
visitors::TimingVisitor< InfAndFlip< GM, ACC, INF > > TimingVisitorType
visitors::EmptyVisitor< InfAndFlip< GM, ACC, INF > > EmptyVisitorType
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.
InferenceTermination infer()
start the algorithm
InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
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
const GraphicalModelType & graphicalModel() const