OpenGM  2.3.x
Discrete Graphical Model Library
lp_functiontransfer.hxx
Go to the documentation of this file.
1 #ifndef OPENGM_LP_FUNCTIONTRANSFER_HXX_
2 #define OPENGM_LP_FUNCTIONTRANSFER_HXX_
3 
4 #include <opengm/opengm.hxx>
6 
9 namespace opengm {
10 
11 /*********************
12  * class definition *
13  *********************/
14 template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
16 public:
17  // typedefs
18  typedef VALUE_TYPE ValueType;
19  typedef INDEX_TYPE IndexType;
20  typedef LABEL_TYPE LabelType;
22  typedef std::vector<LinearConstraintType> LinearConstraintsContainerType;
24  typedef std::vector<IndicatorVariableType> IndicatorVariablesContainerType;
25  typedef std::vector<ValueType> SlackVariablesObjectiveCoefficientsContainerType;
26 
27  // transfer interface
28  template<class FUNCTION_TYPE>
29  static bool isTransferable();
30  template<class FUNCTION_TYPE>
31  static IndexType numSlackVariables(const FUNCTION_TYPE& function);
32  template<class FUNCTION_TYPE>
33  static void getSlackVariablesOrder(const FUNCTION_TYPE& function, IndicatorVariablesContainerType& order);
34  template<class FUNCTION_TYPE>
35  static void getSlackVariablesObjectiveCoefficients(const FUNCTION_TYPE& function, SlackVariablesObjectiveCoefficientsContainerType& coefficients);
36  template<class FUNCTION_TYPE>
37  static void getIndicatorVariables(const FUNCTION_TYPE& function, IndicatorVariablesContainerType& variables);
38  template<class FUNCTION_TYPE>
39  static void getLinearConstraints(const FUNCTION_TYPE& function, LinearConstraintsContainerType& constraints);
40 
41  // functors
44  template<class FUNCTION_TYPE>
45  void operator()(const FUNCTION_TYPE& function);
46  };
48  IndexType numSlackVariables_;
49  template<class FUNCTION_TYPE>
50  void operator()(const FUNCTION_TYPE& function);
51  };
53  IndicatorVariablesContainerType* order_;
54  template<class FUNCTION_TYPE>
55  void operator()(const FUNCTION_TYPE& function);
56  };
58  SlackVariablesObjectiveCoefficientsContainerType* coefficients_;
59  template<class FUNCTION_TYPE>
60  void operator()(const FUNCTION_TYPE& function);
61  };
63  IndicatorVariablesContainerType* variables_;
64  template<class FUNCTION_TYPE>
65  void operator()(const FUNCTION_TYPE& function);
66  };
68  LinearConstraintsContainerType* constraints_;
69  template<class FUNCTION_TYPE>
70  void operator()(const FUNCTION_TYPE& function);
71  };
72 };
73 
74 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
76 public:
77  // typedefs
78  typedef VALUE_TYPE ValueType;
79  typedef INDEX_TYPE IndexType;
80  typedef LABEL_TYPE LabelType;
81  typedef FUNCTION_TYPE FunctionType;
88 
89  // transfer interface
90  static bool isTransferable();
91  static IndexType numSlackVariables(const FunctionType& function);
92  static void getSlackVariablesOrder(const FunctionType& function, IndicatorVariablesContainerType& order);
93  static void getSlackVariablesObjectiveCoefficients(const FunctionType& function, SlackVariablesObjectiveCoefficientsContainerType& coefficients);
94  static void getIndicatorVariables(const FunctionType& function, IndicatorVariablesContainerType& variables);
95  static void getLinearConstraints(const FunctionType& function, LinearConstraintsContainerType& constraints);
96 };
97 
98 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
99 class LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> {
100 public:
101  // typedefs
102  typedef VALUE_TYPE ValueType;
103  typedef INDEX_TYPE IndexType;
104  typedef LABEL_TYPE LabelType;
112 
113  // transfer interface
114  static bool isTransferable();
115  static IndexType numSlackVariables(const FunctionType& function);
116  static void getSlackVariablesOrder(const FunctionType& function, IndicatorVariablesContainerType& order);
117  static void getSlackVariablesObjectiveCoefficients(const FunctionType& function, SlackVariablesObjectiveCoefficientsContainerType& coefficients);
118  static void getIndicatorVariables(const FunctionType& function, IndicatorVariablesContainerType& variables);
119  static void getLinearConstraints(const FunctionType& function, LinearConstraintsContainerType& constraints);
120 };
121 
122 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
123 class LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> {
124 public:
125  // typedefs
126  typedef VALUE_TYPE ValueType;
127  typedef INDEX_TYPE IndexType;
128  typedef LABEL_TYPE LabelType;
136 
137  // transfer interface
138  static bool isTransferable();
139  static IndexType numSlackVariables(const FunctionType& function);
140  static void getSlackVariablesOrder(const FunctionType& function, IndicatorVariablesContainerType& order);
141  static void getSlackVariablesObjectiveCoefficients(const FunctionType& function, SlackVariablesObjectiveCoefficientsContainerType& coefficients);
142  static void getIndicatorVariables(const FunctionType& function, IndicatorVariablesContainerType& variables);
143  static void getLinearConstraints(const FunctionType& function, LinearConstraintsContainerType& constraints);
144 };
145 
146 /***********************
147  * class documentation *
148  ***********************/
585 /******************
586  * implementation *
587  ******************/
588 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
589 template<class FUNCTION_TYPE>
592 }
593 
594 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
595 template<class FUNCTION_TYPE>
598 }
599 
600 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
601 template<class FUNCTION_TYPE>
604 }
605 
606 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
607 template<class FUNCTION_TYPE>
610 }
611 
612 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
613 template<class FUNCTION_TYPE>
616 }
617 
618 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
619 template<class FUNCTION_TYPE>
622 }
623 
624 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
625 template<class FUNCTION_TYPE>
627  isTransferable_ = isTransferable<FUNCTION_TYPE>();
628 }
629 
630 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
631 template<class FUNCTION_TYPE>
633  numSlackVariables_ = numSlackVariables(function);
634 }
635 
636 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
637 template<class FUNCTION_TYPE>
639  getSlackVariablesOrder(function, *order_);
640 }
641 
642 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
643 template<class FUNCTION_TYPE>
645  getSlackVariablesObjectiveCoefficients(function, *coefficients_);
646 }
647 
648 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
649 template<class FUNCTION_TYPE>
651  getIndicatorVariables(function, *variables_);
652 }
653 
654 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
655 template<class FUNCTION_TYPE>
657  getLinearConstraints(function, *constraints_);
658 }
659 
660 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
662  // default implementation
663  return false;
664 }
665 
666 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
668  // default implementation
669  throw opengm::RuntimeError("Unsupported Function Type.");
670  return 0;
671 }
672 
673 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
675  // default implementation
676  throw opengm::RuntimeError("Unsupported Function Type.");
677 }
678 
679 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
681  // default implementation
682  throw opengm::RuntimeError("Unsupported Function Type.");
683 }
684 
685 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
687  // default implementation
688  throw opengm::RuntimeError("Unsupported Function Type.");
689 }
690 
691 template<class FUNCTION_TYPE, class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
693  // default implementation
694  throw opengm::RuntimeError("Unsupported Function Type.");
695 }
696 
697 
698 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
700  // implementation for SumConstraintFunction
701  return true;
702 }
703 
704 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
705 inline typename LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::IndexType LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::numSlackVariables(const FunctionType& function) {
706  // implementation for SumConstraintFunction
707  return 1;
708 }
709 
710 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
711 inline void LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getSlackVariablesOrder(const FunctionType& function, IndicatorVariablesContainerType& order) {
712  // implementation for SumConstraintFunction
713  order.resize(1);
714  order[0] = IndicatorVariableType(function.numVariables_, 0);
715 }
716 
717 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
718 inline void LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getSlackVariablesObjectiveCoefficients(const FunctionType& function, SlackVariablesObjectiveCoefficientsContainerType& coefficients) {
719  // implementation for SumConstraintFunction
720  coefficients.resize(1);
721  coefficients[0] = function.lambda_;
722 }
723 
724 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
725 inline void LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getIndicatorVariables(const FunctionType& function, IndicatorVariablesContainerType& variables) {
726  // implementation for SumConstraintFunction
727  variables.clear();
728  for(IndexType i = 0; i < function.numVariables_; ++i) {
729  for(LabelType j = 0; j < (function.useSameNumLabels_ ? function.maxNumLabels_ : function.shape_[i]); ++j) {
730  const IndicatorVariableType indicatorVariable(i, j);
731  variables.push_back(indicatorVariable);
732  }
733  }
734  const IndicatorVariableType slackVariable(function.numVariables_, 0);
735  variables.push_back(slackVariable);
736 }
737 
738 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
739 inline void LPFunctionTransfer_impl<SumConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getLinearConstraints(const FunctionType& function, LinearConstraintsContainerType& constraints) {
740  // implementation for SumConstraintFunction
741  constraints.resize(2);
742  LinearConstraintType constraint;
744  constraint.setBound(function.bound_);
745  for(IndexType i = 0; i < function.numVariables_; ++i) {
746  for(LabelType j = 0; j < (function.useSameNumLabels_ ? function.maxNumLabels_ : function.shape_[i]); ++j) {
747  const IndicatorVariableType indicatorVariable(i, j);
748  constraint.add(indicatorVariable, function.coefficients_[(function.shareCoefficients_ ? j : function.coefficientsOffsets_[i] + j)]);
749  }
750  }
751  const IndicatorVariableType slackVariable(function.numVariables_, 0);
752  constraint.add(slackVariable, -1.0);
753  constraints[0] = constraint;
754 
755  LinearConstraintType constraint2;
757  constraint2.setBound(-function.bound_);
758  for(IndexType i = 0; i < function.numVariables_; ++i) {
759  for(LabelType j = 0; j < (function.useSameNumLabels_ ? function.maxNumLabels_ : function.shape_[i]); ++j) {
760  const IndicatorVariableType indicatorVariable(i, j);
761  constraint2.add(indicatorVariable, -function.coefficients_[(function.shareCoefficients_ ? j : function.coefficientsOffsets_[i] + j)]);
762  }
763  }
764  constraint2.add(slackVariable, -1.0);
765  constraints[1] = constraint2;
766 }
767 
768 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
770  // implementation for LabelCostFunction
771  return true;
772 }
773 
774 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
775 inline typename LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::IndexType LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::numSlackVariables(const FunctionType& function) {
776  // implementation for LabelCostFunction
777  // one slack variable for each label cost which is not zero
778  if(function.useSingleCost_) {
779  return 1;
780  } else {
781  IndexType numLabelCosts = 0;
782  for(LabelType i = 0; i < function.maxNumLabels_; ++i) {
783  // sort out unused labels
784  if(function.costs_[i] != 0.0) {
785  ++numLabelCosts;
786  }
787  }
788  return numLabelCosts;
789  }
790 }
791 
792 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
793 inline void LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getSlackVariablesOrder(const FunctionType& function, IndicatorVariablesContainerType& order) {
794  // implementation for LabelCostFunction
795  const IndexType numLabelCosts = numSlackVariables(function);
796  order.resize(numLabelCosts);
797  for(IndexType i = 0; i < numLabelCosts; ++i) {
798  order[i] = IndicatorVariableType(function.numVariables_ + i, 0);
799  }
800 }
801 
802 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
803 inline void LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getSlackVariablesObjectiveCoefficients(const FunctionType& function, SlackVariablesObjectiveCoefficientsContainerType& coefficients) {
804  // implementation for LabelCostFunction
805  const IndexType numLabelCosts = numSlackVariables(function);
806  coefficients.resize(numLabelCosts);
807  if(function.useSingleCost_) {
808  OPENGM_ASSERT(numLabelCosts == 1);
809  coefficients[0] = function.singleCost_;
810  } else {
811  LabelType currentCostIndex = 0;
812  for(LabelType i = 0; i < function.maxNumLabels_; ++i) {
813  // sort out unused label costs
814  if(function.costs_[i] != 0.0) {
815  coefficients[currentCostIndex] = function.costs_[i];
816  ++currentCostIndex;
817  }
818  }
819  }
820 }
821 
822 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
823 inline void LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getIndicatorVariables(const FunctionType& function, IndicatorVariablesContainerType& variables) {
824  // implementation for LabelCostFunction
825  const IndexType numLabelCosts = numSlackVariables(function);
826  variables.resize(numLabelCosts * 2);
827  if(function.useSingleCost_) {
828  OPENGM_ASSERT(variables.size() == 2);
829  IndicatorVariableType indicatorVar;
831  if(function.useSameNumLabels_) {
832  for(IndexType i = 0; i < function.numVariables_; ++i) {
833  indicatorVar.add(i, function.singleLabel_);
834  }
835  } else {
836  for(IndexType i = 0; i < function.numVariables_; ++i) {
837  if(function.shape_[i] > function.singleLabel_) {
838  indicatorVar.add(i, function.singleLabel_);
839  }
840  }
841  }
842  variables[0] = indicatorVar;
843 
844  variables[1] = IndicatorVariableType(function.numVariables_, 0);
845  } else {
846  LabelType currentNonZeroLabel = 0;
847  for(LabelType currentLabel = 0; currentLabel < function.maxNumLabels_; ++currentLabel) {
848  if(function.costs_[currentLabel] != 0) {
849  IndicatorVariableType indicatorVar;
851  if(function.useSameNumLabels_) {
852  for(IndexType i = 0; i < function.numVariables_; ++i) {
853  indicatorVar.add(i, currentLabel);
854  }
855  } else {
856  for(IndexType i = 0; i < function.numVariables_; ++i) {
857  if(function.shape_[i] > currentLabel) {
858  indicatorVar.add(i, currentLabel);
859  }
860  }
861  }
862  variables[currentNonZeroLabel * 2] = indicatorVar;
863 
864  variables[(currentNonZeroLabel * 2) + 1] = IndicatorVariableType(function.numVariables_ + currentNonZeroLabel, 0);
865  ++currentNonZeroLabel;
866  }
867  }
868  }
869 }
870 
871 template<class VALUE_TYPE, class INDEX_TYPE, class LABEL_TYPE>
872 inline void LPFunctionTransfer_impl<LabelCostFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::getLinearConstraints(const FunctionType& function, LinearConstraintsContainerType& constraints) {
873  // implementation for LabelCostFunction
875  getIndicatorVariables(function, variables);
876  OPENGM_ASSERT(variables.size() % 2 == 0);
877 
878  constraints.resize(variables.size() / 2);
879  for(size_t i = 0; i < constraints.size(); ++i) {
880  LinearConstraintType constraint;
882  constraint.setBound(0.0);
883  constraint.add(variables[i * 2], 1.0); // Or indicator variable
884  constraint.add(variables[(i * 2) + 1], -1.0); // slack variable
885  constraints[i] = constraint;
886  }
887 }
888 
889 } // namespace opengm
890 
891 #endif /* OPENGM_LP_FUNCTIONTRANSFER_HXX_ */
void operator()(const FUNCTION_TYPE &function)
The operator which implements the access to the function of a graphical model factor.
Functor to call LPFunctionTransfer::getLinearConstraints() for a factor of the graphical model...
LABEL_TYPE LabelType
Typedef of the LABEL_TYPE template parameter type from the class LPFunctionTransfer_impl.
static void getSlackVariablesObjectiveCoefficients(const FunctionType &function, SlackVariablesObjectiveCoefficientsContainerType &coefficients)
This function will tell the coefficients of the slack variables for the objective function of the lin...
LABEL_TYPE LabelType
Typedef of the LABEL_TYPE template parameter type from the class LPFunctionTransfer.
The OpenGM namespace.
Definition: config.hxx:43
IndicatorVariablesContainerType * order_
Pointer to the storage for the return value of the LPFunctionTransfer::getSlackVariablesOrder() metho...
static IndexType numSlackVariables(const FUNCTION_TYPE &function)
This function will tell the number of required slack variables for the function transfer.
static void getLinearConstraints(const FunctionType &function, LinearConstraintsContainerType &constraints)
This function will create the necessary linear constraints to add the function to the linear program...
Provides implementation of a label cost function.
static void getSlackVariablesOrder(const FunctionType &function, IndicatorVariablesContainerType &order)
This function will tell the order of the slack variables for the LP function transfer.
static void getSlackVariablesOrder(const FUNCTION_TYPE &function, IndicatorVariablesContainerType &order)
This function will tell the order of the slack variables which are required for the function transfer...
static void getSlackVariablesObjectiveCoefficients(const FUNCTION_TYPE &function, SlackVariablesObjectiveCoefficientsContainerType &coefficients)
This function will tell the coefficients of the slack variables for the objective function of the lin...
Defines the linear constraint operator type to be . Hence the left hand side of the constraint will b...
LPFunctionTransferType::IndicatorVariablesContainerType IndicatorVariablesContainerType
Defines the indicator variables container type which is used to store multiple indicator variables...
static void getIndicatorVariables(const FUNCTION_TYPE &function, IndicatorVariablesContainerType &variables)
This function will tell all the indicator variables which are used in the linear constraints which ar...
LPFunctionTransferType::LinearConstraintType LinearConstraintType
Typedef of the LinearConstraint class with appropriate template parameter.
LPFunctionTransfer< ValueType, IndexType, LabelType > LPFunctionTransferType
Typedef of the LPFunctionTransfer class with appropriate template parameter.
void operator()(const FUNCTION_TYPE &function)
The operator which implements the access to the function of a graphical model factor.
LinearConstraintType::IndicatorVariableType IndicatorVariableType
Defines the indicator variable type which is used within linear constraints.
static void getLinearConstraints(const FUNCTION_TYPE &function, LinearConstraintsContainerType &constraints)
This function will create the necessary linear constraints which are used to represent the function w...
Provides implementation of a sum constraint function.
LPFunctionTransferType::IndicatorVariableType IndicatorVariableType
Defines the indicator variable type which is used within linear constraints.
Functor to call LPFunctionTransfer::numSlackVariables() for a graphical model factor.
#define OPENGM_ASSERT(expression)
Definition: opengm.hxx:77
A label cost function class penalizing the usage of labels.
std::vector< ValueType > SlackVariablesObjectiveCoefficientsContainerType
Defines the container type which is used to store the coefficients of the slack variables for the obj...
void operator()(const FUNCTION_TYPE &function)
The operator which implements the access to the function of a graphical model factor.
LinearConstraint< ValueType, IndexType, LabelType > LinearConstraintType
Typedef of the LinearConstraint class with appropriate template parameter.
LinearConstraintsContainerType * constraints_
Pointer to the storage for the return value of the LPFunctionTransfer::getLinearConstraints() method...
IndexType numSlackVariables_
Storage for the return value of the LPFunctionTransfer::numSlackVariables() method.
FUNCTION_TYPE FunctionType
Typedef of the FUNCTION_TYPE template parameter type from the class LPFunctionTransfer_impl.
void setLogicalOperatorType(const LogicalOperatorType logicalOperatorType)
Set the logical operator type of the indicator variable.
Default implementation for class opengm::LPFunctionTransfer.
SlackVariablesObjectiveCoefficientsContainerType * coefficients_
Pointer to the storage for the return value of the LPFunctionTransfer::getSlackVariablesObjectiveCoef...
Provides transformations for some function types when they are used in inference algorithms which use...
static IndexType numSlackVariables(const FunctionType &function)
This function will tell the number of required slack variables for the LP function transfer...
Functor to call LPFunctionTransfer::getSlackVariablesOrder() for a factor of the graphical model...
INDEX_TYPE IndexType
Typedef of the INDEX_TYPE template parameter type from the class LPFunctionTransfer.
void add(const IndicatorVariableType &indicatorVariable, const ValueType coefficient)
Add a single indicator variable and the corresponding coefficient to the linear constraint.
std::vector< IndicatorVariableType > IndicatorVariablesContainerType
Defines the indicator variables container type which is used to store multiple indicator variables...
IndicatorVariablesContainerType * variables_
Pointer to the storage for the return value of the LPFunctionTransfer::getIndicatorVariables() method...
VALUE_TYPE ValueType
Typedef of the VALUE_TYPE template parameter type from the class LPFunctionTransfer.
void operator()(const FUNCTION_TYPE &function)
The operator which implements the access to the function of a graphical model factor.
LPFunctionTransferType::LinearConstraintsContainerType LinearConstraintsContainerType
Defines the linear constraints container type which is used to store multiple linear constraints...
void add(const IndexType variable, const LabelType label)
Add a variable label pair to the indicator variable.
void operator()(const FUNCTION_TYPE &function)
The operator which implements the access to the function of a factor of the graphical model...
Combine a group of variables to a new variable.
Provides implementation for class LinearConstraint.
bool isTransferable_
Storage for the return value of the LPFunctionTransfer::isTransferable() method.
Functor to call LPFunctionTransfer::getSlackVariablesObjectiveCoefficients() for a factor of the grap...
Functor to call LPFunctionTransfer::isTransferable() for a factor of the graphical model...
std::vector< LinearConstraintType > LinearConstraintsContainerType
Defines the linear constraints container type which is used to store multiple linear constraints...
The indicator variable will be interpreted as 1 if at least one of the variables associated by the in...
A sum constraint function class penalizing the violation of a given linear equality constraint...
VALUE_TYPE ValueType
Typedef of the VALUE_TYPE template parameter type from the class LPFunctionTransfer_impl.
INDEX_TYPE IndexType
Typedef of the INDEX_TYPE template parameter type from the class LPFunctionTransfer_impl.
Functor to call LPFunctionTransfer::getIndicatorVariables() for a factor of the graphical model...
LPFunctionTransferType::SlackVariablesObjectiveCoefficientsContainerType SlackVariablesObjectiveCoefficientsContainerType
Defines the container type which is used to store the coefficients of the slack variables for the obj...
void setConstraintOperator(const LinearConstraintOperatorValueType constraintOperator)
Set the constraint operator for the linear constraint.
Defines the linear constraint operator type to be . Hence the left hand side of the constraint will b...
Define a linear constraint for a set of indicatorVariables.
static bool isTransferable()
This function will tell if the function type provided via the template parameter can be transfered in...
void setBound(const BoundType bound)
Set the bound of the linear constraint.
OpenGM runtime error.
Definition: opengm.hxx:100
void operator()(const FUNCTION_TYPE &function)
The operator which implements the access to the function of a graphical model factor.
static void getIndicatorVariables(const FunctionType &function, IndicatorVariablesContainerType &variables)
This function will tell the used indicator variables for the linear constraints.
static bool isTransferable()
This function will tell if the function type provided via the template parameter can be transfered in...