1 #ifndef OPENGM_LABEL_ORDER_FUNCTION_HXX_ 2 #define OPENGM_LABEL_ORDER_FUNCTION_HXX_ 20 template<
class VALUE_TYPE,
class INDEX_TYPE =
size_t,
class LABEL_TYPE =
size_t>
32 typedef typename LinearConstraintFunctionTraitsType::IndexType
IndexType;
33 typedef typename LinearConstraintFunctionTraitsType::LabelType
LabelType;
47 LabelOrderFunction(
const LabelType numLabelsVar1,
const LabelType numLabelsVar2,
const LabelOrderType& labelOrder,
const ValueType returnValid = 0.0,
const ValueType returnInvalid = 1.0);
48 template <
class ITERATOR_TYPE>
49 LabelOrderFunction(
const LabelType numLabelsVar1,
const LabelType numLabelsVar2, ITERATOR_TYPE labelOrderBegin,
const ValueType returnValid = 0.0,
const ValueType returnInvalid = 1.0);
53 template<
class Iterator>
54 ValueType
operator()(Iterator statesBegin)
const;
55 size_t shape(
const size_t i)
const;
60 ValueType
min()
const;
61 ValueType
max()
const;
62 MinMaxFunctor<ValueType>
minMax()
const;
83 template <
class LABEL_ITERATOR>
84 void challenge_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin,
const ValueType tolerance = 0.0)
const;
85 template <
class LABEL_ITERATOR>
86 void challengeRelaxed_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin,
const ValueType tolerance = 0.0)
const;
100 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
119 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
128 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
135 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR>
137 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR>
477 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
483 throw opengm::RuntimeError(
"Unsupported configuration for label order function. At least one of LabelOrderFunction::useSingleConstraint_ and LabelOrderFunction::useMultipleConstraints_ has to be set to true.");
487 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
499 throw opengm::RuntimeError(
"Unsupported configuration for label order function. At least one of LabelOrderFunction::useSingleConstraint_ and LabelOrderFunction::useMultipleConstraints_ has to be set to true.");
509 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
510 template <
class ITERATOR_TYPE>
523 throw opengm::RuntimeError(
"Unsupported configuration for label order function. At least one of LabelOrderFunction::useSingleConstraint_ and LabelOrderFunction::useMultipleConstraints_ has to be set to true.");
533 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
538 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
539 template<
class Iterator>
548 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
554 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
559 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
564 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
569 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
574 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
584 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
589 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
594 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
599 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
604 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
605 template <
class LABEL_ITERATOR>
608 if(weight <= tolerance) {
631 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
632 template <
class LABEL_ITERATOR>
634 size_t numViolatedConstraints = 0;
636 double weightVar2 = 0.0;
641 double totalWeight = weightVar2;
643 double currentWeight = (
labelOrder_[i] * labelingBegin[i]);
646 totalWeight += currentWeight;
649 currentWeight += weightVar2;
650 if(currentWeight > tolerance) {
653 ++numViolatedConstraints;
659 if(totalWeight > tolerance) {
662 ++numViolatedConstraints;
671 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
680 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
690 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
694 constraints_[0].setConstraintOperator(LinearConstraintType::LinearConstraintOperatorType::LessEqual);
706 constraints_[i + (
useSingleConstraint_ ? 1 : 0)].setConstraintOperator(LinearConstraintType::LinearConstraintOperatorType::LessEqual);
715 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
717 const size_t shapeSize = 2;
718 const size_t labelOrderSize = 1;
719 const size_t totalIndexSize = shapeSize + labelOrderSize;
720 return totalIndexSize;
723 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
725 const size_t labelOrderSize = src.
labelOrder_.size();
726 const size_t returnSize = 2;
727 const size_t totalValueSize = labelOrderSize + returnSize;
728 return totalValueSize;
731 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
732 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR>
746 for(
size_t i = 0; i < src.
labelOrder_.size(); ++i) {
757 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
758 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR>
762 const size_t numLabelsVar1 = *indexInIterator;
764 const size_t numLabelsVar2 = *indexInIterator;
768 const size_t labelOrderSize = *indexInIterator;
772 valueInIterator += labelOrderSize;
775 VALUE_TYPE returnValid = *valueInIterator;
779 VALUE_TYPE returnInvalid = *valueInIterator;
LinearConstraintFunctionTraitsType::IndicatorVariablesContainerType IndicatorVariablesContainerType
Defines the indicator variables container type which is used to store the indicator variables used by...
std::vector< ValueType > LabelOrderType
Type to store the weights of the label order.
void createConstraints()
Helper function to create all linear constraints which are implied by the label order function...
IndicatorVariablesIteratorType indicatorVariablesOrderEnd_impl() const
Implementation of LinearConstraintFunctionBase::indicatorVariablesOrderEnd.
LinearConstraintFunctionBase< LinearConstraintFunctionType > LinearConstraintFunctionBaseType
Typedef of the LinearConstraintFunctionBase class with appropriate template parameter.
IndicatorVariablesContainerType::const_iterator IndicatorVariablesIteratorType
Defines the const iterator type to iterate over the set of indicator variables.
std::vector< LinearConstraintType > LinearConstraintsContainerType
ValueType operator()(Iterator statesBegin) const
Function evaluation.
std::vector< double > ViolatedLinearConstraintsWeightsContainerType
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::ViolatedLinearConstraintsWeightsContainerType ViolatedLinearConstraintsWeightsContainerType
Defines the violated linear constraints weights container type which is used to store the weights of ...
ValueType max() const
Maximum value of the label order function.
size_t shape(const size_t i) const
Number of labels of the indicated input variable.
size_t dimension() const
Number of input variables.
ViolatedLinearConstraintsWeightsContainerType violatedConstraintsWeights_
Stores the weights of the violated constraints which are detected by LabelOrderFunction::challenge an...
IndicatorVariablesContainerType indicatorVariableList_
A list of all indicator variables present in the label order function.
void fillIndicatorVariableList()
Helper function to fill LabelOrderFunction::indicatorVariableList_ with all indicator variables used ...
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsIteratorType ViolatedLinearConstraintsWeightsIteratorType
Defines the violated linear constraints weights iterator type which is used to iterate over the weigh...
LabelType numLabelsVar2_
The number of labels of the second variable.
LinearConstraintsContainerType constraints_
Stores the linear constraints of the label order function.
std::vector< IndicatorVariableType > IndicatorVariablesContainerType
Defines the storage type for the set of indicator variables.
LabelType numLabelsVar1_
The number of labels of the first variable.
static const size_t dimension_
The dimension of the label order function.
Defines the const iterator type to iterate over the subset of a sequence.
#define OPENGM_ASSERT(expression)
IndicatorVariablesIteratorType indicatorVariablesOrderBegin_impl() const
Implementation of LinearConstraintFunctionBase::indicatorVariablesOrderBegin.
ViolatedLinearConstraintsWeightsContainerType::const_iterator ViolatedLinearConstraintsWeightsIteratorType
LinearConstraintsContainerType::const_iterator LinearConstraintsIteratorType
ValueType returnValid_
Stores the return value of LabelOrderFunction::operator() if no constraint is violated.
LinearConstraintFunctionTraitsType::LabelType LabelType
Typedef of the LABEL_TYPE template parameter type from the class LabelOrderFunction.
LinearConstraintFunctionTraitsType::IndexType IndexType
Typedef of the INDEX_TYPE template parameter type from the class LabelOrderFunction.
LinearConstraintFunctionTraitsType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
Defines the indicator variables container iterator type which is used to iterate over the indicator v...
LinearConstraintFunctionTraitsType::ValueType ValueType
Typedef of the VALUE_TYPE template parameter type from the class LabelOrderFunction.
Base class for linear constraint functions.
LinearConstraint< ValueType, IndexType, LabelType > LinearConstraintType
~LabelOrderFunction()
LabelOrderFunction destructor.
size_t size_
Stores the size of the label order function.
LabelOrderFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE > LinearConstraintFunctionType
Typedef of the LabelOrderFunction class with appropriate template parameter.
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsIteratorType ViolatedLinearConstraintsIteratorType
Defines the violated linear constraints iterator type which is used to iterate over the set of violat...
void challenge_impl(ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
Implementation of LinearConstraintFunctionBase::challenge.
SubsequenceIterator< LinearConstraintsIteratorType, typename std::vector< size_t >::const_iterator > ViolatedLinearConstraintsIteratorType
LinearConstraintFunctionTraits< LinearConstraintFunctionType > LinearConstraintFunctionTraitsType
Typedef of the LinearConstraintFunctionTraits class with appropriate template parameter.
LinearConstraintFunctionTraitsType::LinearConstraintType LinearConstraintType
Typedef of the LinearConstraint class which is used to represent linear constraints.
LinearConstraintType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType
Traits class for linear constraint functions.
std::vector< size_t > violatedConstraintsIds_
Stores the indices of the violated constraints which are detected by LabelOrderFunction::challenge an...
static const bool useMultipleConstraints_
Describe the label order constraint in multiple linear constraints.
const size_t FUNCTION_TYPE_ID_OFFSET
User-defined function have ids smaller than FUNCTION_TYPE_ID_OFFSET.
LinearConstraintType::IndicatorVariablesContainerType IndicatorVariablesContainerType
LabelOrderType labelOrder_
The weights defining the label order.
ValueType min() const
Minimum value of the label order function.
LinearConstraintFunctionTraitsType::LinearConstraintsContainerType LinearConstraintsContainerType
Defines the linear constraints container type which is used to store multiple linear constraints...
Provides implementation for class LinearConstraint.
ValueType returnInvalid_
Stores the return value of LabelOrderFunction::operator() if at least one constraint is violated...
bool checkLabelOrder() const
Check label order weights. Only used for assertion in debug mode.
void challengeRelaxed_impl(ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
Implementation of LinearConstraintFunctionBase::challengeRelaxed.
LinearConstraintFunctionTraitsType::LinearConstraintsIteratorType LinearConstraintsIteratorType
Defines the linear constraints container iterator type which is used to iterate over the set of linea...
LinearConstraintsIteratorType linearConstraintsEnd_impl() const
Implementation of LinearConstraintFunctionBase::linearConstraintsEnd.
A linear constraint function class ensuring the correct label order for two variables.
LinearConstraintsIteratorType linearConstraintsBegin_impl() const
Implementation of LinearConstraintFunctionBase::linearConstraintsBegin.
Provides implementation for class SubsequenceIterator.
static const bool useSingleConstraint_
Describe the label order constraint in one single linear constraint.
LabelOrderFunction()
LabelOrderFunction constructor.
Define a linear constraint for a set of indicatorVariables.
LinearConstraintFunctionTraitsType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType
Defines the variable label pairs iterator type which is used to iterate over the variable label pairs...
size_t size() const
Number of parameters.
LinearConstraintType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
MinMaxFunctor< ValueType > minMax() const
Get minimum and maximum at the same time.