OpenGM  2.3.x
Discrete Graphical Model Library
Public Types | Public Member Functions | Protected Attributes | List of all members
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE > Class Template Reference

Define a linear constraint for a set of indicatorVariables. More...

#include <linear_constraint.hxx>

+ Collaboration diagram for opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >:

Public Types

typedef VALUE_TYPE ValueType
 Typedef of the VALUE_TYPE template parameter type from the class LinearConstraint. More...
 
typedef INDEX_TYPE IndexType
 Typedef of the INDEX_TYPE template parameter type from the class LinearConstraint. More...
 
typedef LABEL_TYPE LabelType
 Typedef of the LABEL_TYPE template parameter type from the class LinearConstraint. More...
 
typedef IndicatorVariable< IndexType, LabelTypeIndicatorVariableType
 Typedef of the IndicatorVariable class with appropriate template parameter. More...
 
typedef std::vector< IndicatorVariableTypeIndicatorVariablesContainerType
 Defines the storage type for the set of indicator variables. More...
 
typedef std::vector< ValueTypeCoefficientsContainerType
 Defines the storage type for the set of coefficients for the indicator variables. More...
 
typedef ValueType BoundType
 Defines the data type for the bound. More...
 
typedef LinearConstraintTraits::LinearConstraintOperator LinearConstraintOperatorType
 Defines the linear constraint operator. More...
 
typedef LinearConstraintOperatorType::ValueType LinearConstraintOperatorValueType
 Defines the linear constraint operator type. More...
 
typedef IndicatorVariableType::IteratorType VariableLabelPairsIteratorType
 Defines the const iterator type to iterate over the variable label pairs of an indicator variable. More...
 
typedef IndicatorVariablesContainerType::const_iterator IndicatorVariablesIteratorType
 Defines the const iterator type to iterate over the set of indicator variables. More...
 
typedef CoefficientsContainerType::const_iterator CoefficientsIteratorType
 Defines the const iterator type to iterate over the set of coefficients for the indicator variables. More...
 

Public Member Functions

 LinearConstraint ()
 LinearConstraint constructor. More...
 
 LinearConstraint (const IndicatorVariablesContainerType &indicatorVariables, const CoefficientsContainerType &coefficients, const BoundType bound=0.0, const LinearConstraintOperatorValueType constraintOperator=LinearConstraintOperatorType::LessEqual)
 LinearConstraint constructor. More...
 
template<class INDICATOR_VARIABLES_ITERATOR_TYPE , class COEFFICIENTS_ITERATOR_TYPE >
 LinearConstraint (const INDICATOR_VARIABLES_ITERATOR_TYPE indicatorVariablesBegin, const INDICATOR_VARIABLES_ITERATOR_TYPE indicatorVariablesEnd, const COEFFICIENTS_ITERATOR_TYPE coefficientsBegin, const BoundType bound=0.0, const LinearConstraintOperatorValueType constraintOperator=LinearConstraintOperatorType::LessEqual)
 LinearConstraint constructor. More...
 
 LinearConstraint (const LinearConstraint< ValueType, IndexType, LabelType > &linearConstraint)
 LinearConstraint constructor. More...
 
void reserve (const size_t numIndicatorVariables)
 Preallocate memory. More...
 
void add (const IndicatorVariableType &indicatorVariable, const ValueType coefficient)
 Add a single indicator variable and the corresponding coefficient to the linear constraint. More...
 
void add (const IndicatorVariablesContainerType &indicatorVariables, const CoefficientsContainerType &coefficients)
 Add a set of indicator variables and the corresponding coefficients to the linear constraint. More...
 
template<class INDICATOR_VARIABLES_ITERATOR_TYPE , class COEFFICIENTS_ITERATOR_TYPE >
void add (const INDICATOR_VARIABLES_ITERATOR_TYPE indicatorVariablesBegin, const INDICATOR_VARIABLES_ITERATOR_TYPE indicatorVariablesEnd, const COEFFICIENTS_ITERATOR_TYPE coefficientsBegin)
 Add a set of indicator variables and the corresponding coefficients to the linear constraint. More...
 
void setBound (const BoundType bound)
 Set the bound of the linear constraint. More...
 
void setConstraintOperator (const LinearConstraintOperatorValueType constraintOperator)
 Set the constraint operator for the linear constraint. More...
 
template<class ITERATOR_TYPE >
ValueType operator() (const ITERATOR_TYPE statesBegin) const
 Evaluation operator to check if the linear constraint is violated by the given labeling. More...
 
IndicatorVariablesIteratorType indicatorVariablesBegin () const
 Get the begin iterator to the set of indicator variables. More...
 
IndicatorVariablesIteratorType indicatorVariablesEnd () const
 Get the end iterator to the set of indicator variables. More...
 
CoefficientsIteratorType coefficientsBegin () const
 Get the begin iterator to the set of coefficients for the indicator variables. More...
 
CoefficientsIteratorType coefficientsEnd () const
 Get the end iterator to the set of coefficients for the indicator variables. More...
 
BoundType getBound () const
 Get the bound of the linear constraint. More...
 
