1 #ifndef OPENGM_INDICATOR_VARIABLE_HXX_
2 #define OPENGM_INDICATOR_VARIABLE_HXX_
13 template <
class INDEX_TYPE =
size_t,
class LABEL_TYPE =
size_t>
25 typedef typename VariableLabelPairContainerType::const_iterator
IteratorType;
32 template<
class ITERATOR_TYPE>
36 void reserve(
const size_t numPairs);
37 void add(
const IndexType variable,
const LabelType label);
38 void add(
const VariableLabelPair& variableLabelPair);
39 void add(
const VariableLabelPairContainerType& variableLabelPairs);
40 template<
class ITERATOR_TYPE>
41 void add(
const ITERATOR_TYPE variableLabelPairsBegin,
const ITERATOR_TYPE variableLabelPairsEnd);
45 template<
class ITERATOR_TYPE>
46 bool operator()(
const ITERATOR_TYPE statesBegin)
const;
49 IteratorType
begin()
const;
50 IteratorType
end()
const;
58 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
60 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
62 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
64 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
66 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
68 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
73 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
76 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
79 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
82 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
85 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
88 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
434 template <
class INDEX_TYPE,
class LABEL_TYPE>
436 : variableLabelPairs_(), logicalOperatorType_(
And) {
440 template <
class INDEX_TYPE,
class LABEL_TYPE>
443 logicalOperatorType_(logicalOperatorType) {
447 template <
class INDEX_TYPE,
class LABEL_TYPE>
449 : variableLabelPairs_(1, variableLabelPair),
450 logicalOperatorType_(logicalOperatorType) {
454 template <
class INDEX_TYPE,
class LABEL_TYPE>
456 : variableLabelPairs_(variableLabelPairs),
457 logicalOperatorType_(logicalOperatorType) {
461 template <
class INDEX_TYPE,
class LABEL_TYPE>
462 template<
class ITERATOR_TYPE>
464 : variableLabelPairs_(variableLabelPairsBegin, variableLabelPairsEnd),
465 logicalOperatorType_(logicalOperatorType) {
470 template <
class INDEX_TYPE,
class LABEL_TYPE>
472 variableLabelPairs_.reserve(numPairs);
475 template <
class INDEX_TYPE,
class LABEL_TYPE>
478 std::sort(variableLabelPairs_.begin(), variableLabelPairs_.end());
481 template <
class INDEX_TYPE,
class LABEL_TYPE>
483 variableLabelPairs_.push_back(variableLabelPair);
484 std::sort(variableLabelPairs_.begin(), variableLabelPairs_.end());
487 template <
class INDEX_TYPE,
class LABEL_TYPE>
489 variableLabelPairs_.insert(variableLabelPairs_.end(), variableLabelPairs.begin(), variableLabelPairs.end());
490 std::sort(variableLabelPairs_.begin(), variableLabelPairs_.end());
493 template <
class INDEX_TYPE,
class LABEL_TYPE>
494 template<
class ITERATOR_TYPE>
496 variableLabelPairs_.insert(variableLabelPairs_.end(), variableLabelPairsBegin, variableLabelPairsEnd);
497 std::sort(variableLabelPairs_.begin(), variableLabelPairs_.end());
500 template <
class INDEX_TYPE,
class LABEL_TYPE>
502 logicalOperatorType_ = logicalOperatorType;
506 template <
class INDEX_TYPE,
class LABEL_TYPE>
507 template<
class ITERATOR_TYPE>
510 if(logicalOperatorType_ ==
And) {
511 for(
IteratorType indicatorVariableIter = begin(); indicatorVariableIter != end(); ++indicatorVariableIter) {
512 if(indicatorVariableIter->second != statesBegin[indicatorVariableIter->first]) {
517 }
else if(logicalOperatorType_ ==
Or) {
519 for(
IteratorType indicatorVariableIter = begin(); indicatorVariableIter != end(); ++indicatorVariableIter) {
520 if(indicatorVariableIter->second == statesBegin[indicatorVariableIter->first]) {
527 for(
IteratorType indicatorVariableIter = begin(); indicatorVariableIter != end(); ++indicatorVariableIter) {
528 if(indicatorVariableIter->second == statesBegin[indicatorVariableIter->first]) {
538 template <
class INDEX_TYPE,
class LABEL_TYPE>
540 return variableLabelPairs_.begin();
543 template <
class INDEX_TYPE,
class LABEL_TYPE>
545 return variableLabelPairs_.end();
548 template <
class INDEX_TYPE,
class LABEL_TYPE>
550 return logicalOperatorType_;
553 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
558 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
563 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
565 if(indicatorVar1.logicalOperatorType_ < indicatorVar2.logicalOperatorType_) {
567 }
else if(indicatorVar1.logicalOperatorType_ > indicatorVar2.logicalOperatorType_) {
570 if(indicatorVar1.variableLabelPairs_.size() > indicatorVar2.variableLabelPairs_.size()) {
573 if(indicatorVar1.variableLabelPairs_.size() == indicatorVar2.variableLabelPairs_.size()) {
574 if(indicatorVar1.variableLabelPairs_.size() == 0) {
577 for(
size_t i = 0; i < indicatorVar1.variableLabelPairs_.size(); ++i) {
578 if(indicatorVar1.variableLabelPairs_[i].first > indicatorVar2.variableLabelPairs_[i].first) {
580 }
else if(indicatorVar1.variableLabelPairs_[i].first == indicatorVar2.variableLabelPairs_[i].first) {
581 if(indicatorVar1.variableLabelPairs_[i].second >= indicatorVar2.variableLabelPairs_[i].second) {
591 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
619 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
621 if(indicatorVar1.logicalOperatorType_ < indicatorVar2.logicalOperatorType_) {
623 }
else if(indicatorVar1.logicalOperatorType_ > indicatorVar2.logicalOperatorType_) {
626 if(indicatorVar1.variableLabelPairs_.size() > indicatorVar2.variableLabelPairs_.size()) {
629 if(indicatorVar1.variableLabelPairs_.size() == indicatorVar2.variableLabelPairs_.size()) {
630 for(
size_t i = 0; i < indicatorVar1.variableLabelPairs_.size(); ++i) {
631 if(indicatorVar1.variableLabelPairs_[i].first > indicatorVar2.variableLabelPairs_[i].first) {
633 }
else if(indicatorVar1.variableLabelPairs_[i].first == indicatorVar2.variableLabelPairs_[i].first) {
634 if(indicatorVar1.variableLabelPairs_[i].second > indicatorVar2.variableLabelPairs_[i].second) {
644 template<
class INDEX1_TYPE,
class LABEL1_TYPE,
class INDEX2_TYPE,
class LABEL2_TYPE>
friend bool operator!=(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
Inequality operator for IndicatorVariable.
bool operator>=(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
friend bool operator>=(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
Greater equal operator for IndicatorVariable.
LABEL_TYPE LabelType
Typedef of the LABEL_TYPE template parameter type from the class IndicatorVariable.
The indicator variable will be interpreted as 1 if none of the variables associated by the indicator ...
IteratorType begin() const
Get the iterator over the sequence of variable label pairs from the indicator variable.
VariableLabelPairContainerType::const_iterator IteratorType
A const iterator to iterate over the VariableLabelPair elements.
bool operator!=(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
bool operator==(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
IteratorType end() const
Get the end iterator of the sequence of variable label pairs from the indicator variable.
VariableLabelPairContainerType variableLabelPairs_
Storage for the variable label pairs.
friend bool operator==(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
Equality operator for IndicatorVariable.
std::vector< VariableLabelPair > VariableLabelPairContainerType
A vector containing VariableLabelPair elements.
IndicatorVariable()
IndicatorVariable constructor.
void setLogicalOperatorType(const LogicalOperatorType logicalOperatorType)
Set the logical operator type of the indicator variable.
friend bool operator>(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
Greater operator for IndicatorVariable.
void reserve(const size_t numPairs)
Preallocate memory.
bool operator>(const IndicatorVariable< INDEX1_TYPE, LABEL1_TYPE > &indicatorVar1, const IndicatorVariable< INDEX2_TYPE, LABEL2_TYPE > &indicatorVar2)
void add(const IndexType variable, const LabelType label)
Add a variable label pair to the indicator variable.
Combine a group of variables to a new variable.
std::pair< IndexType, LabelType > VariableLabelPair
A pair representing a single state of a variable.
LogicalOperatorType logicalOperatorType_
Storage for the logical operator type of the indicator variable.
bool operator()(const ITERATOR_TYPE statesBegin) const
Evaluation operator to check if the indicator variable is active for the given labeling.
The indicator variable will be interpreted as 1 if all variables associated by the indicator variable...
The indicator variable will be interpreted as 1 if at least one of the variables associated by the in...
LogicalOperatorType
This enum defines the logical operator types which are supported by the indicator variables...
LogicalOperatorType getLogicalOperatorType() const
Get the logical operator type of the indicator variable.
Disjunction as a binary operation.
Conjunction as a binary operation.
INDEX_TYPE IndexType
Typedef of the INDEX_TYPE template parameter type from the class IndicatorVariable.