1 #ifndef OPENGM_SELF_FUSION_HXX 2 #define OPENGM_SELF_FUSION_HXX 34 template<
class INF,
class SELF_FUSION,
class SELF_FUSION_VISITOR>
49 typedef kolmogorov::qpbo::QPBO<double> QpboSubInf;
61 SelfFusionType & selfFusion,
62 SelfFusionVisitorType & selfFusionVisitor,
63 std::vector<LabelType> & argBest,
68 :
gm_(selfFusion.graphicalModel()),
76 argFromInf_(selfFusion.graphicalModel().numberOfVariables()),
78 argOut_(selfFusion.graphicalModel().numberOfVariables()),
79 returnFlag_(visitors::VisitorReturnFlag::ContinueInf),
109 const typename SelfFusionType::Parameter & param =
selfFusion_.parameter();
111 ValueType oldValue =
value_;
115 ValueType value = inference.value();
116 if(AccumulationType::bop(value,
value_)){
127 const ValueType infValue = inference.value();
128 bound_ = inference.bound();
130 IndexType nLocalVar=0;
131 for(IndexType vi=0;vi<
gm_.numberOfVariables();++vi){
147 if(param.fusionSolver_==SelfFusionType::LazyFlipperFusion){
155 else if(param.fusionSolver_==SelfFusionType::CplexFusion ){
158 if(param.reducedInf_==
false){
161 typename CplexSubInf::Parameter p;
162 p.integerConstraint_ =
true;
163 p.numberOfThreads_ = 1;
164 p.timeLimit_ = param.fusionTimeLimit_;
174 typename _CplexSubInf::Parameter _subInfParam;
175 _subInfParam.integerConstraint_ =
true;
176 _subInfParam.numberOfThreads_ = 1;
177 _subInfParam.timeLimit_ = param.fusionTimeLimit_;
178 typename CplexReducedSubInf::Parameter subInfParam(
true,param.tentacles_,param.connectedComponents_,_subInfParam);
188 else if(param.fusionSolver_==SelfFusionType::QpboFusion ){
201 typename HQPBOSubInf::Parameter subInfParam;
207 throw std::runtime_error(
"Unknown Fusion Type! Maybe caused by missing linking!");
242 const GraphicalModelType &
gm_;
265 template<
class INFERENCE>
295 template<
class _GM,
class _ACC>
305 const size_t fuseNth=1,
307 const typename INFERENCE::Parameter & infParam =
typename INFERENCE::Parameter(),
308 const size_t maxSubgraphSize=2,
309 const bool reducedInf =
false,
310 const bool tentacles =
false,
311 const bool connectedComponents =
false,
312 const double fusionTimeLimit = 100.0,
313 const size_t numStopIt = 10
316 fusionSolver_(fusionSolver),
318 maxSubgraphSize_(maxSubgraphSize),
319 reducedInf_(reducedInf),
320 connectedComponents_(connectedComponents),
321 tentacles_(tentacles),
322 fusionTimeLimit_(fusionTimeLimit),
323 numStopIt_(numStopIt)
334 infParam_(p.infParam_),
335 maxSubgraphSize_(p.maxSubgraphSize_),
336 reducedInf_(p.reducedInf_),
337 connectedComponents_(p.connectedComponents_),
338 tentacles_(p.tentacles_),
339 fusionTimeLimit_(p.fusionTimeLimit_),
340 numStopIt_(p.numStopIt_)
342 if(p.fusionSolver_ == 0){
343 fusionSolver_ = QpboFusion;
345 else if(p.fusionSolver_ == 1){
346 fusionSolver_ = CplexFusion;
348 else if(p.fusionSolver_ == 2){
349 fusionSolver_ = LazyFlipperFusion;
365 std::string name()
const;
366 const GraphicalModelType& graphicalModel()
const;
368 template<
class VisitorType>
370 void setStartingPoint(
typename std::vector<LabelType>::const_iterator);
394 const GraphicalModelType&
gm_;
404 template<
class INFERENCE>
407 const GraphicalModelType& gm,
414 maxOrder_(gm.factorOrder())
416 AccumulationType::neutral(
value_);
421 template<
class INFERENCE>
430 template<
class INFERENCE>
437 template<
class INFERENCE>
444 template<
class INFERENCE>
454 template<
class INFERENCE>
455 template<
class VisitorType>
461 AccumulationType::ineutral(
bound_);
462 AccumulationType::neutral(
value_);
464 visitor.begin(*
this);
465 visitor.addLog(
"infValue");
469 INFERENCE inf(
gm_,param_.infParam_);
470 inf.infer(fusionVisitor);
475 template<
class INFERENCE>
479 std::vector<LabelType>& x,
483 x.resize(
gm_.numberOfVariables());
492 #endif // #ifndef OPENGM_SELF_FUSION_HXX
IndexType numberOfFusionMoveVariable() const
INF::AccumulationType AccumulationType
FusionMoverType fusionMover_
SELF_FUSION SelfFusionType
SELF_FUSION_VISITOR SelfFusionVisitorType
INFERENCE::AccumulationType AccumulationType
INFERENCE::Parameter infParam_
Parameter(const size_t fuseNth=1, const FusionSolver fusionSolver=LazyFlipperFusion, const typename INFERENCE::Parameter &infParam=typename INFERENCE::Parameter(), const size_t maxSubgraphSize=2, const bool reducedInf=false, const bool tentacles=false, const bool connectedComponents=false, const double fusionTimeLimit=100.0, const size_t numStopIt=10)
size_t fuseVisit(INF &inference)
SelfFusionVisitorType & selfFusionVisitor_
const GraphicalModelType & gm_
void infer(const typename INF::GraphicalModelType &gm, const typename INF::Parameter ¶m, std::vector< typename INF::LabelType > &conf)
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
FusionVisitor(SelfFusionType &selfFusion, SelfFusionVisitorType &selfFusionVisitor, std::vector< LabelType > &argBest, ValueType &value, ValueType &bound, size_t fuseNth=1)
SelfFusion< RebindedInf > type
SelfFusion< RebindedInf > type
SelfFusion(const GraphicalModelType &, const Parameter &=Parameter())
size_t operator()(INF &inf)
ValueType value() const
return the solution (value)
FusionMoverType::SubGmType SubGmType
InferenceTermination infer()
GraphicalModelType::IndexType IndexType
std::vector< LabelType > & argBest_
const GraphicalModelType & graphicalModel() const
FusionSolver fusionSolver_
opengm::LazyFlipper< SubGmType, AccumulationType > LazyFlipperSubInf
const Parameter & parameter() const
SelfFusion< INFERENCE > SelfType
Optimization by Linear Programming (LP) or Integer LP using IBM ILOG CPLEX http://www.ilog.com/products/cplex/.
GraphicalModelType::ValueType ValueType
INFERENCE::template RebindGm< _GM >::type RebindedInf
std::vector< LabelType > argFromInf_
Inference algorithm interface.
std::vector< LabelType > argOut_
visitors::TimingVisitor< SelfFusion< INFERENCE > > TimingVisitorType
INFERENCE::template RebindGmAndAcc< _GM, _ACC >::type RebindedInf
static const size_t StopInfTimeout
INFERENCE::GraphicalModelType GraphicalModelType
bool connectedComponents_
INFERENCE ToFuseInferenceType
void setup(const std::vector< LabelType > &argA, const std::vector< LabelType > &argB, std::vector< LabelType > &resultArg, const ValueType valueA, const ValueType valueB)
const size_t maxOrder() const
visitors::VerboseVisitor< SelfFusion< INFERENCE > > VerboseVisitorType
GraphicalModelType::LabelType LabelType
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
visitors::EmptyVisitor< SelfFusion< INFERENCE > > EmptyVisitorType
A generalization of ICM B. Andres, J. H. Kappes, U. Koethe and Hamprecht F. A., The Lazy Flipper: MA...
SelfFusionType & selfFusion_
[class reducedinference] Reduced Inference Implementation of the reduction techniques proposed in J...
INF::GraphicalModelType GraphicalModelType
ValueType bound() const
return a bound on the solution
FusionMover< GraphicalModelType, AccumulationType > FusionMoverType