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>
294 const typename INFERENCE::Parameter & infParam =
typename INFERENCE::Parameter(),
296 const bool reducedInf =
false,
297 const bool tentacles =
false,
298 const bool connectedComponents =
false,
299 const double fusionTimeLimit = 100.0,
300 const size_t numStopIt = 10
303 fusionSolver_(fusionSolver),
305 maxSubgraphSize_(maxSubgraphSize),
306 reducedInf_(reducedInf),
307 connectedComponents_(connectedComponents),
308 tentacles_(tentacles),
309 fusionTimeLimit_(fusionTimeLimit),
310 numStopIt_(numStopIt)
326 std::string name()
const;
327 const GraphicalModelType& graphicalModel()
const;
329 template<
class VisitorType>
331 void setStartingPoint(
typename std::vector<LabelType>::const_iterator);
355 const GraphicalModelType& gm_;
358 std::vector<LabelType> argBest_;
365 template<
class INFERENCE>
368 const GraphicalModelType& gm,
373 argBest_(gm.numberOfVariables()),
375 maxOrder_(gm.factorOrder())
377 AccumulationType::neutral(value_);
382 template<
class INFERENCE>
391 template<
class INFERENCE>
398 template<
class INFERENCE>
405 template<
class INFERENCE>
415 template<
class INFERENCE>
416 template<
class VisitorType>
422 AccumulationType::ineutral(bound_);
423 AccumulationType::neutral(value_);
425 visitor.begin(*
this);
426 visitor.addLog(
"infValue");
430 INFERENCE inf(gm_,param_.infParam_);
431 inf.infer(fusionVisitor);
436 template<
class INFERENCE>
440 std::vector<LabelType>& x,
444 x.resize(gm_.numberOfVariables());
445 for(
IndexType vi=0;vi<gm_.numberOfVariables();++vi){
453 #endif // #ifndef OPENGM_SELF_FUSION_HXX
INF::AccumulationType AccumulationType
FusionMoverType fusionMover_
SELF_FUSION SelfFusionType
SELF_FUSION_VISITOR SelfFusionVisitorType
INFERENCE::AccumulationType AccumulationType
INFERENCE::Parameter infParam_
size_t fuseVisit(INF &inference)
SelfFusionVisitorType & selfFusionVisitor_
const GraphicalModelType & gm_
ValueType value() const
return the solution (value)
ValueType bound() const
return a bound on the solution
UInt64Type maxSubgraphSize_
IndexType numberOfFusionMoveVariable() const
SelfFusion(const GraphicalModelType &, const Parameter &=Parameter())
size_t operator()(INF &inf)
detail_types::UInt64Type UInt64Type
uint64
FusionMoverType::SubGmType SubGmType
InferenceTermination infer()
GraphicalModelType::IndexType IndexType
std::vector< LabelType > & argBest_
FusionSolver fusionSolver_
opengm::LazyFlipper< SubGmType, AccumulationType > LazyFlipperSubInf
SelfFusion< INFERENCE > SelfType
const Parameter & parameter() const
Optimization by Linear Programming (LP) or Integer LP using IBM ILOG CPLEX http://www.ilog.com/products/cplex/.
GraphicalModelType::ValueType ValueType
std::vector< LabelType > argFromInf_
Inference algorithm interface.
std::vector< LabelType > argOut_
visitors::TimingVisitor< SelfFusion< INFERENCE > > TimingVisitorType
static const size_t StopInfTimeout
INFERENCE::GraphicalModelType GraphicalModelType
bool connectedComponents_
const GraphicalModelType & graphicalModel() const
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
Parameter(const UInt64Type fuseNth=1, const FusionSolver fusionSolver=LazyFlipperFusion, const typename INFERENCE::Parameter &infParam=typename INFERENCE::Parameter(), const UInt64Type maxSubgraphSize=2, const bool reducedInf=false, const bool tentacles=false, const bool connectedComponents=false, const double fusionTimeLimit=100.0, const size_t numStopIt=10)
GraphicalModelType::LabelType LabelType
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
set initial labeling
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
FusionVisitor(SelfFusionType &selfFusion, SelfFusionVisitorType &selfFusionVisitor, std::vector< LabelType > &argBest, ValueType &value, ValueType &bound, UInt64Type fuseNth=1)
FusionMover< GraphicalModelType, AccumulationType > FusionMoverType