This file is indexed.

/usr/include/opengm/inference/self_fusion.hxx is in libopengm-dev 2.3.6-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#ifndef OPENGM_SELF_FUSION_HXX
#define OPENGM_SELF_FUSION_HXX

#include <vector>
#include <string>
#include <iostream>

#include "opengm/opengm.hxx"
#include "opengm/inference/visitors/visitors.hxx"
#include "opengm/inference/inference.hxx"


// Fusion Move Solver
#include "opengm/inference/lazyflipper.hxx"

#include "opengm/inference/visitors/visitors.hxx"


#ifdef WITH_CPLEX
#include "opengm/inference/lpcplex.hxx"
#endif
#ifdef WITH_QPBO
#include "QPBO.h"
#include "opengm/inference/reducedinference.hxx"
#include "opengm/inference/hqpbo.hxx"
#endif

// fusion move model generator
#include "opengm/inference/auxiliary/fusion_move/fusion_mover.hxx"


namespace opengm {
  
template<class INF,class SELF_FUSION,class SELF_FUSION_VISITOR>
struct FusionVisitor{

    typedef typename INF::AccumulationType AccumulationType;
    typedef typename INF::GraphicalModelType GraphicalModelType;
    OPENGM_GM_TYPE_TYPEDEFS;

    typedef FusionMover<GraphicalModelType,AccumulationType>    FusionMoverType ;

    typedef typename FusionMoverType::SubGmType                 SubGmType;
    // sub-inf-lf
    typedef opengm::LazyFlipper<SubGmType,AccumulationType>     LazyFlipperSubInf;


    #ifdef WITH_QPBO
    typedef kolmogorov::qpbo::QPBO<double>                          QpboSubInf;
    typedef opengm::external::QPBO<SubGmType>                       QPBOSubInf;
    typedef opengm::HQPBO<SubGmType,AccumulationType>               HQPBOSubInf;
    #endif
    #ifdef WITH_CPLEX
    typedef opengm::LPCplex<SubGmType,AccumulationType>             CplexSubInf;
    #endif

    typedef SELF_FUSION SelfFusionType;
    typedef SELF_FUSION_VISITOR SelfFusionVisitorType;

    FusionVisitor(
            SelfFusionType &            selfFusion,
            SelfFusionVisitorType &     selfFusionVisitor,
            std::vector<LabelType> &    argBest,
            ValueType &                 value,
            ValueType &                 bound,
            UInt64Type                  fuseNth=1
        )
    :   gm_(selfFusion.graphicalModel()),
        selfFusion_(selfFusion),
        selfFusionVisitor_(selfFusionVisitor), 
        fusionMover_(selfFusion.graphicalModel()),
        iteration_(0),
        fuseNth_(fuseNth),
        value_(value),
                bound_(bound),
        argFromInf_(selfFusion.graphicalModel().numberOfVariables()),
        argBest_(argBest),
        argOut_(selfFusion.graphicalModel().numberOfVariables()),
        returnFlag_(visitors::VisitorReturnFlag::ContinueInf),
        numNoProgress_(0)
    {

    }

    void begin(
        INF  & inf
    ){
        returnFlag_ =   selfFusionVisitor_(selfFusion_);
        selfFusionVisitor_.log("infValue",inf.value());
    }
    void end(
        INF  & inf
    ){
    }

    size_t operator()(
        INF  & inf
    ){
        return this->fuseVisit(inf);
    }