LinearConstraintOperatorValueType getConstraintOperator () const
 Get the constraint operator of the linear constraint. More...
 

Protected Attributes

IndicatorVariablesContainerType indicatorVariables_
 Storage for the set of indicator variables. More...
 
CoefficientsContainerType coefficients_
 Storage for the set of coefficients for the indicator variables. More...
 
BoundType bound_
 Storage for the bound of the linear constraint. More...
 
LinearConstraintOperatorValueType constraintOperator_
 Storage for the constraint operator of the linear constraint. More...
 

Detailed Description

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
class opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >

Define a linear constraint for a set of indicatorVariables.

This class defines a linear constraint for a set of indicator variables. Each variable has to be an indicator variable of the class IndicatorVariable. Each constraint consists of four parts:

  1. A set of indicator variables.
  2. A set of coefficients. One coefficient for each indicator variable.
  3. A bound.
  4. An operator type which defines how the left hand side of the constraint is compared against the bound.

The constraint will be evaluated by the following formula:

\[ \sum_i c_i \cdot v_i \quad \bigcirc \quad b. \]

Here $v_i$ represents the $i$-th indicator variable, $c_i$ represents the coefficient belonging to the $i$-th indictor variable, $b$ represents the bound and $\bigcirc$ is the selected operator type ( $\leq$, $=$ or $\geq$).

Template Parameters
VALUE_TYPEValue type.
INDEX_TYPEIndex type.
LABEL_TYPELabel type.

Definition at line 21 of file linear_constraint.hxx.

Member Typedef Documentation

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::BoundType

Defines the data type for the bound.

Definition at line 31 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::CoefficientsContainerType

Defines the storage type for the set of coefficients for the indicator variables.

Definition at line 30 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::CoefficientsIteratorType

Defines the const iterator type to iterate over the set of coefficients for the indicator variables.

Definition at line 37 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndexType

Typedef of the INDEX_TYPE template parameter type from the class LinearConstraint.

Definition at line 25 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndicatorVariablesContainerType

Defines the storage type for the set of indicator variables.

Definition at line 29 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndicatorVariablesIteratorType

Defines the const iterator type to iterate over the set of indicator variables.

Definition at line 36 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndicatorVariableType

Typedef of the IndicatorVariable class with appropriate template parameter.

Definition at line 28 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelType

Typedef of the LABEL_TYPE template parameter type from the class LinearConstraint.

Definition at line 26 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraintOperatorType

Defines the linear constraint operator.

Definition at line 32 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraintOperatorValueType

Defines the linear constraint operator type.

Definition at line 33 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::ValueType

Typedef of the VALUE_TYPE template parameter type from the class LinearConstraint.

Definition at line 24 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::VariableLabelPairsIteratorType

Defines the const iterator type to iterate over the variable label pairs of an indicator variable.

Definition at line 35 of file linear_constraint.hxx.

Constructor & Destructor Documentation

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraint ( )
inline

LinearConstraint constructor.

This constructor will create an empty LinearConstraint.

Definition at line 391 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraint ( const IndicatorVariablesContainerType indicatorVariables,
const CoefficientsContainerType coefficients,
const BoundType  bound = 0.0,
const LinearConstraintOperatorValueType  constraintOperator = LinearConstraintOperatorType::LessEqual 
)
inline

LinearConstraint constructor.

This constructor will create a LinearConstraint by copying the set of indicator variables and coefficients.

Parameters
[in]indicatorVariablesThe set of indicator variables.
[in]coefficientsThe set of coefficients for the indicator variables.
[in]boundThe right hand side of the constraint.
[in]constraintOperatorThe comparison operator by which the constraint will be evaluated.

Definition at line 398 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class INDICATOR_VARIABLES_ITERATOR_TYPE , class COEFFICIENTS_ITERATOR_TYPE >
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraint ( const INDICATOR_VARIABLES_ITERATOR_TYPE  indicatorVariablesBegin,
const INDICATOR_VARIABLES_ITERATOR_TYPE  indicatorVariablesEnd,
const COEFFICIENTS_ITERATOR_TYPE  coefficientsBegin,
const BoundType  bound = 0.0,
const LinearConstraintOperatorValueType  constraintOperator = LinearConstraintOperatorType::LessEqual 
)
inline

LinearConstraint constructor.

This constructor will create a LinearConstraint by copying the set of indicator variables and coefficients.

Template Parameters
INDICATOR_VARIABLES_ITERATOR_TYPEIterator type to iterate over the set of indicator variables.
COEFFICIENTS_ITERATOR_TYPEIterator type to iterate over the set of coefficients for the indicator variables.
Parameters
[in]indicatorVariablesBeginIterator pointing to the begin of the set of indicator variables.
[in]indicatorVariablesEndIterator pointing to the end of the set of indicator variables.
[in]coefficientsBeginIterator pointing to the begin of the set of coefficients for the indicator variables.
[in]boundThe right hand side of the constraint.
[in]constraintOperatorThe comparison operator by which the constraint will be evaluated.

Definition at line 406 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraint ( const LinearConstraint< ValueType, IndexType, LabelType > &  linearConstraint)
inline

LinearConstraint constructor.

