1 #ifndef OPENGM_LINEAR_CONSTRAINT_FUNCTION_HXX_
2 #define OPENGM_LINEAR_CONSTRAINT_FUNCTION_HXX_
21 template<
class VALUE_TYPE,
class INDEX_TYPE =
size_t,
class LABEL_TYPE =
size_t>
28 typedef typename LinearConstraintFunctionTraitsType::ValueType
ValueType;
29 typedef typename LinearConstraintFunctionTraitsType::IndexType
IndexType;
30 typedef typename LinearConstraintFunctionTraitsType::LabelType
LabelType;
43 template <
class SHAPE_ITERATOR_TYPE>
44 LinearConstraintFunction(SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd,
const LinearConstraintsContainerType& constraints,
const ValueType returnValid = 0.0,
const ValueType returnInvalid = 1.0);
45 template <
class SHAPE_ITERATOR_TYPE,
class CONSTRAINTS_ITERATOR_TYPE>
46 LinearConstraintFunction(SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, CONSTRAINTS_ITERATOR_TYPE constraintsBegin, CONSTRAINTS_ITERATOR_TYPE constraintsEnd,
const ValueType returnValid = 0.0,
const ValueType returnInvalid = 1.0);
50 template<
class STATES_ITERATOR_TYPE>
51 ValueType
operator()(STATES_ITERATOR_TYPE statesBegin)
const;
52 size_t shape(
const size_t i)
const;
57 ValueType
min()
const;
58 ValueType
max()
const;
59 MinMaxFunctor<ValueType>
minMax()
const;
78 template <
class LABEL_ITERATOR>
79 void challenge_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin,
const ValueType tolerance = 0.0)
const;
80 template <
class LABEL_ITERATOR>
81 void challengeRelaxed_impl(ViolatedLinearConstraintsIteratorType& violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType& violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType& violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin,
const ValueType tolerance = 0.0)
const;
95 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
114 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
123 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
124 class FunctionSerialization<LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> > {
126 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::ValueType ValueType;
128 static size_t indexSequenceSize(
const LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&);
129 static size_t valueSequenceSize(
const LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&);
130 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR>
131 static void serialize(
const LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&, INDEX_OUTPUT_ITERATOR, VALUE_OUTPUT_ITERATOR);
132 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR>
133 static void deserialize( INDEX_INPUT_ITERATOR, VALUE_INPUT_ITERATOR, LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>&);
430 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
432 size_(), constraints_(), violatedConstraintsIds_(),
433 violatedConstraintsWeights_(), returnValid_(), returnInvalid_(),
434 indicatorVariableList_(), indicatorVariableLookupTable_() {
438 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
439 template <
class SHAPE_ITERATOR_TYPE>
441 : shape_(shapeBegin, shapeEnd),
442 size_(
std::accumulate(shapeBegin, shapeEnd, 1,
std::multiplies<typename
std::iterator_traits<SHAPE_ITERATOR_TYPE>::value_type>())),
443 constraints_(constraints), violatedConstraintsIds_(constraints_.size()),
444 violatedConstraintsWeights_(constraints_.size()),
445 returnValid_(returnValid), returnInvalid_(returnInvalid),
446 indicatorVariableList_(), indicatorVariableLookupTable_() {
456 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
457 template <
class SHAPE_ITERATOR_TYPE,
class CONSTRAINTS_ITERATOR_TYPE>
459 : shape_(shapeBegin, shapeEnd),
460 size_(
std::accumulate(shapeBegin, shapeEnd, 1,
std::multiplies<typename
std::iterator_traits<SHAPE_ITERATOR_TYPE>::value_type>())),
461 constraints_(constraintsBegin, constraintsEnd),
462 violatedConstraintsIds_(constraints_.size()),
463 violatedConstraintsWeights_(constraints_.size()),
464 returnValid_(returnValid), returnInvalid_(returnInvalid),
465 indicatorVariableList_(), indicatorVariableLookupTable_() {
474 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
479 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
480 template<
class STATES_ITERATOR_TYPE>
484 const ValueType weight = constraintsIter->operator()(statesBegin);
486 return returnInvalid_;
492 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
498 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
500 return shape_.size();
503 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
508 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
510 return returnValid_ < returnInvalid_ ? returnValid_ : returnInvalid_;
513 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
515 return returnValid_ > returnInvalid_ ? returnValid_ : returnInvalid_;
518 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
520 if(returnValid_ < returnInvalid_) {
521 return MinMaxFunctor<ValueType>(returnValid_, returnInvalid_);
524 return MinMaxFunctor<ValueType>(returnInvalid_, returnValid_);
528 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
530 return constraints_.begin();
533 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
535 return constraints_.end();
538 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
540 return indicatorVariableList_.begin();
543 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
545 return indicatorVariableList_.end();
548 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
549 template <
class LABEL_ITERATOR>
551 size_t numViolatedConstraints = 0;
554 const double weight =
static_cast<double>(constraintsIter->operator()(labelingBegin));
555 if(weight > tolerance) {
556 violatedConstraintsIds_[numViolatedConstraints] = std::distance(constraints_.begin(), constraintsIter);
557 violatedConstraintsWeights_[numViolatedConstraints] = weight;
558 ++numViolatedConstraints;
563 violatedConstraintsWeightsBegin = violatedConstraintsWeights_.begin();
566 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
567 template <
class LABEL_ITERATOR>
569 size_t numViolatedConstraints = 0;
570 std::vector<std::vector<size_t> >::const_iterator indicatorVariableLookupTableIter = indicatorVariableLookupTable_.begin();
573 typename LinearConstraintType::CoefficientsIteratorType coefficientsIter = constraintsIter->coefficientsBegin();
574 for(std::vector<size_t>::const_iterator variableIDsIter = indicatorVariableLookupTableIter->begin(); variableIDsIter != indicatorVariableLookupTableIter->end(); ++variableIDsIter) {
575 result += labelingBegin[*variableIDsIter] * (*coefficientsIter);
580 const double weight = result - constraintsIter->getBound();
581 switch(constraintsIter->getConstraintOperator()) {
582 case LinearConstraintType::LinearConstraintOperatorType::LessEqual : {
583 if(weight > tolerance) {
584 violatedConstraintsIds_[numViolatedConstraints] = std::distance(constraints_.begin(), constraintsIter);
585 violatedConstraintsWeights_[numViolatedConstraints] = weight;
586 ++numViolatedConstraints;
590 case LinearConstraintType::LinearConstraintOperatorType::Equal : {
591 if(weight > tolerance) {
592 violatedConstraintsIds_[numViolatedConstraints] = std::distance(constraints_.begin(), constraintsIter);
593 violatedConstraintsWeights_[numViolatedConstraints] = weight;
594 ++numViolatedConstraints;
595 }
else if(weight < -tolerance) {
596 violatedConstraintsIds_[numViolatedConstraints] = std::distance(constraints_.begin(), constraintsIter);
597 violatedConstraintsWeights_[numViolatedConstraints] = -weight;
598 ++numViolatedConstraints;
611 if(weight < -tolerance) {
612 violatedConstraintsIds_[numViolatedConstraints] = std::distance(constraints_.begin(), constraintsIter);
613 violatedConstraintsWeights_[numViolatedConstraints] = -weight;
614 ++numViolatedConstraints;
618 ++indicatorVariableLookupTableIter;
622 violatedConstraintsWeightsBegin = violatedConstraintsWeights_.begin();
625 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
628 if(std::distance(constraintsIter->indicatorVariablesBegin(), constraintsIter->indicatorVariablesEnd()) == 0) {
630 std::cout <<
"empty constraint" << std::endl;
633 for(
IndicatorVariablesIteratorType variablesIter = constraintsIter->indicatorVariablesBegin(); variablesIter != constraintsIter->indicatorVariablesEnd(); ++variablesIter) {
634 if(std::distance(variablesIter->begin(), variablesIter->end()) == 0) {
636 std::cout <<
"empty indicator variable" << std::endl;
639 for(
VariableLabelPairsIteratorType indicatorVariablesIter = variablesIter->begin(); indicatorVariablesIter != variablesIter->end(); ++indicatorVariablesIter) {
640 if(indicatorVariablesIter->first >= shape_.size()) {
642 }
else if(indicatorVariablesIter->second >= shape_[indicatorVariablesIter->first]) {
652 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
656 for(
IndicatorVariablesIteratorType variablesIter = constraintsIter->indicatorVariablesBegin(); variablesIter != constraintsIter->indicatorVariablesEnd(); ++variablesIter) {
657 if(std::find(indicatorVariableList_.begin(), indicatorVariableList_.end(), *variablesIter) == indicatorVariableList_.end()) {
658 indicatorVariableList_.push_back(*variablesIter) ;
664 std::sort(indicatorVariableList_.begin(), indicatorVariableList_.end());
667 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
671 std::vector<size_t> currentConstraintLookup;
672 for(
IndicatorVariablesIteratorType variablesIter = constraintsIter->indicatorVariablesBegin(); variablesIter != constraintsIter->indicatorVariablesEnd(); ++variablesIter) {
673 OPENGM_ASSERT(std::find(indicatorVariableList_.begin(), indicatorVariableList_.end(), *variablesIter) != indicatorVariableList_.end());
674 currentConstraintLookup.push_back(std::distance(indicatorVariableList_.begin(), std::find(indicatorVariableList_.begin(), indicatorVariableList_.end(), *variablesIter)));
676 indicatorVariableLookupTable_.push_back(currentConstraintLookup);
681 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
683 const size_t dimensionSize = 1;
684 const size_t shapeSize = src.
dimension();
685 const size_t numConstraintsSize = 1;
686 const size_t operatorTypeSize = src.
constraints_.size();
687 const size_t numIndicatorVariablesPerConstraintSize = src.
constraints_.size();
691 size_t numVariablesPerIndicatorVariablePerConstraintSize = 0;
692 for(LinearConstraintsIteratorType constraintsIter = src.
constraints_.begin(); constraintsIter != src.
constraints_.end(); ++constraintsIter) {
693 numVariablesPerIndicatorVariablePerConstraintSize += std::distance(constraintsIter->indicatorVariablesBegin(), constraintsIter->indicatorVariablesEnd());
695 numVariablesPerIndicatorVariablePerConstraintSize *= 2;
697 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::IndicatorVariablesIteratorType IndicatorVariablesIteratorType;
699 size_t variableStatePairSize = 0;
700 for(LinearConstraintsIteratorType constraintsIter = src.
constraints_.begin(); constraintsIter != src.
constraints_.end(); ++constraintsIter) {
701 for(IndicatorVariablesIteratorType variablesIter = constraintsIter->indicatorVariablesBegin(); variablesIter != constraintsIter->indicatorVariablesEnd(); ++variablesIter) {
702 variableStatePairSize += std::distance(variablesIter->begin(), variablesIter->end());
705 variableStatePairSize *= 2;
707 const size_t totalIndexSize = dimensionSize + shapeSize + operatorTypeSize + numConstraintsSize + numIndicatorVariablesPerConstraintSize + numVariablesPerIndicatorVariablePerConstraintSize + variableStatePairSize;
708 return totalIndexSize;
711 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
712 inline size_t FunctionSerialization<LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >::valueSequenceSize(
const LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>& src) {
713 const size_t boundsSize = src.constraints_.size();
714 const size_t validSize = 1;
715 const size_t invalidSize = 1;
717 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintsIteratorType LinearConstraintsIteratorType;
719 size_t coefficientsSize = 0;
720 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
721 coefficientsSize += std::distance(constraintsIter->coefficientsBegin(), constraintsIter->coefficientsEnd());
724 const size_t totalValueSize = boundsSize + validSize + invalidSize + coefficientsSize;
725 return totalValueSize;
728 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
729 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR>
730 inline void FunctionSerialization<LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >::serialize(
const LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>& src, INDEX_OUTPUT_ITERATOR indexOutIterator, VALUE_OUTPUT_ITERATOR valueOutIterator) {
733 *indexOutIterator = src.dimension();
737 for(
size_t i = 0; i < src.dimension(); i++) {
738 *indexOutIterator = src.shape_[i];
743 *indexOutIterator = src.constraints_.size();
747 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintsIteratorType LinearConstraintsIteratorType;
749 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
750 *indexOutIterator = constraintsIter->getConstraintOperator();
755 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
756 *indexOutIterator = std::distance(constraintsIter->indicatorVariablesBegin(), constraintsIter->indicatorVariablesEnd());
761 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::IndicatorVariablesIteratorType IndicatorVariablesIteratorType;
763 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
764 for(IndicatorVariablesIteratorType variablesIter = constraintsIter->indicatorVariablesBegin(); variablesIter != constraintsIter->indicatorVariablesEnd(); ++variablesIter) {
765 *indexOutIterator =
static_cast<size_t>(variablesIter->getLogicalOperatorType());
767 *indexOutIterator = std::distance(variablesIter->begin(), variablesIter->end());
773 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::VariableLabelPairsIteratorType VariableLabelPairsIteratorType;
775 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
776 for(IndicatorVariablesIteratorType variablesIter = constraintsIter->indicatorVariablesBegin(); variablesIter != constraintsIter->indicatorVariablesEnd(); ++variablesIter) {
777 for(VariableLabelPairsIteratorType indicatorVariablesIter = variablesIter->begin(); indicatorVariablesIter != variablesIter->end(); ++indicatorVariablesIter) {
778 *indexOutIterator = indicatorVariablesIter->first;
780 *indexOutIterator = indicatorVariablesIter->second;
788 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
789 *valueOutIterator = constraintsIter->getBound();
794 *valueOutIterator = src.returnValid_;
798 *valueOutIterator = src.returnInvalid_;
802 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintType::CoefficientsIteratorType CoefficientsIteratorType;
803 for(LinearConstraintsIteratorType constraintsIter = src.constraints_.begin(); constraintsIter != src.constraints_.end(); ++constraintsIter) {
804 for(CoefficientsIteratorType coefficientsIter = constraintsIter->coefficientsBegin(); coefficientsIter != constraintsIter->coefficientsEnd(); ++coefficientsIter) {
805 *valueOutIterator = *coefficientsIter;
811 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
812 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR>
813 inline void FunctionSerialization<LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE> >::deserialize( INDEX_INPUT_ITERATOR indexInIterator, VALUE_INPUT_ITERATOR valueInIterator, LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>& dst) {
816 const size_t dimension = *indexInIterator;
819 INDEX_INPUT_ITERATOR shapeBegin = indexInIterator;
820 INDEX_INPUT_ITERATOR shapeEnd = indexInIterator + dimension;
821 indexInIterator += dimension;
824 typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintsContainerType constraints(*indexInIterator);
828 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintsContainerType::iterator LinearConstraintsIteratorType;
830 for(LinearConstraintsIteratorType constraintsIter = constraints.begin(); constraintsIter != constraints.end(); ++constraintsIter) {
831 constraintsIter->setConstraintOperator(
static_cast<typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintType::LinearConstraintOperatorValueType
>(*indexInIterator));
836 std::vector<INDEX_TYPE> numIndicatorariablesPerConstraint;
837 for(LinearConstraintsIteratorType constraintsIter = constraints.begin(); constraintsIter != constraints.end(); ++constraintsIter) {
838 numIndicatorariablesPerConstraint.push_back(*indexInIterator);
843 std::vector<std::vector<INDEX_TYPE> > numVariablesPerIndicatorVariablePerConstraint;
844 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintType::IndicatorVariableType::LogicalOperatorType LogicalOperatorType;
845 std::vector<std::vector<LogicalOperatorType> > logicalOperatorPerIndicatorVariablePerConstraint;
846 for(
size_t i = 0; i < numIndicatorariablesPerConstraint.size(); ++i) {
847 numVariablesPerIndicatorVariablePerConstraint.push_back(std::vector<INDEX_TYPE>());
848 logicalOperatorPerIndicatorVariablePerConstraint.push_back(std::vector<LogicalOperatorType>());
849 for(
size_t j = 0; j < numIndicatorariablesPerConstraint[i]; ++j) {
850 logicalOperatorPerIndicatorVariablePerConstraint[i].push_back(static_cast<LogicalOperatorType>(*indexInIterator));
852 numVariablesPerIndicatorVariablePerConstraint[i].push_back(*indexInIterator);
858 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintType::IndicatorVariablesContainerType IndicatorVariablesContainerType;
859 std::vector<IndicatorVariablesContainerType> variableStatePairs;
861 for(
size_t i = 0; i < numVariablesPerIndicatorVariablePerConstraint.size(); ++i) {
862 variableStatePairs.push_back(IndicatorVariablesContainerType());
863 for(
size_t j = 0; j < numVariablesPerIndicatorVariablePerConstraint[i].size(); ++j) {
864 variableStatePairs[i].push_back(
typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintType::IndicatorVariableType());
865 for(
size_t k = 0; k < numVariablesPerIndicatorVariablePerConstraint[i][j]; ++k) {
866 const INDEX_TYPE variable = *indexInIterator;
868 const LABEL_TYPE label = *indexInIterator;
870 variableStatePairs[i][j].add(variable, label);
873 variableStatePairs[i][j].setLogicalOperatorType(logicalOperatorPerIndicatorVariablePerConstraint[i][j]);
879 for(LinearConstraintsIteratorType constraintsIter = constraints.begin(); constraintsIter != constraints.end(); ++constraintsIter) {
880 constraintsIter->setBound(*valueInIterator);
885 const VALUE_TYPE returnValid = *valueInIterator;
889 const VALUE_TYPE returnInvalid = *valueInIterator;
893 typedef typename LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>::LinearConstraintType::CoefficientsContainerType CoefficientsContainerType;
894 std::vector<CoefficientsContainerType> coefficients;
895 for(
size_t i = 0; i < numIndicatorariablesPerConstraint.size(); ++i) {
896 coefficients.push_back(CoefficientsContainerType());
897 for(
size_t j = 0; j < numIndicatorariablesPerConstraint[i]; ++j) {
898 coefficients[i].push_back(*valueInIterator);
904 for(
size_t i = 0; i < constraints.size(); ++i) {
905 constraints[i].add(variableStatePairs[i].begin(), variableStatePairs[i].end(), coefficients[i].begin());
908 dst = LinearConstraintFunction<VALUE_TYPE, INDEX_TYPE, LABEL_TYPE>(shapeBegin, shapeEnd, constraints, returnValid, returnInvalid);
LinearConstraintsIteratorType linearConstraintsEnd_impl() const
Implementation of LinearConstraintFunctionBase::linearConstraintsEnd.
ValueType returnValid_
Stores the return value of LinearConstraintFunction::operator() if no constraint is violated...
LinearConstraintType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType
std::vector< LinearConstraintType > LinearConstraintsContainerType
IndicatorVariablesContainerType::const_iterator IndicatorVariablesIteratorType
Defines the const iterator type to iterate over the set of indicator variables.
Provides interface for liner constraint functions.
std::vector< std::vector< size_t > > indicatorVariableLookupTable_
Lookup table for fast access of the indicator variable IDs.
bool checkConstraints() const
Check linear constraints. Only used for assertion in debug mode.
IndicatorVariableType::IteratorType VariableLabelPairsIteratorType
Defines the const iterator type to iterate over the variable label pairs of an indicator variable...
LinearConstraintsContainerType constraints_
Stores the constraints of the linear constraint function.
LinearConstraintFunctionTraitsType::LinearConstraintType LinearConstraintType
Typedef of the LinearConstraint class which is used to represent linear constraints.
std::vector< IndicatorVariableType > IndicatorVariablesContainerType
Defines the storage type for the set of indicator variables.
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsIteratorType ViolatedLinearConstraintsIteratorType
Defines the violated linear constraints iterator type which is used to iterate over the set of violat...
LinearConstraintFunctionTraitsType::IndexType IndexType
Typedef of the INDEX_TYPE template parameter type from the class LinearConstraintFunction.
MinMaxFunctor< ValueType > minMax() const
Get minimum and maximum at the same time.
LinearConstraintFunctionTraitsType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
Defines the indicator variables container iterator type which is used to iterate over the indicator v...
Defines the const iterator type to iterate over the subset of a sequence.
#define OPENGM_ASSERT(expression)
LinearConstraintFunctionTraitsType::LinearConstraintsContainerType LinearConstraintsContainerType
Defines the linear constraints container type which is used to store multiple linear constraints...
LinearConstraintType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsIteratorType ViolatedLinearConstraintsWeightsIteratorType
Defines the violated linear constraints weights iterator type which is used to iterate over the weigh...
IndicatorVariablesIteratorType indicatorVariablesOrderBegin_impl() const
Implementation of LinearConstraintFunctionBase::indicatorVariableOrderBegin.
std::vector< LabelType > shape_
Stores the shape of the linear constraint function.
Default implementation of a linear constraint function class.
LinearConstraintsContainerType::const_iterator LinearConstraintsIteratorType
LinearConstraintFunction()
LinearConstraintFunction constructor.
LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsContainerType ViolatedLinearConstraintsWeightsContainerType
Defines the violated linear constraints weights container type which is used to store the weights of ...
std::vector< double > ViolatedLinearConstraintsWeightsContainerType
void challenge_impl(ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
Implementation of LinearConstraintFunctionBase::challenge.
Base class for linear constraint functions.
std::vector< size_t > violatedConstraintsIds_
Stores the indices of the violated constraints which are detected by LinearConstraintFunction::challe...
IndicatorVariablesContainerType indicatorVariableList_
A list of all indicator variables present in the linear constraint function.
size_t shape(const size_t i) const
Number of labels of the indicated input variable.
ViolatedLinearConstraintsWeightsContainerType::const_iterator ViolatedLinearConstraintsWeightsIteratorType
LinearConstraintsIteratorType linearConstraintsBegin_impl() const
Implementation of LinearConstraintFunctionBase::linearConstraintsBegin.
void createIndicatorVariableLookupTable()
Helper function to create an indicator variable lookup table. The table is stored in LinearConstraint...
ViolatedLinearConstraintsWeightsContainerType violatedConstraintsWeights_
Stores the weights of the violated constraints which are detected by LinearConstraintFunction::challe...
LinearConstraintFunctionTraitsType::LinearConstraintsIteratorType LinearConstraintsIteratorType
Defines the linear constraints container iterator type which is used to iterate over the set of linea...
IndicatorVariablesIteratorType indicatorVariablesOrderEnd_impl() const
Implementation of LinearConstraintFunctionBase::indicatorVariableOrderEnd.
Traits class for linear constraint functions.
ValueType min() const
Minimum value of the linear constraint function.
const size_t FUNCTION_TYPE_ID_OFFSET
User-defined function have ids smaller than FUNCTION_TYPE_ID_OFFSET.
LinearConstraint< ValueType, IndexType, LabelType > LinearConstraintType
Provides implementation for class LinearConstraint.
ValueType operator()(STATES_ITERATOR_TYPE statesBegin) const
Function evaluation.
LinearConstraintFunctionTraits< LinearConstraintFunctionType > LinearConstraintFunctionTraitsType
Typedef of the LinearConstraintFunctionTraits class with appropriate template parameter.
LinearConstraintFunctionTraitsType::ValueType ValueType
Typedef of the VALUE_TYPE template parameter type from the class LinearConstraintFunction.
size_t size() const
Number of parameters.
Provides implementation for class SubsequenceIterator.
LinearConstraintFunctionBase< LinearConstraintFunctionType > LinearConstraintFunctionBaseType
Typedef of the LinearConstraintFunctionBase class with appropriate template parameter.
LinearConstraintFunctionTraitsType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType
Defines the variable label pairs iterator type which is used to iterate over the variable label pairs...
LinearConstraintType::IndicatorVariablesContainerType IndicatorVariablesContainerType
void fillIndicatorVariableList()
Helper function to fill LinearConstraintFunction::indicatorVariableList_ with all indicator variables...
LinearConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE > LinearConstraintFunctionType
Typedef of the LinearConstraintFunction class with appropriate template parameter.
ValueType returnInvalid_
Stores the return value of LinearConstraintFunction::operator() if at least one constraint is violate...
LinearConstraintFunctionTraitsType::IndicatorVariablesContainerType IndicatorVariablesContainerType
Defines the indicator variables container type which is used to store the indicator variables used by...
Define a linear constraint for a set of indicatorVariables.
LinearConstraintFunctionTraitsType::LabelType LabelType
Typedef of the LABEL_TYPE template parameter type from the class LinearConstraintFunction.
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 linear constraint function.
SubsequenceIterator< LinearConstraintsIteratorType, typename std::vector< size_t >::const_iterator > ViolatedLinearConstraintsIteratorType
~LinearConstraintFunction()
LinearConstraintFunction destructor.
ValueType max() const
Maximum value of the linear constraint function.
size_t dimension() const
Number of input variables.