    size_t fuseVisit(INF & inference){

        const typename SelfFusionType::Parameter & param = selfFusion_.parameter();

        ValueType oldValue = value_;

        if(iteration_==0 ){         
            inference.arg(argBest_);
            ValueType value = inference.value();
            if(AccumulationType::bop(value,value_)){
               std::copy(argOut_.begin(),argOut_.end(),argBest_.begin());
               value_ = value;
            }
            returnFlag_ =   selfFusionVisitor_(selfFusion_);
            selfFusionVisitor_.log("infValue",value);
        }
        else if(iteration_%fuseNth_==0){
          
            inference.arg(argFromInf_);

            const ValueType infValue = inference.value();
            bound_   = inference.bound();
            lastInfValue_=infValue;
            IndexType nLocalVar=0;
            for(IndexType vi=0;vi<gm_.numberOfVariables();++vi){
                if(argBest_[vi]!=argFromInf_[vi]){
                    ++nLocalVar;
                }
            }


            // setup which to labels should be fused and declare 
            // output label vector
            fusionMover_.setup(argBest_,argFromInf_,argOut_,value_,infValue);
            // get the number of fusion-move variables
            const IndexType nFuseMoveVar=fusionMover_.numberOfFusionMoveVariable();

            if(nFuseMoveVar>0){


                if(param.fusionSolver_==SelfFusionType::LazyFlipperFusion){
                    //std::cout<<"fuse with lazy flipper "<<param.maxSubgraphSize_<<"\n";
                    value_ = fusionMover_. template fuse<LazyFlipperSubInf> (
                        typename LazyFlipperSubInf::Parameter(param.maxSubgraphSize_),true
                    );

                }
                #ifdef WITH_CPLEX
                else if(param.fusionSolver_==SelfFusionType::CplexFusion ){
#ifdef WITH_QPBO
                   // NON reduced inference
                   if(param.reducedInf_==false){
#endif  
                      //std::cout <<"ILP"<<std::endl;
                      typename CplexSubInf::Parameter p;
                      p.integerConstraint_ = true;
                      p.numberOfThreads_   = 1;
                      p.timeLimit_         = param.fusionTimeLimit_;
                      value_ = fusionMover_. template fuse<CplexSubInf> (p,true);
 #ifdef WITH_QPBO
                   } 
                   // reduced inference
                   else{
                      //std::cout <<"RILP"<<std::endl;
                      typedef typename ReducedInferenceHelper<SubGmType>::InfGmType ReducedGmType;
                      typedef opengm::LPCplex<ReducedGmType, AccumulationType>      _CplexSubInf;
                      typedef ReducedInference<SubGmType,AccumulationType,_CplexSubInf>          CplexReducedSubInf; 
                      typename _CplexSubInf::Parameter _subInfParam;
                      _subInfParam.integerConstraint_ = true; 
                      _subInfParam.numberOfThreads_   = 1;
                      _subInfParam.timeLimit_         = param.fusionTimeLimit_; 
                      typename CplexReducedSubInf::Parameter subInfParam(true,param.tentacles_,param.connectedComponents_,_subInfParam);
                      value_ = fusionMover_. template fuse<CplexReducedSubInf> (subInfParam,true); 
                   }
                  
 #endif
                   
                }
                #endif

                #ifdef WITH_QPBO
                else if(param.fusionSolver_==SelfFusionType::QpboFusion ){
                    
                    if(selfFusion_.maxOrder()<=2){
                        //std::cout<<"fuse with qpbo\n";
                        value_ = fusionMover_. template fuseQpbo<QpboSubInf> ();
                        //typename QPBOSubInf::Parameter subInfParam;
                        //subInfParam.strongPersistency_ = false;
                        //subInfParam.label_ = argBest_;
                        //value_ = fusionMover_. template fuse<QPBOSubInf> (subInfParam,false); 
                    }
                    else{
                        //std::cout<<"fuse with fix-qpbo\n";
                        //value_ = fusionMover_. template fuseFixQpbo<QpboSubInf> ();
                        typename HQPBOSubInf::Parameter subInfParam;
                        value_ = fusionMover_. template fuse<HQPBOSubInf> (subInfParam,true);
                    }
                }
                #endif
                else{
                   throw std::runtime_error("Unknown Fusion Type! Maybe caused by missing linking!");
                }


                // write fusion result into best arg
                std::copy(argOut_.begin(),argOut_.end(),argBest_.begin());

                //std::cout<<"fusionValue "<<value_<<" infValue "<<infValue<<"\n";

                returnFlag_ =  selfFusionVisitor_(selfFusion_);
                                selfFusionVisitor_.log("infValue",infValue);
            } 

            else{
               returnFlag_ =   selfFusionVisitor_(selfFusion_);
               selfFusionVisitor_.log("infValue",value_);
            }
        }
        ++iteration_;

        if(oldValue == value_){
           ++numNoProgress_;
        }else{
           numNoProgress_=0; 
        }
        
        if(numNoProgress_>=param.numStopIt_)
           return visitors::VisitorReturnFlag::StopInfTimeout;

        return returnFlag_;
    } 




    const GraphicalModelType & gm_;
    SelfFusionType & selfFusion_;
    SelfFusionVisitorType & selfFusionVisitor_;
    
    FusionMoverType fusionMover_;

    UInt64Type iteration_;
    UInt64Type fuseNth_;

    ValueType & value_;
    ValueType & bound_;

    std::vector<LabelType>      argFromInf_;
    std::vector<LabelType> &    argBest_;
    std::vector<LabelType>      argOut_;

    ValueType lastInfValue_;
    size_t returnFlag_;
    size_t numNoProgress_;

};


template<class INFERENCE>
class SelfFusion : public Inference<typename INFERENCE::GraphicalModelType, typename INFERENCE::AccumulationType>
{
public:

    typedef typename INFERENCE::AccumulationType AccumulationType;
    typedef typename INFERENCE::GraphicalModelType GraphicalModelType;
    OPENGM_GM_TYPE_TYPEDEFS;

   typedef visitors::VerboseVisitor< SelfFusion<INFERENCE> > VerboseVisitorType;
   typedef visitors::EmptyVisitor<   SelfFusion<INFERENCE> >   EmptyVisitorType;
   typedef visitors::TimingVisitor<  SelfFusion<INFERENCE> >  TimingVisitorType;

    typedef SelfFusion<INFERENCE> SelfType;

    typedef INFERENCE ToFuseInferenceType;

    enum FusionSolver{
        QpboFusion,
        CplexFusion,
        LazyFlipperFusion
    };


   class Parameter {
   public:
      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
      )
      : fuseNth_(fuseNth),
        fusionSolver_(fusionSolver),
        infParam_(infParam),
        maxSubgraphSize_(maxSubgraphSize),
        reducedInf_(reducedInf),
        connectedComponents_(connectedComponents),
        tentacles_(tentacles),
        fusionTimeLimit_(fusionTimeLimit),
        numStopIt_(numStopIt)
      {

      }
      UInt64Type fuseNth_;
      FusionSolver fusionSolver_;
      typename INFERENCE::Parameter infParam_;
      UInt64Type maxSubgraphSize_;
      bool reducedInf_;
      bool connectedComponents_;
      bool tentacles_;
      double fusionTimeLimit_;
      size_t numStopIt_;
   };

   SelfFusion(const GraphicalModelType&, const Parameter& = Parameter());
   std::string name() const;
   const GraphicalModelType& graphicalModel() const;
   InferenceTermination infer();
   template<class VisitorType>
   InferenceTermination infer(VisitorType&);
   void setStartingPoint(typename std::vector<LabelType>::const_iterator);
   virtual InferenceTermination arg(std::vector<LabelType>&, const size_t = 1) const ;

    ValueType value()const{
        return value_;
    }

    ValueType bound()const{
        return bound_;
    }

    const Parameter & parameter()const{
        return param_;
    }
    const size_t maxOrder()const{
        return maxOrder_;
    }

private:

    Parameter param_;
    size_t maxOrder_;


    const GraphicalModelType& gm_;


    std::vector<LabelType> argBest_;
    ValueType value_;
    ValueType bound_;
};



template<class INFERENCE>
SelfFusion<INFERENCE>::SelfFusion
(
      const GraphicalModelType& gm,
      const Parameter& parameter
)
:  gm_(gm),
   param_(parameter),
   argBest_(gm.numberOfVariables()),
   value_(),
   maxOrder_(gm.factorOrder())
{
    AccumulationType::neutral(value_);
}
      

   
template<class INFERENCE>
inline void 
SelfFusion<INFERENCE>::setStartingPoint
(
   typename std::vector<typename SelfFusion<INFERENCE>::LabelType>::const_iterator begin
) {

}
   
template<class INFERENCE>
inline std::string
SelfFusion<INFERENCE>::name() const
{
   return "SelfFusion";
}

template<class INFERENCE>
inline const typename SelfFusion<INFERENCE>::GraphicalModelType&
SelfFusion<INFERENCE>::graphicalModel() const
{
   return gm_;
}
  
template<class INFERENCE>
inline InferenceTermination
SelfFusion<INFERENCE>::infer()
{
   EmptyVisitorType v;
    //VerboseVisitorType v;
   return infer(v);
}

  
template<class INFERENCE>
template<class VisitorType>
InferenceTermination SelfFusion<INFERENCE>::infer
(
   VisitorType& visitor
)
{
   AccumulationType::ineutral(bound_);
   AccumulationType::neutral(value_);

   visitor.begin(*this);
   visitor.addLog("infValue");
   // the fusion visitor will do the job...
   FusionVisitor<INFERENCE,SelfType,VisitorType> fusionVisitor(*this,visitor,argBest_,value_,bound_,param_.fuseNth_);

   INFERENCE inf(gm_,param_.infParam_);
   inf.infer(fusionVisitor);
   visitor.end(*this);
   return NORMAL;
}

template<class INFERENCE>
inline InferenceTermination
SelfFusion<INFERENCE>::arg
(
      std::vector<LabelType>& x,
      const size_t N
) const
{
    x.resize(gm_.numberOfVariables());
    for(IndexType vi=0;vi<gm_.numberOfVariables();++vi){
        x[vi]=argBest_[vi];
    }
    return NORMAL;
}

} // namespace opengm

#endif // #ifndef OPENGM_SELF_FUSION_HXX