OpenGM  2.3.x
Discrete Graphical Model Library
num_labels_limitation_function.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_NUM_LABELS_LIMITATION_FUNCTION_HXX_
2 #define OPENGM_NUM_LABELS_LIMITATION_FUNCTION_HXX_
3 
4 #include <opengm/opengm.hxx>
6 
11 
12 namespace opengm {
13 
14 /*********************
15  * class definition *
16  *********************/
17 template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
18 class NumLabelsLimitationFunction : public LinearConstraintFunctionBase<NumLabelsLimitationFunction<VALUE_TYPE,INDEX_TYPE, LABEL_TYPE> > {
19 public:
20  // typedefs
24  typedef typename LinearConstraintFunctionTraitsType::ValueType ValueType;
25  typedef typename LinearConstraintFunctionTraitsType::IndexType IndexType;
26  typedef typename LinearConstraintFunctionTraitsType::LabelType LabelType;
27  typedef typename LinearConstraintFunctionTraitsType::LinearConstraintType LinearConstraintType;
28  typedef typename LinearConstraintFunctionTraitsType::LinearConstraintsContainerType LinearConstraintsContainerType;
29  typedef typename LinearConstraintFunctionTraitsType::LinearConstraintsIteratorType LinearConstraintsIteratorType;
30  typedef typename LinearConstraintFunctionTraitsType::IndicatorVariablesContainerType IndicatorVariablesContainerType;
31  typedef typename LinearConstraintFunctionTraitsType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType;
32  typedef typename LinearConstraintFunctionTraitsType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType;
33  typedef typename LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsIteratorType ViolatedLinearConstraintsIteratorType;
34  typedef typename LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsContainerType ViolatedLinearConstraintsWeightsContainerType;
35  typedef typename LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsIteratorType ViolatedLinearConstraintsWeightsIteratorType;
36 
37  // constructors
39  template <class SHAPE_ITERATOR_TYPE>
40  NumLabelsLimitationFunction(SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, const LabelType maxNumUsedLabels, const ValueType returnValid = 0.0, const ValueType returnInvalid = 1.0);
41  NumLabelsLimitationFunction(const IndexType numVariables, const LabelType numLabels, const LabelType maxNumUsedLabels, const ValueType returnValid = 0.0, const ValueType returnInvalid = 1.0);
43 
44  // function access
45  template<class Iterator>
46  ValueType operator()(Iterator statesBegin) const; // function evaluation
47  size_t shape(const size_t i) const; // number of labels of the indicated input variable
48  size_t dimension() const; // number of input variables
49  size_t size() const; // number of parameters
50 
51  // specializations
52  ValueType min() const;
53  ValueType max() const;
54  MinMaxFunctor<ValueType> minMax() const;
55 
56 protected:
57  // storage
58  std::vector<LabelType> shape_;
59  size_t numVariables_;
61  LabelType maxNumLabels_;
62  LabelType maxNumUsedLabels_;
63  size_t size_;
64  ValueType returnValid_;
65  ValueType returnInvalid_;
66  LinearConstraintsContainerType constraints_;
67  mutable std::vector<size_t> violatedConstraintsIds_;
68  mutable ViolatedLinearConstraintsWeightsContainerType violatedConstraintsWeights_;
69  IndicatorVariablesContainerType indicatorVariableList_;
70 
71  // implementations for LinearConstraintFunctionBase
72  LinearConstraintsIteratorType linearConstraintsBegin_impl() const;
73  LinearConstraintsIteratorType linearConstraintsEnd_impl() const;
74  IndicatorVariablesIteratorType indicatorVariablesOrderBegin_impl() const;
75  IndicatorVariablesIteratorType indicatorVariablesOrderEnd_impl() const;
76  template <class LABEL_ITERATOR>
77  void challenge_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance = 0.0) const;
78  template <class LABEL_ITERATOR>
79  void challengeRelaxed_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance = 0.0) const;
80 
81  // helper functions
83  void createConstraints();
84 
85  // friends
86  friend class FunctionSerialization<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >;
87  friend class opengm::LinearConstraintFunctionBase<NumLabelsLimitationFunction<VALUE_TYPE,INDEX_TYPE, LABEL_TYPE> >;
88 };
89 
90 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
91 struct LinearConstraintFunctionTraits<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> > {
92  // typedefs
93  typedef VALUE_TYPE ValueType;
94  typedef INDEX_TYPE IndexType;
95  typedef LABEL_TYPE LabelType;
97  typedef std::vector<LinearConstraintType> LinearConstraintsContainerType;
98  typedef typename LinearConstraintsContainerType::const_iterator LinearConstraintsIteratorType;
104  typedef typename ViolatedLinearConstraintsWeightsContainerType::const_iterator ViolatedLinearConstraintsWeightsIteratorType;
105 };
106 
109 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
110 struct FunctionRegistration<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> > {
111  enum ID {
112  // TODO set final Id
114  };
115 };
116 
118 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
119 class FunctionSerialization<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> > {
120 public:
121  typedef typename NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::ValueType ValueType;
122 
123  static size_t indexSequenceSize(const NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&);
124  static size_t valueSequenceSize(const NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&);
125  template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR>
126  static void serialize(const NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&, INDEX_OUTPUT_ITERATOR, VALUE_OUTPUT_ITERATOR);
127  template<class INDEX_INPUT_ITERATOR, class VALUE_INPUT_ITERATOR>
128  static void deserialize( INDEX_INPUT_ITERATOR, VALUE_INPUT_ITERATOR, NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&);
129 };
131 
132 /***********************
133  * class documentation *
134  ***********************/
440 /******************
441  * implementation *
442  ******************/
443 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
445 : shape_(), numVariables_(), useSameNumLabels_(), maxNumLabels_(),
446  maxNumUsedLabels_(), size_(), returnValid_(), returnInvalid_(),
447  constraints_(), violatedConstraintsIds_(), violatedConstraintsWeights_(),
448  indicatorVariableList_() {
449 
450 }
451 
452 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
453 template <class SHAPE_ITERATOR_TYPE>
454 inline NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::NumLabelsLimitationFunction(SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, const LabelType maxNumUsedLabels, const ValueType returnValid, const ValueType returnInvalid)
455 : shape_(shapeBegin, shapeEnd), numVariables_(shape_.size()),
456  useSameNumLabels_(numVariables_ > 0 ? std::equal(shape_.begin() + 1, shape_.end(), shape_.begin()) : true),
457  maxNumLabels_(numVariables_ > 0 ? *std::max_element(shape_.begin(), shape_.end()) : 0),
458  maxNumUsedLabels_(maxNumUsedLabels),
459  size_(std::accumulate(shapeBegin, shapeEnd, 1, std::multiplies<typename std::iterator_traits<SHAPE_ITERATOR_TYPE>::value_type>())),
460  returnValid_(returnValid), returnInvalid_(returnInvalid),
461  constraints_(1), violatedConstraintsIds_(1), violatedConstraintsWeights_(1),
462  indicatorVariableList_(maxNumLabels_) {
463  // fill indicator variable list
465 
466  // create linear constraints
468 }
469 
470 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
471 inline NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::NumLabelsLimitationFunction(const IndexType numVariables, const LabelType numLabels, const LabelType maxNumUsedLabels, const ValueType returnValid, const ValueType returnInvalid)
472 : shape_(), numVariables_(numVariables), useSameNumLabels_(true),
473  maxNumLabels_(numLabels), maxNumUsedLabels_(maxNumUsedLabels),
474  size_(unsignedIntegerPow(maxNumLabels_, numVariables_)),
475  returnValid_(returnValid), returnInvalid_(returnInvalid),
476  constraints_(1), violatedConstraintsIds_(1), violatedConstraintsWeights_(1),
477  indicatorVariableList_(maxNumLabels_) {
478  // fill indicator variable list
480 
481  // create linear constraints
483 }
484 
485 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
487 
488 }
489 
490 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
491 template<class Iterator>
493  std::vector<bool> labelIsUsed(maxNumLabels_, false);
494  LabelType maxNumLabelsFound = 0;
495  const Iterator statesEnd = statesBegin + numVariables_;
496  while(statesBegin != statesEnd) {
497  const LabelType currentLabel = *statesBegin;
498  OPENGM_ASSERT(currentLabel < maxNumLabels_);
499  if(!labelIsUsed[currentLabel]) {
500  labelIsUsed[currentLabel] = true;
501  ++maxNumLabelsFound;
502  if(maxNumLabelsFound > maxNumUsedLabels_) {
503  return returnInvalid_;
504  }
505  }
506  ++statesBegin;
507  }
508  return returnValid_;
509 }
510 
511 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
513  OPENGM_ASSERT(i < numVariables_);
514  return (useSameNumLabels_ ? maxNumLabels_ : shape_[i]);
515 }
516 
517 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
519  return numVariables_;
520 }
521 
522 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
524  return size_;
525 }
526 
527 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
529  return returnValid_ < returnInvalid_ ? returnValid_ : returnInvalid_;
530 }
531 
532 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
534  return returnValid_ > returnInvalid_ ? returnValid_ : returnInvalid_;
535 }
536 
537 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
538 inline MinMaxFunctor<typename NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::ValueType> NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::minMax() const {
539  if(returnValid_ < returnInvalid_) {
540  return MinMaxFunctor<VALUE_TYPE>(returnValid_, returnInvalid_);
541  }
542  else {
543  return MinMaxFunctor<VALUE_TYPE>(returnInvalid_, returnValid_);
544  }
545 }
546 
547 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
549  return constraints_.begin();
550 }
551 
552 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
554  return constraints_.end();
555 }
556 
557 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
559  return indicatorVariableList_.begin();
560 }
561 
562 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
564  return indicatorVariableList_.end();
565 }
566 
567 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
568 template <class LABEL_ITERATOR>
569 inline void NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::challenge_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance) const {
570  std::vector<bool> labelIsUsed(maxNumLabels_, false);
571  ValueType maxNumLabelsFound = 0;
572  const LABEL_ITERATOR labelingEnd = labelingBegin + numVariables_;
573  while(labelingBegin != labelingEnd) {
574  const LabelType currentLabel = *labelingBegin;
575  OPENGM_ASSERT(currentLabel < maxNumLabels_);
576  if(!labelIsUsed[currentLabel]) {
577  labelIsUsed[currentLabel] = true;
578  ++maxNumLabelsFound;
579  if(maxNumLabelsFound == static_cast<ValueType>(maxNumLabels_)) {
580  // all labels are used
581  break;
582  }
583  }
584  ++labelingBegin;
585  }
586 
587  const ValueType weight = maxNumLabelsFound - static_cast<ValueType>(maxNumUsedLabels_);
588  if(weight <= tolerance) {
589  violatedConstraintsBegin = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 0);
590  violatedConstraintsEnd = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 0);
591  violatedConstraintsWeightsBegin = violatedConstraintsWeights_.begin();
592  } else {
593  violatedConstraintsIds_[0] = 0;
594  violatedConstraintsWeights_[0] = weight;
595  violatedConstraintsBegin = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 0);
596  violatedConstraintsEnd = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 1);
597  violatedConstraintsWeightsBegin = violatedConstraintsWeights_.begin();
598  return;
599  }
600 }
601 
602 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
603 template <class LABEL_ITERATOR>
604 inline void NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::challengeRelaxed_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance) const {
605  double weight = -static_cast<double>(maxNumUsedLabels_);
606  for(LabelType i = 0; i < maxNumLabels_; ++i) {
607  weight += labelingBegin[i];
608  }
609 
610  violatedConstraintsBegin = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 0);
611 
612  if(weight > tolerance) {
613  violatedConstraintsIds_[0] = 0;
614  violatedConstraintsWeights_[0] = weight;
615  violatedConstraintsEnd = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 1);
616  violatedConstraintsWeightsBegin = violatedConstraintsWeights_.begin();
617  } else {
618  violatedConstraintsEnd = ViolatedLinearConstraintsIteratorType(constraints_.begin(), violatedConstraintsIds_.begin(), 0);
619  }
620 }
621 
622 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
624  for(LabelType i = 0; i < maxNumLabels_; ++i) {
625  typename LinearConstraintType::IndicatorVariableType indicatorVariable;
626  indicatorVariable.setLogicalOperatorType(LinearConstraintType::IndicatorVariableType::Or);
627  for(IndexType j = 0; j < numVariables_; ++j) {
628  if(useSameNumLabels_) {
629  indicatorVariable.add(j, i);
630  } else if(shape_[j] > i) {
631  indicatorVariable.add(j, i);
632  }
633  }
634  indicatorVariableList_[i] = indicatorVariable;
635  }
636 }
637 
638 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
640  constraints_[0].setBound(maxNumUsedLabels_);
641  constraints_[0].setConstraintOperator(LinearConstraintType::LinearConstraintOperatorType::LessEqual);
642  for(LabelType i = 0; i < maxNumLabels_; ++i) {
643  constraints_[0].add(indicatorVariableList_[i], 1.0);
644  }
645 }
646 
648 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
650  const size_t sameNumLabelsSize = 1;
651  const size_t numVariablesSize = 1;
652  const size_t shapeSize = src.useSameNumLabels_ ? 1 : src.shape_.size();
653  const size_t maxNumUsedLabelsSize = 1;
654 
655  const size_t totalIndexSize = sameNumLabelsSize + numVariablesSize + shapeSize + maxNumUsedLabelsSize;
656  return totalIndexSize;
657 }
658 
659 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
660 inline size_t FunctionSerialization<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >::valueSequenceSize(const NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>& src) {
661  const size_t returnSize = 2; //returnValid and returnInvalid
662 
663  const size_t totalValueSize = returnSize;
664  return totalValueSize;
665 }
666 
667 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
668 template<class INDEX_OUTPUT_ITERATOR, class VALUE_OUTPUT_ITERATOR>
669 inline void FunctionSerialization<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >::serialize(const NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>& src, INDEX_OUTPUT_ITERATOR indexOutIterator, VALUE_OUTPUT_ITERATOR valueOutIterator) {
670  // index output
671  // shape
672  *indexOutIterator = static_cast<typename INDEX_OUTPUT_ITERATOR::value_type>(src.useSameNumLabels_);
673  ++indexOutIterator;
674  *indexOutIterator = src.numVariables_;
675  ++indexOutIterator;
676  if(src.useSameNumLabels_) {
677  *indexOutIterator = src.maxNumLabels_;
678  ++indexOutIterator;
679  } else {
680  for(size_t i = 0; i < src.shape_.size(); ++i) {
681  *indexOutIterator = src.shape_[i];
682  ++indexOutIterator;
683  }
684  }
685 
686  // max num used labels
687  *indexOutIterator = src.maxNumUsedLabels_;
688 
689  // value output
690  // return values
691  *valueOutIterator = src.returnValid_;
692  ++valueOutIterator;
693  *valueOutIterator = src.returnInvalid_;
694 }
695 
696 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
697 template<class INDEX_INPUT_ITERATOR, class VALUE_INPUT_ITERATOR>
698 inline void FunctionSerialization<NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >::deserialize(INDEX_INPUT_ITERATOR indexInIterator, VALUE_INPUT_ITERATOR valueInIterator, NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>& dst) {
699  typedef VALUE_TYPE ValueType;
700  typedef INDEX_TYPE IndexType;
701  typedef LABEL_TYPE LabelType;
702 
703  // index input
704  // shape
705  const bool useSameNumLabels = *indexInIterator;
706  ++indexInIterator;
707  const IndexType numVariables = *indexInIterator;
708  ++indexInIterator;
709 
710  std::vector<LabelType> shape(indexInIterator, indexInIterator + (useSameNumLabels ? 1 : numVariables));
711  indexInIterator += (useSameNumLabels ? 1 : numVariables);
712 
713  // max num used labels
714  const LabelType maxNumUsedLabels = *indexInIterator;
715 
716  // value input
717  // valid value
718  ValueType returnValid = *valueInIterator;
719  ++valueInIterator;
720 
721  // invalid value
722  ValueType returnInvalid = *valueInIterator;
723 
724  if(useSameNumLabels) {
725  dst = NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>(numVariables, shape[0], maxNumUsedLabels, returnValid, returnInvalid);
726  } else {
727  dst = NumLabelsLimitationFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>(shape.begin(), shape.end(), maxNumUsedLabels, returnValid, returnInvalid);
728  }
729 }
731 
732 } // namespace opengm
733 
734 #endif /* OPENGM_NUM_LABELS_LIMITATION_FUNCTION_HXX_ */
LinearConstraintFunctionTraits< LinearConstraintFunctionType > LinearConstraintFunctionTraitsType
Typedef of the LinearConstraintFunctionTraits class with appropriate template parameter.
void challengeRelaxed_impl(ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
Implementation of LinearConstraintFunctionBase::challengeRelaxed.
size_t size_
Stores the size of the function.
size_t shape(const size_t i) const
Number of labels of the indicated input variable.
The OpenGM namespace.
Definition: config.hxx:43
NumLabelsLimitationFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE > LinearConstraintFunctionType
Typedef of the NumLabelsLimitationFunction class with appropriate template parameter.
IndicatorVariablesContainerType::const_iterator IndicatorVariablesIteratorType
Defines the const iterator type to iterate over the set of indicator variables.
Provides implementation for the power function of unsigned integer values.
Provides interface for liner constraint functions.
IndicatorVariableType::IteratorType VariableLabelPairsIteratorType
Defines the const iterator type to iterate over the variable label pairs of an indicator variable...
LinearConstraintFunctionTraitsType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
Defines the indicator variables container iterator type which is used to iterate over the indicator v...
void fillIndicatorVariableList()
Helper function to fill NumLabelsLimitationFunction::indicatorVariableList_ with all indicator variab...
STL namespace.
std::vector< IndicatorVariableType > IndicatorVariablesContainerType
Defines the storage type for the set of indicator variables.
SubsequenceIterator< LinearConstraintsIteratorType, typename std::vector< size_t >::const_iterator > ViolatedLinearConstraintsIteratorType
size_t size() const
Number of parameters.
LinearConstraintFunctionTraitsType::ValueType ValueType
Typedef of the VALUE_TYPE template parameter type from the class LabelOrderFunction.
NumLabelsLimitationFunction()
NumLabelsLimitationFunction constructor.
size_t unsignedIntegerPow(size_t base, size_t exponent)
Unsigned integer power function.
Defines the const iterator type to iterate over the subset of a sequence.
#define OPENGM_ASSERT(expression)
Definition: opengm.hxx:77
void createConstraints()
Helper function to create all linear constraints which are implied by the function.
LabelType maxNumLabels_
The maximum number of labels of the variables.
LinearConstraintsIteratorType linearConstraintsEnd_impl() const
Implementation of LinearConstraintFunctionBase::linearConstraintsEnd.
LinearConstraintFunctionTraitsType::LinearConstraintType LinearConstraintType
Typedef of the LinearConstraint class which is used to represent linear constraints.
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsIteratorType ViolatedLinearConstraintsIteratorType
Defines the violated linear constraints iterator type which is used to iterate over the set of violat...
~NumLabelsLimitationFunction()
NumLabelsLimitationFunction destructor.
A linear constraint function class for limiting the number of used labels.
IndicatorVariablesContainerType indicatorVariableList_
A list of all indicator variables present in the function.
Base class for linear constraint functions.
LinearConstraintFunctionTraitsType::LabelType LabelType
Typedef of the LABEL_TYPE template parameter type from the class LabelOrderFunction.
LinearConstraintFunctionTraitsType::LinearConstraintsIteratorType LinearConstraintsIteratorType
Defines the linear constraints container iterator type which is used to iterate over the set of linea...
LabelType maxNumUsedLabels_
The maximum number of different labels which are allowed in the assignment of the function...
IndicatorVariablesIteratorType indicatorVariablesOrderBegin_impl() const
Implementation of LinearConstraintFunctionBase::indicatorVariablesOrderBegin.
LinearConstraintFunctionTraitsType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType
Defines the variable label pairs iterator type which is used to iterate over the variable label pairs...
size_t dimension() const
Number of input variables.
LinearConstraintsContainerType constraints_
Stores the linear constraints of the function.
LinearConstraintFunctionTraitsType::IndicatorVariablesContainerType IndicatorVariablesContainerType
Defines the indicator variables container type which is used to store the indicator variables used by...
Traits class for linear constraint functions.
const size_t FUNCTION_TYPE_ID_OFFSET
User-defined function have ids smaller than FUNCTION_TYPE_ID_OFFSET.
MinMaxFunctor< ValueType > minMax() const
Get minimum and maximum at the same time.
LinearConstraintFunctionTraitsType::LinearConstraintsContainerType LinearConstraintsContainerType
Defines the linear constraints container type which is used to store multiple linear constraints...
size_t numVariables_
The number of variables of the function.
Provides implementation for class LinearConstraint.
ViolatedLinearConstraintsWeightsContainerType violatedConstraintsWeights_
Stores the weights of the violated constraints which are detected by NumLabelsLimitationFunction::cha...
LinearConstraintFunctionTraitsType::IndexType IndexType
Typedef of the INDEX_TYPE template parameter type from the class LabelOrderFunction.
ValueType max() const
Maximum value of the function.
void challenge_impl(ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
Implementation of LinearConstraintFunctionBase::challenge.
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsIteratorType ViolatedLinearConstraintsWeightsIteratorType
Defines the violated linear constraints weights iterator type which is used to iterate over the weigh...
ValueType operator()(Iterator statesBegin) const
Function evaluation.
IndicatorVariablesIteratorType indicatorVariablesOrderEnd_impl() const
Implementation of LinearConstraintFunctionBase::indicatorVariablesOrderEnd.
Provides implementation for class SubsequenceIterator.
bool useSameNumLabels_
Indicator to tell that all variables have the same number of variables.
LinearConstraintFunctionBase< LinearConstraintFunctionType > LinearConstraintFunctionBaseType
Typedef of the LinearConstraintFunctionBase class with appropriate template parameter.
Define a linear constraint for a set of indicatorVariables.
std::vector< size_t > violatedConstraintsIds_
Stores the indices of the violated constraints which are detected by NumLabelsLimitationFunction::cha...
ValueType min() const
Minimum value of the function.
ValueType returnInvalid_
Stores the return value of NumLabelsLimitationFunction::operator() if the number of different labels ...
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsContainerType ViolatedLinearConstraintsWeightsContainerType
Defines the violated linear constraints weights container type which is used to store the weights of ...
std::vector< LabelType > shape_
The shape of the function (only used if variables have different number of labels).
ValueType returnValid_
Stores the return value of NumLabelsLimitationFunction::operator() if the number of different labels ...
LinearConstraintsIteratorType linearConstraintsBegin_impl() const
Implementation of LinearConstraintFunctionBase::linearConstraintsBegin.