OpenGM  2.3.x
Discrete Graphical Model Library
submodel_builder.hxx
Go to the documentation of this file.
1 
2 #include "opengm/opengm.hxx"
11 
12 
13 namespace opengm{
14 
15 template<class ITER>
16 void printIter(ITER begin , ITER end){
17  while(begin!=end){
18  std::cout<<*begin<<" ";
19  ++begin;
20  }
21  std::cout<<"\n";
22 }
23 
24 
25 template<class GM,class GM_OUT>
27  const GM & gm,
28  GM_OUT & gmOut
29 ){
30  typedef typename GM::IndexType IndexType;
31  typedef typename GM::LabelType LabelType;
32  typedef typename GM::ValueType ValueType;
33  typedef typename GM::FactorType FactorType;
34  typedef typename GM::FunctionIdentifier Fid;
36 
37  typedef std::map< UInt64Type , Fid > FidMap;
38  FidMap firstOrderF;
39  FidMap secondOrderMap;
40 
41 
42 
43  for(IndexType fi=0;fi<gm.numberOfFactors();++fi){
44  const FactorType & fac = gm[fi];
45  const IndexType order = fac.numberOfVariables();
46  OPENGM_CHECK_OP(order,<=,2,"order must be <=2");
47 
48 
49  //if(fac.numberOfVariables()>=2){
50  // std::cout<<"fi = "<<fi<<" VARIABLES ";
51  // printIter(fac.variableIndicesBegin(),fac.variableIndicesEnd());
52  //}
53 
54  if(order==1 || order==2){
55 
56 
57  UInt64Type key=fac.variableIndex(0);
58  if(order==2){
59  key+=(fac.variableIndex(1)*gm.numberOfVariables());
60  }
61 
62  FidMap & fidMap = ( order == 1 ? firstOrderF : secondOrderMap );
63 
64 
65  if(fidMap.find(key)==fidMap.end()){
66  ArrayFunction function(fac.shapeBegin(),fac.shapeEnd());
67  fac.copyValues(&function(0));
68  const Fid fid = gmOut.addFunction(function);
69  gmOut.addFactor(fid,fac.variableIndicesBegin(),fac.variableIndicesEnd());
70  fidMap[key]=fid;
71  }
72 
73  else{
74  const Fid fid = fidMap[key];
75  ArrayFunction & function = gmOut. template getFunction<ArrayFunction>(fid);
76  ArrayFunction buffer(fac.shapeBegin(),fac.shapeEnd());
77  fac.copyValues(&buffer(0));
78  // update function
79  function+=buffer;
80  }
81 
82  }
83  else{
84 
85  }
86 
87  }
88 
89  /*
90  for(IndexType fi=0;fi<gmOut.numberOfFactors();++fi){
91  const IndexType order = gmOut[fi].numberOfVariables();
92  OPENGM_CHECK_OP(order,<=,2,"order must be <=2");
93 
94  if(gmOut[fi].numberOfVariables()>=2){
95  std::cout<<"fi = "<<fi<<" OUT VAR ";
96  printIter(gmOut[fi].variableIndicesBegin(),gmOut[fi].variableIndicesEnd());
97  }
98  }
99  */
100 
101 }
102 
103 
104 
105 
106 
107 template<class GM,class ACC>
109 
110 public:
111  typedef GM GraphicalModelType;
112  typedef ACC AccumulationType;
114 
115 
116 
117  // function types
120  typedef PositionAndLabel<IndexType,LabelType> PosAndLabel;
121  typedef std::vector<PosAndLabel> PosAndLabelVector;
122 
124 
125  // sub gm
127  typedef typename meta::TypeListGenerator< ViewingFunction,FixFunction >::type SubFunctionTypeList;
128  typedef typename meta::TypeListGenerator< ArrayFunction >::type MergeSubFunctionTypeList;
129 
132 
133  SubmodelOptimizer(const GM & gm)
134  : gm_(gm),
135  localVariables_(gm.numberOfVariables()),
136  globalToLocalVariables_(gm.numberOfVariables()),
137  submodelSpace_(gm.numberOfVariables()),
138  inSubmodel_(gm.numberOfVariables(),false),
139  localFactorViBuffer_(),
140  fixedVarPosBuffer_(),
141  notFixedVarPosBuffer_(),
142  nLocalVar_(0),
143  handledFactor_(gm.numberOfFactors(),false),
144  labels_(gm.numberOfVariables())
145  {
146  //std::cout<<"submodel constructor\n";
147  const IndexType maxOrder = gm_.factorOrder();
148  localFactorViBuffer_.resize(maxOrder);
149  fixedVarPosBuffer_.resize(maxOrder);
150  notFixedVarPosBuffer_.resize(maxOrder);
151  //std::cout<<"submodel constructor done\n";
152  }
153 
154 
155 
156  struct InfResult{
157 
158  };
159 
160  struct SubmodelInfo{
161 
162  };
163 
164 
165 
166  // set current state
167  // O( CONST )
168  void setLabel(const IndexType vi,const LabelType label){
169  labels_[vi]=label;
170  }
171 
172  // set and unset subvariables
173  // O( |SUB_VARIABLES| )
174  template<class VI_ITER>
175  void setVariableIndices(VI_ITER begin,VI_ITER end){
176  /*
177  for(IndexType vi=0;vi<gm_.numberOfVariables();++vi){
178  OPENGM_CHECK(inSubmodel_[vi]==false,"");
179  }
180  */
181  OPENGM_CHECK_OP(nLocalVar_,==,0,"internal error");
182  nLocalVar_=std::distance(begin,end);
183  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
184  const IndexType globalVi = begin[localVi];
185  OPENGM_CHECK_OP(globalVi,<,gm_.numberOfVariables(),"");
186  localVariables_[localVi]=globalVi;
187  submodelSpace_[localVi]=gm_.numberOfLabels(globalVi);
188  globalToLocalVariables_[globalVi]=localVi;
189  OPENGM_CHECK(inSubmodel_[globalVi]==false,"internal error");
190  inSubmodel_[globalVi]=true;
191  }
192  }
193 
194  // unset all subvariables
195  // O( |SUB_VARIABLES| )
197  OPENGM_CHECK_OP(nLocalVar_,>,0,"internal error");
198  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
199  const IndexType globalVi = localVariables_[localVi];
200  OPENGM_CHECK(inSubmodel_[globalVi]==true,"internal error");
201  inSubmodel_[globalVi]=false;
202  }
203 
204  nLocalVar_=0;
205 
206  /*
207  for(IndexType vi=0;vi<gm_.numberOfVariables();++vi){
208  OPENGM_CHECK(inSubmodel_[vi]==false,"");
209  }
210  */
211 
212 
213  }
214 
215 
216 
217  // build and infer with template
218  template<class SOLVER>
220  const typename SOLVER::Parameter & para ,
221  std::vector<LabelType> & resultArg,
222  const bool improving=true,
223  const bool warmStart=false
224  ){
225  OPENGM_CHECK_OP(nLocalVar_,!=,0,"");
226 
227  if(resultArg.size()!=nLocalVar_){
228  resultArg.resize(nLocalVar_);
229  }
230 
231  SOLVER solver(submodelSpace_.begin(),submodelSpace_.begin()+nLocalVar_,para);
232  buildModelInplace(solver);
233  if(warmStart){
234  for(IndexType viLocal=0;viLocal<nLocalVar_;++viLocal){
235  resultArg[viLocal]=labels_[localVariables_[viLocal]];
236  }
237  solver.setStartingPoint(resultArg.begin());
238  }
239  solver.infer();
240  solver.arg(resultArg);
241 
242  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
243  const IndexType globalVi=localVariables_[localVi];
244  if(resultArg[localVi]!=labels_[globalVi]){
245  return true;
246  }
247  }
248  return false;
249  }
250 
251  template<class SOLVER>
253  const typename SOLVER::Parameter & para ,
254  std::vector<LabelType> & resultArg,
255  const bool improving=true,
256  const bool warmStart=false
257  ){
258  OPENGM_CHECK_OP(nLocalVar_,!=,0,"");
259  if(resultArg.size()!=nLocalVar_){
260  resultArg.resize(nLocalVar_);
261  }
262  SubGmType subGm( SubSpaceType(submodelSpace_.begin(),submodelSpace_.begin()+nLocalVar_) );
263  reserveGraphicalModel(subGm);
264  buildModelOpenGm(subGm);
265  SOLVER solver(subGm,para);
266  if(warmStart){
267  for(IndexType viLocal=0;viLocal<nLocalVar_;++viLocal){
268  resultArg[viLocal]=labels_[localVariables_[viLocal]];
269  }
270  solver.setStartingPoint(resultArg.begin());
271  }
272  solver.infer();
273  solver.arg(resultArg);
274 
275  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
276  const IndexType globalVi=localVariables_[localVi];
277  if(resultArg[localVi]!=labels_[globalVi]){
278  return true;
279  }
280  }
281  return false;
282  }
283 
284 
285 
286  //template<class SOLVER>
288  //const typename SOLVER::Parameter & para ,
289  std::vector<LabelType> & resultArg
290  ){
291  OPENGM_CHECK_OP(nLocalVar_,!=,0,"");
292  if(resultArg.size()!=nLocalVar_){
293  resultArg.resize(nLocalVar_);
294  }
295  SubGmType subGm( SubSpaceType(submodelSpace_.begin(),submodelSpace_.begin()+nLocalVar_) );
296  reserveGraphicalModel(subGm);
297  buildModelOpenGm(subGm);
298 
299 
300  MergedSubGmType mergeGm( SubSpaceType(submodelSpace_.begin(),submodelSpace_.begin()+nLocalVar_) );
301 
302  mergeFactors(subGm,mergeGm);
303 
305 
306  DpSubInf solver(mergeGm);
307  solver.infer();
308  solver.arg(resultArg);
309 
310  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
311  const IndexType globalVi=localVariables_[localVi];
312  if(resultArg[localVi]!=labels_[globalVi]){
313  return true;
314  }
315  }
316  return false;
317  }
318 
319 
320  // build model inplace for a given solver
321  void reserveGraphicalModel(SubGmType & subGm){
322  OPENGM_CHECK_OP(nLocalVar_,!=,0,"");
323 
324  IndexType nFac = 0; // nFac
325  IndexType nFullUnaries = 0; // (full) included unaries
326  IndexType nFullHighOrder = 0; // full included high order
327  IndexType nFixeHighOrder = 0; // high order which are lower but still high order
328  IndexType nFixedUnary = 0; // high order which are now unaries
329  IndexType facVisSpace = 0;
330 
331  /*
332  for(IndexType fi=0;fi<gm_.numberOfFactors();++fi){
333  OPENGM_CHECK(handledFactor_[fi]==false,"internal error");
334  }
335 
336  IndexType c=0;
337  for(IndexType vi=0;vi<gm_.numberOfVariables();++vi){
338  if(inSubmodel_[vi]==true){
339  ++c;
340  }
341  }
342  OPENGM_CHECK_OP(c,==,nLocalVar_,"");
343  */
344 
345  // Counting all that stuff
346  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
347  const IndexType globalVi = localVariables_[localVi];
348  OPENGM_CHECK(inSubmodel_[globalVi],"");
349  OPENGM_CHECK_OP(globalToLocalVariables_[globalVi],==,localVi,"internal error...mapping invalid");
350  // get all factors for variable "globalVi"
351  // and iterate over them
352  const IndexType nFacVar = gm_.numberOfFactors(globalVi);
353  for(IndexType f=0;f<nFacVar;++f){
354  const IndexType fi = gm_.factorOfVariable(globalVi,f);
355  if(handledFactor_[fi]==false){
356  handledFactor_[fi]=true;
357 
358  const FactorType & factor = gm_[fi];
359  const IndexType order = factor.numberOfVariables();
360 
361  // if factor is unary :
362  if(order == 0){
363  OPENGM_CHECK(false,"order==0 is not yet supported");
364  }
365  else if(order == 1){
366 
367  const IndexType viGlobal = factor.variableIndex(0);
368  const IndexType viLocal = globalToLocalVariables_[viGlobal];
369  OPENGM_CHECK_OP(viGlobal,==,globalVi,"");
370  OPENGM_CHECK_OP(viLocal,==,localVi,"");
371  ++nFac;
372  ++nFullUnaries;
373  ++facVisSpace;
374  }
375  // if factor is higher order we need to check
376  // if the factor needs to be inclued completely
377  // or only partial
378  else{
379  /*
380  bool foundOwn=false;
381  for(IndexType v=0;v<order;++v){
382  const IndexType facVi=factor.variableIndex(v);
383  const IndexType facViDGB=gm_[fi].variableIndex(v);
384  OPENGM_CHECK_OP(facVi,==,facViDGB,"");
385  if(facVi==globalVi){
386  foundOwn=true;
387  break;
388  }
389  }
390  OPENGM_CHECK(foundOwn,"");
391  OPENGM_CHECK_OP(order,>=,2,"");
392  */
393 
394  IndexType fixedVars = 0;
395  IndexType notFixedVars = 0;
396  for(IndexType v=0;v<order;++v){
397  const IndexType facVi=factor.variableIndex(v);
398  if(inSubmodel_[facVi]==false){
399  fixedVarPosBuffer_[fixedVars]=v;
400  ++fixedVars;
401  }
402  else{
403  notFixedVarPosBuffer_[notFixedVars]=v;
404  ++notFixedVars;
405  }
406  }
407  const IndexType partialOrder = order - fixedVars;
408  OPENGM_CHECK_OP(notFixedVars,>,0,"");
409  OPENGM_CHECK_OP(fixedVars+notFixedVars,==,order,"internal error");
410  OPENGM_CHECK_OP(partialOrder,<=,order,"internal error");
411  OPENGM_CHECK_OP(partialOrder,>=,1,"internal error");
412  // if higher order factor is fuly included
413  if(fixedVars==0){
414  ++nFac;
415  ++nFullHighOrder;
416  facVisSpace+=order;
417  }
418  else{
419  ++nFac;
420  facVisSpace+=partialOrder;
421  if(partialOrder==1)
422  ++nFixedUnary;
423  else
424  ++nFixeHighOrder;
425  }
426  }
427  }
428  }
429  }
430 
431 
432 
433 
434  // CLEANUP
435  // - clean all used factors
436  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
437  const IndexType globalVi = localVariables_[localVi];
438  // get all factors for variable "globalVi"
439  // and iterate over them
440  const IndexType nFac = gm_.numberOfFactors(globalVi);
441  for(IndexType f=0;f<nFac;++f){
442  const IndexType fi = gm_.factorOfVariable(globalVi,f);
443  handledFactor_[fi]=false;
444  }
445  }
446 
447  OPENGM_CHECK_OP(nFac,==,nFullUnaries+nFullHighOrder+nFixeHighOrder+nFixedUnary,"");
448  subGm.reserveFactors(nFac);
449  subGm.reserveFactorsVarialbeIndices(facVisSpace);
450  subGm. template reserveFunctions<ViewingFunction> (nFullUnaries+nFullHighOrder);
451  subGm. template reserveFunctions<FixFunction> (nFixeHighOrder+nFixedUnary);
452 
453  }
454  // build model inplace for a given solver
455  void buildModelOpenGm(SubGmType & subGm){
456 
457  /*
458  for(IndexType fi=0;fi<gm_.numberOfFactors();++fi){
459  OPENGM_CHECK(handledFactor_[fi]==false,"internal error");
460  }
461  */
462 
463  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
464  const IndexType globalVi = localVariables_[localVi];
465  // get all factors for variable "globalVi"
466  // and iterate over them
467  const IndexType nFac = gm_.numberOfFactors(globalVi);
468  for(IndexType f=0;f<nFac;++f){
469  const IndexType fi = gm_.factorOfVariable(globalVi,f);
470  if(handledFactor_[fi]==false){
471  handledFactor_[fi]=true;
472 
473  const FactorType & factor = gm_[fi];
474  const IndexType order = factor.numberOfVariables();
475 
476 
477  // if factor is unary :
478  // - factor needs to be added to the submodel
479  if(order == 1){
480  const IndexType viGlobal = factor.variableIndex(0);
481  const IndexType viLocal = globalToLocalVariables_[viGlobal];
482  OPENGM_CHECK_OP(viLocal,==,localVi,"");
483  OPENGM_CHECK_OP(viLocal,<,nLocalVar_,"");
484  subGm.addFactor(subGm.addFunction(ViewingFunction(factor)),&viLocal,&viLocal+1);
485  }
486  // if factor is higher order we need to check
487  // if the factor needs to be inclued completely
488  // or only partial
489  else{
490 
491  IndexType fixedVars = 0;
492  IndexType notFixedVars = 0;
493  for(IndexType v=0;v<order;++v){
494  const IndexType facVi=factor.variableIndex(v);
495  if(!inSubmodel_[facVi]){
496  fixedVarPosBuffer_[fixedVars]=v;
497  ++fixedVars;
498  }
499  else{
500  notFixedVarPosBuffer_[notFixedVars]=v;
501  ++notFixedVars;
502  }
503  }
504  const IndexType partialOrder = order - fixedVars;
505  OPENGM_CHECK_OP(notFixedVars,>,0,"");
506  OPENGM_CHECK_OP(fixedVars+notFixedVars,==,order,"internal error");
507  OPENGM_CHECK_OP(partialOrder,<=,order,"internal error");
508  OPENGM_CHECK_OP(partialOrder,>=,1,"internal error");
509  // if higher order factor is fuly included
510  if(fixedVars==0){
511  // map factors indices from global to local
512  for(IndexType v=0;v<order;++v){
513  const IndexType facVi=factor.variableIndex(v);
514  localFactorViBuffer_[v]=globalToLocalVariables_[facVi];
515  OPENGM_CHECK_OP(localFactorViBuffer_[v],<,nLocalVar_,"");
516  }
517  // add higher order factor
518  subGm.addFactor(subGm.addFunction(ViewingFunction(factor)),
519  localFactorViBuffer_.begin(),localFactorViBuffer_.begin()+order);
520  }
521  else{
522  PosAndLabelVector positionsAndLabelsOfFixedVars(fixedVars);
523 
524  // map factor indices from global to local
525  for(IndexType v=0;v<partialOrder;++v){
526  const IndexType facVi=factor.variableIndex(notFixedVarPosBuffer_[v]);
527  localFactorViBuffer_[v]=globalToLocalVariables_[facVi];
528  OPENGM_CHECK_OP(localFactorViBuffer_[v],<,nLocalVar_,"");
529  }
530 
531  for(IndexType fv=0;fv<fixedVars;++fv){
532  const IndexType facVi=factor.variableIndex(fixedVarPosBuffer_[fv]);
533  positionsAndLabelsOfFixedVars[fv].position_ = fixedVarPosBuffer_[fv];
534  positionsAndLabelsOfFixedVars[fv].label_ = labels_[facVi];
535  }
536  // add partial fixed factor
537  subGm.addFactor(subGm.addFunction(FixFunction(factor,positionsAndLabelsOfFixedVars)),
538  localFactorViBuffer_.begin(),localFactorViBuffer_.begin()+order-fixedVars);
539  }
540  }
541  }
542  }
543  }
544 
545  // CLEANUP
546  // - clean all used factors
547  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
548  const IndexType globalVi = localVariables_[localVi];
549  // get all factors for variable "globalVi"
550  // and iterate over them
551  const IndexType nFac = gm_.numberOfFactors(globalVi);
552  for(IndexType f=0;f<nFac;++f){
553  const IndexType fi = gm_.factorOfVariable(globalVi,f);
554  handledFactor_[fi]=false;
555  }
556  }
557  }
558 
559  // build model inplace for a given solver
560  template<class INF_TYPE>
561  void buildModelInplace(INF_TYPE & infType){
562 
563  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
564  const IndexType globalVi = localVariables_[localVi];
565  // get all factors for variable "globalVi"
566  // and iterate over them
567  const IndexType nFac = gm_.numberOfFactors(globalVi);
568  for(IndexType f=0;f<nFac;++f){
569  const IndexType fi = gm_.factorOfVariable(globalVi,f);
570  if(handledFactor_[fi]==false){
571  handledFactor_[fi]=true;
572 
573  const FactorType & factor = gm_[fi];
574  const IndexType order = factor.numberOfVariables();
575 
576 
577  // if factor is unary :
578  // - factor needs to be added to the submodel
579  if(order == 1){
580  const IndexType viGlobal = factor.variableIndex(0);
581  const IndexType viLocal = globalToLocalVariables_[viGlobal];
582  OPENGM_CHECK_OP(viLocal,<,nLocalVar_,"");
583  infType.addFactor(&viLocal,&viLocal+1,factor);
584  }
585  // if factor is higher order we need to check
586  // if the factor needs to be inclued completely
587  // or only partial
588  else{
589 
590  IndexType fixedVars = 0;
591  IndexType notFixedVars = 0;
592  for(IndexType v=0;v<order;++v){
593  const IndexType facVi=factor.variableIndex(v);
594  if(!inSubmodel_[facVi]){
595  fixedVarPosBuffer_[fixedVars]=v;
596  ++fixedVars;
597  }
598  else{
599  notFixedVarPosBuffer_[notFixedVars]=v;
600  ++notFixedVars;
601  }
602  }
603  const IndexType partialOrder = order - fixedVars;
604  OPENGM_CHECK_OP(fixedVars+notFixedVars,==,order,"internal error");
605  OPENGM_CHECK_OP(partialOrder,<=,order,"internal error");
606  OPENGM_CHECK_OP(partialOrder,>=,1,"internal error");
607  // if higher order factor is fuly included
608  if(fixedVars==0){
609  // map factors indices from global to local
610  for(IndexType v=0;v<order;++v){
611  const IndexType facVi=factor.variableIndex(v);
612  localFactorViBuffer_[v]=globalToLocalVariables_[facVi];
613  OPENGM_CHECK_OP(localFactorViBuffer_[v],<,nLocalVar_,"");
614  }
615  // add higher order factor
616  infType.addFactor(localFactorViBuffer_.begin(),localFactorViBuffer_.begin()+order,factor);
617  }
618  else{
619  PosAndLabelVector positionsAndLabelsOfFixedVars(fixedVars);
620 
621  // map factor indices from global to local
622  for(IndexType v=0;v<partialOrder;++v){
623  const IndexType facVi=factor.variableIndex(notFixedVarPosBuffer_[v]);
624  localFactorViBuffer_[v]=globalToLocalVariables_[facVi];
625  OPENGM_CHECK_OP(localFactorViBuffer_[v],<,nLocalVar_,"");
626  }
627 
628  for(IndexType fv=0;fv<fixedVars;++fv){
629  const IndexType facVi=factor.variableIndex(fixedVarPosBuffer_[fv]);
630  positionsAndLabelsOfFixedVars[fv].position_ = fixedVarPosBuffer_[fv];
631  positionsAndLabelsOfFixedVars[fv].label_ = labels_[facVi];
632  }
633  // add partial fixed factor
634  infType.addFactor(localFactorViBuffer_.begin(),localFactorViBuffer_.begin()+order-fixedVars,
635  FixFunction(factor,positionsAndLabelsOfFixedVars));
636  }
637  }
638  }
639  }
640  }
641 
642  // CLEANUP
643  // - clean all used factors
644  for(IndexType localVi=0;localVi<nLocalVar_;++localVi){
645  const IndexType globalVi = localVariables_[localVi];
646  // get all factors for variable "globalVi"
647  // and iterate over them
648  const IndexType nFac = gm_.numberOfFactors(globalVi);
649  for(IndexType f=0;f<nFac;++f){
650  const IndexType fi = gm_.factorOfVariable(globalVi,f);
651  handledFactor_[fi]=false;
652  }
653  }
654  }
655 
656 
657  bool inSubmodel(const IndexType vi)const{
658  return inSubmodel_[vi];
659  }
660 
661  IndexType submodelSize()const{
662  return nLocalVar_;
663  }
664 
665 
666 private:
667  const GM & gm_;
668 
669 
670  // submodel
671  std::vector<IndexType> localVariables_;
672  std::vector<IndexType> globalToLocalVariables_;
673  std::vector<LabelType> submodelSpace_;
674  std::vector<bool> inSubmodel_;
675  std::vector<IndexType> localFactorViBuffer_;
676  std::vector<IndexType> fixedVarPosBuffer_;
677  std::vector<IndexType> notFixedVarPosBuffer_;
678  IndexType nLocalVar_;
679 
680 
681  // factors
682  std::vector<bool> handledFactor_;
683 
684  // global labels
685  std::vector<LabelType> labels_;
686 
687 
688 
689 };
690 
691 }
692 
693 
694 
IndexType addFactor(const FunctionIdentifier &, ITERATOR, ITERATOR)
add a factor to the graphical model
The OpenGM namespace.
Definition: config.hxx:43
Discrete space in which variables can have differently many labels.
meta::TypeListGenerator< ViewingFunction, FixFunction >::type SubFunctionTypeList
FunctionIdentifier addFunction(const FUNCTION_TYPE &)
add a function to the graphical model
bool inferSubmodel(const typename SOLVER::Parameter &para, std::vector< LabelType > &resultArg, const bool improving=true, const bool warmStart=false)
PositionAndLabel< IndexType, LabelType > PosAndLabel
void printIter(ITER begin, ITER end)
bool mergeFactorsAndInferDp(std::vector< LabelType > &resultArg)
void buildModelOpenGm(SubGmType &subGm)
bool inferSubmodelInplace(const typename SOLVER::Parameter &para, std::vector< LabelType > &resultArg, const bool improving=true, const bool warmStart=false)
void buildModelInplace(INF_TYPE &infType)
void reserveFactors(const size_t numF)
detail_types::UInt64Type UInt64Type
uint64
Definition: config.hxx:300
IndexType submodelSize() const
void mergeFactors(const GM &gm, GM_OUT &gmOut)
reference to a Factor of a GraphicalModel
Definition: view.hxx:13
void setVariableIndices(VI_ITER begin, VI_ITER end)
void reserveFactorsVarialbeIndices(const size_t size)
ViewFixVariablesFunction< GM > FixFunction
meta::TypeListGenerator< ArrayFunction >::type MergeSubFunctionTypeList
std::vector< PosAndLabel > PosAndLabelVector
opengm::DiscreteSpace< IndexType, LabelType > SubSpaceType
bool inSubmodel(const IndexType vi) const
GraphicalModel< ValueType, typename GM::OperatorType, SubFunctionTypeList, SubSpaceType > SubGmType
GraphicalModel< ValueType, typename GM::OperatorType, MergeSubFunctionTypeList, SubSpaceType > MergedSubGmType
#define OPENGM_CHECK_OP(A, OP, B, TXT)
Definition: submodel2.hxx:24
ExplicitFunction< ValueType, IndexType, LabelType > ArrayFunction
Funcion that refers to a factor of another GraphicalModel in which some variables are fixed...
#define OPENGM_CHECK(B, TXT)
Definition: submodel2.hxx:28
ViewFunction< GM > ViewingFunction
void setLabel(const IndexType vi, const LabelType label)
void reserveGraphicalModel(SubGmType &subGm)