This constructor will create a LinearConstraint by copying an existing linear constraint.

Parameters
[in]linearConstraintExisting linear constraint which will be copied.

Definition at line 414 of file linear_constraint.hxx.

Member Function Documentation

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
void opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::add ( const IndicatorVariableType indicatorVariable,
const ValueType  coefficient 
)
inline

Add a single indicator variable and the corresponding coefficient to the linear constraint.

Parameters
[in]indicatorVariableIndicator variable which will be added to the linear constraint.
[in]coefficientCoefficient of the indicator variable.

Definition at line 429 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
void opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::add ( const IndicatorVariablesContainerType indicatorVariables,
const CoefficientsContainerType coefficients 
)
inline

Add a set of indicator variables and the corresponding coefficients to the linear constraint.

Parameters
[in]indicatorVariablesSet of indicator variables which will be added to the linear constraint.
[in]coefficientsSet of coefficients for the indicator variables.

Definition at line 435 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class INDICATOR_VARIABLES_ITERATOR_TYPE , class COEFFICIENTS_ITERATOR_TYPE >
void opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::add ( const INDICATOR_VARIABLES_ITERATOR_TYPE  indicatorVariablesBegin,
const INDICATOR_VARIABLES_ITERATOR_TYPE  indicatorVariablesEnd,
const COEFFICIENTS_ITERATOR_TYPE  coefficientsBegin 
)
inline

Add a set of indicator variables and the corresponding coefficients to the linear constraint.

Template Parameters
INDICATOR_VARIABLES_ITERATOR_TYPEIterator type to iterate over the set of indicator variables.
COEFFICIENTS_ITERATOR_TYPEIterator type to iterate over the set of coefficients for the indicator variables.
Parameters
[in]indicatorVariablesBeginIterator pointing to the begin of the set of indicator variables which will be added to the linear constraint.
[in]indicatorVariablesEndIterator pointing to the end of the set of indicator variables which will be added to the linear constraint.
[in]coefficientsBeginIterator pointing to the begin of the set of coefficients for the indicator variables.

Definition at line 442 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::CoefficientsIteratorType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::coefficientsBegin ( ) const
inline

Get the begin iterator to the set of coefficients for the indicator variables.

Returns
The const iterator pointing to the begin of the set of coefficients for the indicator variables.

Definition at line 517 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::CoefficientsIteratorType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::coefficientsEnd ( ) const
inline

Get the end iterator to the set of coefficients for the indicator variables.

Returns
The const iterator pointing to the end of the set of coefficients for the indicator variables.

Definition at line 522 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::BoundType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::getBound ( ) const
inline

Get the bound of the linear constraint.

Returns
The bound of the linear constraint.

Definition at line 527 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LinearConstraintOperatorValueType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::getConstraintOperator ( ) const
inline

Get the constraint operator of the linear constraint.

Returns
The constraint operator of the linear constraint.

Definition at line 532 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndicatorVariablesIteratorType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::indicatorVariablesBegin ( ) const
inline

Get the begin iterator to the set of indicator variables.

Returns
The const iterator pointing to the begin of the set of indicator variables.

Definition at line 507 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndicatorVariablesIteratorType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::indicatorVariablesEnd ( ) const
inline

Get the end iterator to the set of indicator variables.

Returns
The const iterator pointing to the end of the set of indicator variables.

Definition at line 512 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class ITERATOR_TYPE >
LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::ValueType opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::operator() ( const ITERATOR_TYPE  statesBegin) const
inline

Evaluation operator to check if the linear constraint is violated by the given labeling.

Template Parameters
ITERATOR_TYPEIterator type.
Parameters
[in]statesBeginIterator pointing to the begin of the labeling.
Returns
The absolute value by which the constraint is violated (0.0 if the linear constraint is not violated).
Warning
No boundary check is performed.

Definition at line 459 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
void opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::reserve ( const size_t  numIndicatorVariables)
inline

Preallocate memory.

The reserve function fill preallocate enough memory to store at least the stated number of indicator variables and the corresponding coefficients.

Parameters
[in]numIndicatorVariablesThe number of indicator variables for which memory will be allocated.

Definition at line 423 of file linear_constraint.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
void opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::setBound ( const BoundType  bound)
inline

Set the bound of the linear constraint.

Parameters
[in]boundThe new bound for the linear constraint.

Definition at line 448 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
void opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::setConstraintOperator ( const LinearConstraintOperatorValueType  constraintOperator)
inline

Set the constraint operator for the linear constraint.

Parameters
[in]constraintOperatorThe new constraint operator for the linear constraint.

Definition at line 453 of file linear_constraint.hxx.

+ Here is the caller graph for this function:

Member Data Documentation

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::bound_
protected

Storage for the bound of the linear constraint.

Definition at line 70 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::coefficients_
protected

Storage for the set of coefficients for the indicator variables.

Definition at line 69 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::constraintOperator_
protected

Storage for the constraint operator of the linear constraint.

Definition at line 71 of file linear_constraint.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LinearConstraint< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::indicatorVariables_
protected

Storage for the set of indicator variables.

Definition at line 68 of file linear_constraint.hxx.