1 #ifndef OPENGM_LP_INFERENCE_BASE_HXX_
2 #define OPENGM_LP_INFERENCE_BASE_HXX_
25 template <
class LP_INFERENCE_TYPE>
28 template <
class LP_INFERENCE_TYPE>
29 class LPInferenceBase :
public Inference<typename LPInferenceTraits<LP_INFERENCE_TYPE>::GraphicalModelType, typename LPInferenceTraits<LP_INFERENCE_TYPE>::AccumulationType> {
53 typedef typename LPInferenceTraitsType::SolverType
SolverType;
89 template<
class VISITOR_TYPE>
117 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
118 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
120 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
124 template<
class FUNCTION_TYPE>
133 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
134 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
136 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
140 template<
class FUNCTION_TYPE>
149 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
150 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
152 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
156 template<
class FUNCTION_TYPE>
165 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
166 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
168 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
172 template<
class FUNCTION_TYPE>
185 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
186 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
188 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
192 template<
class FUNCTION_TYPE>
205 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
206 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
208 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
212 template<
class FUNCTION_TYPE>
224 const GraphicalModelType&
gm_;
254 LPInferenceBase(
const GraphicalModelType& gm,
const Parameter& parameter = Parameter());
271 template<
class LABELING_ITERATOR_TYPE>
272 SolverIndexType
factorLPVariableIndex(
const IndexType factorID, LABELING_ITERATOR_TYPE labelingBegin,
const LABELING_ITERATOR_TYPE labelingEnd)
const;
273 template <
class HIGHER_ORDER_FACTORS_MAP_TYPE,
class INDICATOR_VARIABLES_MAP_TYPE>
274 bool getLPVariableIndexFromIndicatorVariable(
const HIGHER_ORDER_FACTORS_MAP_TYPE& higherOrderFactorVariablesLookupTable,
const INDICATOR_VARIABLES_MAP_TYPE& indicatorVariablesLookupTable,
const IndicatorVariableType& indicatorVariable,
const IndexType linearConstraintFactorIndex, SolverIndexType& lpVariableIndex)
const;
283 template <
class VISITOR_TYPE>
285 template <
class VISITOR_TYPE,
typename Parameter::Relaxation RELAXATION>
287 template <
class VISITOR_TYPE,
typename Parameter::Relaxation RELAXATION,
typename Parameter::ChallengeHeuristic HEURISTIC>
289 template <
class VISITOR_TYPE,
typename Parameter::Relaxation RELAXATION,
typename Parameter::ChallengeHeuristic HEURISTIC,
bool USE_INFINITE_ITERATIONS>
291 template <
class VISITOR_TYPE,
typename Parameter::Relaxation RELAXATION,
typename Parameter::ChallengeHeuristic HEURISTIC,
bool USE_INFINITE_ITERATIONS,
bool ADD_ALL_VIOLATED_CONSTRAINTS>
293 template <
class VISITOR_TYPE,
typename Parameter::Relaxation RELAXATION,
typename Parameter::ChallengeHeuristic HEURISTIC,
bool USE_INFINITE_ITERATIONS,
bool ADD_ALL_VIOLATED_CONSTRAINTS,
bool USE_INTEGER_CONSTRAINTS>
295 template <
typename Parameter::Relaxation RELAXATION,
typename Parameter::ChallengeHeuristic HEURISTIC,
bool ADD_ALL_VIOLATED_CONSTRAINTS>
297 template <
typename Parameter::Relaxation RELAXATION,
typename Parameter::ChallengeHeuristic HEURISTIC,
bool ADD_ALL_VIOLATED_CONSTRAINTS>
303 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
305 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
309 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
313 typename LP_INFERENCE_BASE_TYPE::IntegerSolutionSubsequenceIterator
labelingBegin_;
319 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
320 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
322 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
326 template<
class FUNCTION_TYPE>
331 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
335 typename LP_INFERENCE_BASE_TYPE::RelaxedSolutionSubsequenceIterator
labelingBegin_;
341 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
342 void operator()(
const LINEAR_CONSTRAINT_FUNCTION_TYPE& linearConstraintFunction);
344 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
348 template<
class FUNCTION_TYPE>
1751 template <
class LP_INFERENCE_TYPE>
1753 : SolverParameterType(), integerConstraintNodeVar_(false),
1754 integerConstraintFactorVar_(false), useSoftConstraints_(false),
1755 useFunctionTransfer_(false), mergeParallelFactors_(false),
1756 nameConstraints_(false), relaxation_(LocalPolytope),
1757 maxNumIterations_(1000), maxNumConstraintsPerIter_(0),
1762 template <
class LP_INFERENCE_TYPE>
1767 template <
class LP_INFERENCE_TYPE>
1769 EmptyVisitorType visitor;
1770 return infer(visitor);
1773 template <
class LP_INFERENCE_TYPE>
1774 template<
class VISITOR_TYPE>
1782 template <
class LP_INFERENCE_TYPE>
1784 if(inferenceStarted_) {
1785 return static_cast<const LPInferenceType*
>(
this)->objectiveFunctionValueBound() +
constValue_;
1788 return AccumulationType::template ineutral<ValueType>();
1792 template <
class LP_INFERENCE_TYPE>
1794 std::vector<LabelType> states;
1796 return gm_.evaluate(states);
1799 template <
class LP_INFERENCE_TYPE>
1801 x.resize(gm_.numberOfVariables());
1802 if(inferenceStarted_) {
1803 SolverSolutionIteratorType solutionIterator =
static_cast<const LPInferenceType*
>(
this)->solutionBegin();
1804 for(
IndexType node = 0; node < gm_.numberOfVariables(); ++node) {
1805 SolverIndexType currentNodeLPVariable = nodesLPVariablesOffset_[node];
1806 SolverValueType bestValue = solutionIterator[currentNodeLPVariable];
1808 for(
LabelType i = 1; i < gm_.numberOfLabels(node); ++i) {
1809 ++currentNodeLPVariable;
1810 const SolverValueType currentValue = solutionIterator[currentNodeLPVariable];
1811 if(currentValue > bestValue) {
1812 bestValue = currentValue;
1820 for(
IndexType node = 0; node < gm_.numberOfVariables(); ++node) {
1827 template <
class LP_INFERENCE_TYPE>
1829 : gm_(gm), parameter_(parameter), constValue_(0.0), unaryFactors_(),
1830 higherOrderFactors_(), linearConstraintFactors_(), transferableFactors_(),
1831 inferenceStarted_(false), numLPVariables_(0), numNodesLPVariables_(0),
1832 numFactorsLPVariables_(0), numLinearConstraintsLPVariables_(0),
1833 numTransferedFactorsLPVariables(0), numSlackVariables_(0),
1834 nodesLPVariablesOffset_(gm_.numberOfVariables()),
1835 factorsLPVariablesOffset_(gm_.numberOfFactors()),
1836 linearConstraintsLPVariablesIndicesLookupTable_(),
1837 transferedFactorsLPVariablesIndicesLookupTable_(),
1838 linearConstraintLPVariablesSubsequenceIndices_(),
1839 addLocalPolytopeFactorConstraintCachePreviousFactorID_(gm_.numberOfFactors()),
1840 addLocalPolytopeFactorConstraintCacheFactorLPVariableIDs_(),
1841 inactiveConstraints_() {
1842 if(!opengm::meta::Compare<OperatorType, opengm::Adder>::value) {
1843 throw RuntimeError(
"This implementation does only supports Min-Sum-Semiring and Max-Sum-Semiring.");
1865 switch(parameter_.relaxation_){
1884 static_cast<LPInferenceType*
>(
this)->addConstraintsFinished();
1888 addLocalPolytopeFactorConstraintCachePreviousFactorID_ = gm_.numberOfFactors();
1891 template <
class LP_INFERENCE_TYPE>
1896 template <
class LP_INFERENCE_TYPE>
1899 for(
IndexType factorIndex = 0; factorIndex < gm_.numberOfFactors(); ++factorIndex){
1900 gm_[factorIndex].callFunctor(isTransferableFunctor);
1901 if((!parameter_.useSoftConstraints_) && gm_[factorIndex].isLinearConstraint()) {
1902 linearConstraintFactors_.push_back(factorIndex);
1903 }
else if(parameter_.useFunctionTransfer_ && isTransferableFunctor.
isTransferable_) {
1904 transferableFactors_.push_back(factorIndex);
1905 }
else if(gm_[factorIndex].numberOfVariables() == 0) {
1907 constValue_ += gm_[factorIndex](&l);
1908 }
else if(gm_[factorIndex].numberOfVariables() == 1) {
1909 unaryFactors_.push_back(factorIndex);
1910 }
else if(gm_[factorIndex].numberOfVariables() > 1) {
1911 higherOrderFactors_.push_back(factorIndex);
1916 template <
class LP_INFERENCE_TYPE>
1919 for(
IndexType node = 0; node < gm_.numberOfVariables(); ++node){
1920 numNodesLPVariables_ += gm_.numberOfLabels(node);
1921 nodesLPVariablesOffset_[node] = numLPVariables_;
1922 numLPVariables_ += gm_.numberOfLabels(node);
1926 for(
IndexType i = 0; i < unaryFactors_.size(); ++i) {
1927 const IndexType factorIndex = unaryFactors_[i];
1928 const IndexType node = gm_[factorIndex].variableIndex(0);
1929 factorsLPVariablesOffset_[factorIndex] = nodesLPVariablesOffset_[node];
1935 std::map<std::vector<IndexType>,
IndexType> higherOrderFactorVariablesLookupTable;
1936 for(
IndexType i = 0; i < higherOrderFactors_.size(); ++i) {
1937 const IndexType factorIndex = higherOrderFactors_[i];
1938 bool duplicate =
false;
1939 if(parameter_.mergeParallelFactors_) {
1941 std::vector<IndexType> currentFactorVariables(gm_[factorIndex].numberOfVariables());
1942 for(
IndexType j = 0; j < gm_[factorIndex].numberOfVariables(); ++j) {
1943 currentFactorVariables[j] = gm_[factorIndex].variableIndex(j);
1945 const typename std::map<std::vector<IndexType>,
IndexType>::const_iterator iter = higherOrderFactorVariablesLookupTable.find(currentFactorVariables);
1946 if(iter != higherOrderFactorVariablesLookupTable.end()) {
1948 factorsLPVariablesOffset_[factorIndex] = factorsLPVariablesOffset_[iter->second];
1951 higherOrderFactorVariablesLookupTable[currentFactorVariables] = factorIndex;
1955 const size_t currentSize = gm_[factorIndex].size();
1956 numFactorsLPVariables_ += currentSize;
1957 factorsLPVariablesOffset_[factorIndex] = numLPVariables_;
1958 numLPVariables_ += currentSize;
1962 OPENGM_ASSERT(numLPVariables_ == numNodesLPVariables_ + numFactorsLPVariables_);
1967 std::map<std::pair<typename IndicatorVariableType::LogicalOperatorType, std::vector<std::pair<IndexType, LabelType> > >, SolverIndexType> linearConstraintIndicatorVariablesLookupTable;
1970 for(
IndexType i = 0; i < linearConstraintFactors_.size(); ++i) {
1971 const IndexType currentLinearConstraintFactorIndex = linearConstraintFactors_[i];
1972 factorsLPVariablesOffset_[currentLinearConstraintFactorIndex] = numLPVariables_;
1973 gm_[currentLinearConstraintFactorIndex].callFunctor(getIndicatorVariablesOrderBegin);
1975 gm_[currentLinearConstraintFactorIndex].callFunctor(getIndicatorVariablesOrderEnd);
1978 linearConstraintsLPVariablesIndicesLookupTable_.push_back(std::map<const IndicatorVariableType, SolverIndexType>());
1979 const size_t numIndicatorVariables = std::distance(currentIndicatorVariablesBegin, currentIndicatorVariablesEnd);
1980 for(
size_t j = 0; j < numIndicatorVariables; ++j) {
1981 const IndicatorVariableType& currentIndicatorVariable = *currentIndicatorVariablesBegin;
1983 SolverIndexType lpVariableIndex = std::numeric_limits<SolverIndexType>::max();
1984 const bool matchingLPVariableIndexFound = getLPVariableIndexFromIndicatorVariable(higherOrderFactorVariablesLookupTable, linearConstraintIndicatorVariablesLookupTable, currentIndicatorVariable, currentLinearConstraintFactorIndex, lpVariableIndex);
1986 if(matchingLPVariableIndexFound) {
1987 linearConstraintsLPVariablesIndicesLookupTable_.back()[currentIndicatorVariable] = lpVariableIndex;
1990 linearConstraintsLPVariablesIndicesLookupTable_.back()[currentIndicatorVariable] = numLPVariables_;
1991 const size_t currentIndicatorVariableSize = std::distance(currentIndicatorVariable.
begin(), currentIndicatorVariable.
end());
1992 std::vector<std::pair<IndexType, LabelType> > currentVariableLabelPairs(currentIndicatorVariableSize);
1993 for(
size_t k = 0; k < currentIndicatorVariableSize; ++k) {
1994 currentVariableLabelPairs[k] = std::pair<IndexType, LabelType>(gm_[currentLinearConstraintFactorIndex].variableIndex((currentIndicatorVariable.
begin() + k)->first), (currentIndicatorVariable.
begin() + k)->second);
1996 linearConstraintIndicatorVariablesLookupTable[make_pair(currentIndicatorVariable.
getLogicalOperatorType(), currentVariableLabelPairs)] = numLPVariables_;
1997 ++numLinearConstraintsLPVariables_;
2000 ++currentIndicatorVariablesBegin;
2002 OPENGM_ASSERT(currentIndicatorVariablesBegin == currentIndicatorVariablesEnd);
2005 OPENGM_ASSERT(linearConstraintFactors_.size() == linearConstraintsLPVariablesIndicesLookupTable_.size());
2006 OPENGM_ASSERT(numLPVariables_ == numNodesLPVariables_ + numFactorsLPVariables_ + numLinearConstraintsLPVariables_);
2011 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2012 const IndexType currentTransferableFactorIndex = transferableFactors_[i];
2013 factorsLPVariablesOffset_[currentTransferableFactorIndex] = numLPVariables_;
2016 gm_[currentTransferableFactorIndex].callFunctor(numSlackVariablesFunctor);
2020 transferedFactorsLPVariablesIndicesLookupTable_.push_back(std::map<const IndicatorVariableType, SolverIndexType>());
2023 IndicatorVariablesContainerType currentIndicatorVariables;
2024 getIndicatorVariablesFunctor.
variables_ = ¤tIndicatorVariables;
2025 gm_[currentTransferableFactorIndex].callFunctor(getIndicatorVariablesFunctor);
2028 for(IndicatorVariablesIteratorType iter = currentIndicatorVariables.begin(); iter != currentIndicatorVariables.end(); ++iter) {
2029 const IndicatorVariableType& currentIndicatorVariable = *iter;
2030 const size_t currentIndicatorVariableSize = std::distance(currentIndicatorVariable.
begin(), currentIndicatorVariable.
end());
2032 if(currentIndicatorVariableSize == 1) {
2033 if(currentIndicatorVariable.
begin()->first >= gm_[currentTransferableFactorIndex].numberOfVariables()) {
2035 transferedFactorsLPVariablesIndicesLookupTable_.back()[currentIndicatorVariable] = numSlackVariables_ + currentNumSlackVariables;
2036 ++currentNumSlackVariables;
2041 SolverIndexType lpVariableIndex;
2042 const bool matchingLPVariableIndexFound = getLPVariableIndexFromIndicatorVariable(higherOrderFactorVariablesLookupTable, linearConstraintIndicatorVariablesLookupTable, currentIndicatorVariable, currentTransferableFactorIndex, lpVariableIndex);
2044 if(matchingLPVariableIndexFound) {
2045 transferedFactorsLPVariablesIndicesLookupTable_.back()[currentIndicatorVariable] = lpVariableIndex;
2048 transferedFactorsLPVariablesIndicesLookupTable_.back()[currentIndicatorVariable] = numLPVariables_;
2049 const size_t currentIndicatorVariableSize = std::distance(currentIndicatorVariable.
begin(), currentIndicatorVariable.
end());
2050 std::vector<std::pair<IndexType, LabelType> > currentVariableLabelPairs(currentIndicatorVariableSize);
2051 for(
size_t j = 0; j < currentIndicatorVariableSize; ++j) {
2052 currentVariableLabelPairs[j] = std::pair<IndexType, LabelType>(gm_[currentTransferableFactorIndex].variableIndex((currentIndicatorVariable.
begin() + j)->first), (currentIndicatorVariable.
begin() + j)->second);
2054 linearConstraintIndicatorVariablesLookupTable[make_pair(currentIndicatorVariable.
getLogicalOperatorType(), currentVariableLabelPairs)] = numLPVariables_;
2055 ++numTransferedFactorsLPVariables;
2066 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2067 const IndexType currentTransferableFactorIndex = transferableFactors_[i];
2070 IndicatorVariablesContainerType slackVariables;
2071 getSlackVariablesOrderFunctor.
order_ = &slackVariables;
2072 gm_[currentTransferableFactorIndex].callFunctor(getSlackVariablesOrderFunctor);
2075 for(IndicatorVariablesIteratorType iter = slackVariables.begin(); iter != slackVariables.end(); ++iter) {
2076 const IndicatorVariableType& currentSlackVariable = *iter;
2077 transferedFactorsLPVariablesIndicesLookupTable_[i][currentSlackVariable] += numLPVariables_;
2081 OPENGM_ASSERT(transferableFactors_.size() == transferedFactorsLPVariablesIndicesLookupTable_.size());
2082 OPENGM_ASSERT(numLPVariables_ == numNodesLPVariables_ + numFactorsLPVariables_ + numLinearConstraintsLPVariables_ + numTransferedFactorsLPVariables);
2085 template <
class LP_INFERENCE_TYPE>
2087 linearConstraintLPVariablesSubsequenceIndices_.resize(linearConstraintFactors_.size());
2088 if(parameter_.integerConstraintNodeVar_ || parameter_.integerConstraintFactorVar_) {
2089 for(
size_t i = 0; i < linearConstraintFactors_.size(); ++i) {
2090 const IndexType currentFactor = linearConstraintFactors_[i];
2091 const size_t numVariables = gm_[currentFactor].numberOfVariables();
2092 linearConstraintLPVariablesSubsequenceIndices_[i].resize(numVariables);
2093 for(
size_t j = 0; j < numVariables; ++j) {
2094 linearConstraintLPVariablesSubsequenceIndices_[i][j] = gm_[currentFactor].variableIndex(j);
2100 for(
size_t i = 0; i < linearConstraintFactors_.size(); ++i) {
2101 const IndexType currentFactor = linearConstraintFactors_[i];
2102 gm_[currentFactor].callFunctor(getIndicatorVariablesOrderBegin);
2103 gm_[currentFactor].callFunctor(getIndicatorVariablesOrderEnd);
2105 for(IndicatorVariablesIteratorType iter = getIndicatorVariablesOrderBegin.
indicatorVariablesOrderBegin_; iter != currentIndicatorVariablesEnd; ++iter) {
2106 linearConstraintLPVariablesSubsequenceIndices_[i].push_back(linearConstraintsLPVariablesIndicesLookupTable_[i][*iter]);
2112 template <
class LP_INFERENCE_TYPE>
2114 if(meta::Compare<AccumulationType, Minimizer>::value) {
2115 static_cast<LPInferenceType*
>(
this)->setObjective(LPInferenceType::Minimize);
2116 }
else if(meta::Compare<AccumulationType, Maximizer>::value) {
2117 static_cast<LPInferenceType*
>(
this)->setObjective(LPInferenceType::Maximize);
2119 throw RuntimeError(
"This implementation of lp inference does only support Minimizer or Maximizer accumulators");
2123 template <
class LP_INFERENCE_TYPE>
2125 if(parameter_.integerConstraintNodeVar_) {
2126 static_cast<LPInferenceType*
>(
this)->addBinaryVariables(numNodesLPVariables_);
2128 static_cast<LPInferenceType*
>(
this)->addContinuousVariables(numNodesLPVariables_, 0.0, 1.0);
2131 if(parameter_.integerConstraintFactorVar_) {
2132 static_cast<LPInferenceType*
>(
this)->addBinaryVariables(numFactorsLPVariables_);
2133 static_cast<LPInferenceType*
>(
this)->addBinaryVariables(numLinearConstraintsLPVariables_);
2134 static_cast<LPInferenceType*
>(
this)->addBinaryVariables(numTransferedFactorsLPVariables);
2136 static_cast<LPInferenceType*
>(
this)->addContinuousVariables(numFactorsLPVariables_, 0.0, 1.0);
2137 static_cast<LPInferenceType*
>(
this)->addContinuousVariables(numLinearConstraintsLPVariables_, 0.0, 1.0);
2138 static_cast<LPInferenceType*
>(
this)->addContinuousVariables(numTransferedFactorsLPVariables, 0.0, 1.0);
2142 static_cast<LPInferenceType*
>(
this)->addContinuousVariables(numSlackVariables_, 0.0, LPInferenceType::infinity());
2145 template <
class LP_INFERENCE_TYPE>
2147 std::vector<SolverValueType> objective(numNodesLPVariables_ + numFactorsLPVariables_ + numLinearConstraintsLPVariables_ + numTransferedFactorsLPVariables + numSlackVariables_, 0.0);
2150 for(
IndexType i = 0; i < unaryFactors_.size(); i++) {
2151 const IndexType factorIndex = unaryFactors_[i];
2152 const IndexType node = gm_[factorIndex].variableIndex(0);
2153 for(
LabelType j = 0; j < gm_.numberOfLabels(node); j++) {
2154 objective[nodeLPVariableIndex(node, j)] +=
static_cast<SolverValueType
>(gm_[factorIndex](&j));
2159 for(
IndexType i = 0; i < higherOrderFactors_.size(); i++) {
2160 const IndexType factorIndex = higherOrderFactors_[i];
2162 std::vector<ValueType> tempValues(gm_[factorIndex].size());
2163 gm_[factorIndex].copyValues(tempValues.begin());
2164 for(
size_t j = 0; j < tempValues.size(); ++j) {
2165 objective[factorLPVariableIndex(factorIndex, j)] +=
static_cast<SolverValueType
>(tempValues[j]);
2172 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2173 const IndexType currentTransferableFactorIndex = transferableFactors_[i];
2176 IndicatorVariablesContainerType slackVariables;
2177 getSlackVariablesOrderFunctor.
order_ = &slackVariables;
2178 gm_[currentTransferableFactorIndex].callFunctor(getSlackVariablesOrderFunctor);
2182 getSlackVariablesObjectiveCoefficientsFunctor.
coefficients_ = &coefficients;
2183 gm_[currentTransferableFactorIndex].callFunctor(getSlackVariablesObjectiveCoefficientsFunctor);
2185 OPENGM_ASSERT(coefficients.size() == slackVariables.size());
2188 for(
size_t j = 0; j < slackVariables.size(); ++j) {
2189 const IndicatorVariableType& currentSlackVariable = slackVariables[j];
2190 const ValueType currentCoefficient = coefficients[j];
2191 const SolverIndexType currentSlackVariableLPVariableIndex = transferedFactorsLPVariablesIndicesLookupTable_[i][currentSlackVariable];
2192 objective[currentSlackVariableLPVariableIndex] +=
static_cast<SolverValueType
>(currentCoefficient);
2195 static_cast<LPInferenceType*
>(
this)->setObjectiveValue(objective.begin(), objective.end());
2198 template <
class LP_INFERENCE_TYPE>
2201 for(
IndexType i = 0; i < gm_.numberOfVariables(); ++i) {
2202 addLocalPolytopeVariableConstraint(i,
true);
2206 for(
IndexType i = 0; i < higherOrderFactors_.size(); ++i) {
2207 const IndexType factorIndex = higherOrderFactors_[i];
2208 for(
IndexType j = 0; j < gm_[factorIndex].numberOfVariables(); ++j) {
2209 const IndexType node = gm_[factorIndex].variableIndex(j);
2210 for(
LabelType k = 0; k < gm_.numberOfLabels(node); k++) {
2211 addLocalPolytopeFactorConstraint(i, j, k,
true);
2219 for(
IndexType i = 0; i < linearConstraintFactors_.size(); ++i) {
2220 gm_[linearConstraintFactors_[i]].callFunctor(getIndicatorVariablesOrderBegin);
2221 gm_[linearConstraintFactors_[i]].callFunctor(getIndicatorVariablesOrderEnd);
2223 for(
size_t j = 0; j < linearConstraintNumIndicatorVariables; ++j) {
2224 const IndexType currentFactor = linearConstraintFactors_[i];
2226 const SolverIndexType currentLPVariable = linearConstraintsLPVariablesIndicesLookupTable_[i][currentIndicatorVariable];
2227 addIndicatorVariableConstraints(currentFactor, currentIndicatorVariable, currentLPVariable,
true);
2233 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2235 getIndicatorVariablesFunctor.
variables_ = ¤tIndicatorVariables;
2236 gm_[transferableFactors_[i]].callFunctor(getIndicatorVariablesFunctor);
2237 const size_t transformedFactorsNumIndicatorVariables = currentIndicatorVariables.size();
2238 for(
size_t j = 0; j < transformedFactorsNumIndicatorVariables; ++j) {
2239 const IndexType currentFactor = transferableFactors_[i];
2240 const IndicatorVariableType& currentIndicatorVariable = currentIndicatorVariables[j];
2241 const SolverIndexType currentLPVariable = transferedFactorsLPVariablesIndicesLookupTable_[i][currentIndicatorVariable];
2242 addIndicatorVariableConstraints(currentFactor, currentIndicatorVariable, currentLPVariable,
true);
2248 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2249 const IndexType currentTransferableFactorIndex = transferableFactors_[i];
2252 getLinearConstraintsFunctor.
constraints_ = &constraints;
2253 gm_[currentTransferableFactorIndex].callFunctor(getLinearConstraintsFunctor);
2254 for(
size_t j = 0; j < constraints.size(); ++j) {
2255 const LinearConstraintType& currentConstraint = constraints[j];
2257 for(
size_t k = 0; k < lpVariables.size(); ++k) {
2258 lpVariables[k] = transferedFactorsLPVariablesIndicesLookupTable_[i][currentConstraint.
indicatorVariablesBegin()[k]];
2261 case LinearConstraintType::LinearConstraintOperatorType::LessEqual : {
2262 static_cast<LPInferenceType*
>(
this)->addLessEqualConstraint(lpVariables.begin(), lpVariables.end(), currentConstraint.
coefficientsBegin(),
static_cast<const SolverValueType
>(currentConstraint.
getBound()));
2265 case LinearConstraintType::LinearConstraintOperatorType::Equal : {
2266 static_cast<LPInferenceType*
>(
this)->addEqualityConstraint(lpVariables.begin(), lpVariables.end(), currentConstraint.
coefficientsBegin(),
static_cast<const SolverValueType
>(currentConstraint.
getBound()));
2271 static_cast<LPInferenceType*
>(
this)->addGreaterEqualConstraint(lpVariables.begin(), lpVariables.end(), currentConstraint.
coefficientsBegin(),
static_cast<const SolverValueType
>(currentConstraint.
getBound()));
2278 template <
class LP_INFERENCE_TYPE>
2281 for(
IndexType i = 0; i < gm_.numberOfVariables(); ++i) {
2282 addLocalPolytopeVariableConstraint(i,
true);
2286 for(
IndexType i = 0; i < higherOrderFactors_.size(); ++i) {
2287 const IndexType factorIndex = higherOrderFactors_[i];
2288 for(
IndexType j = 0; j < gm_[factorIndex].numberOfVariables(); ++j) {
2289 const IndexType node = gm_[factorIndex].variableIndex(j);
2290 for(
LabelType k = 0; k < gm_.numberOfLabels(node); k++) {
2291 addLocalPolytopeFactorConstraint(i, j, k,
false);
2299 for(
IndexType i = 0; i < linearConstraintFactors_.size(); ++i) {
2300 gm_[linearConstraintFactors_[i]].callFunctor(getIndicatorVariablesOrderBegin);
2301 gm_[linearConstraintFactors_[i]].callFunctor(getIndicatorVariablesOrderEnd);
2303 for(
size_t j = 0; j < linearConstraintNumIndicatorVariables; ++j) {
2304 const IndexType currentFactor = linearConstraintFactors_[i];
2306 const SolverIndexType currentLPVariable = linearConstraintsLPVariablesIndicesLookupTable_[i][currentIndicatorVariable];
2307 addIndicatorVariableConstraints(currentFactor, currentIndicatorVariable, currentLPVariable,
false);
2313 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2315 getIndicatorVariablesFunctor.
variables_ = ¤tIndicatorVariables;
2316 gm_[transferableFactors_[i]].callFunctor(getIndicatorVariablesFunctor);
2317 const size_t transformedFactorsNumIndicatorVariables = currentIndicatorVariables.size();
2318 for(
size_t j = 0; j < transformedFactorsNumIndicatorVariables; ++j) {
2319 const IndexType currentFactor = transferableFactors_[i];
2320 const IndicatorVariableType& currentIndicatorVariable = currentIndicatorVariables[j];
2321 const SolverIndexType currentLPVariable = transferedFactorsLPVariablesIndicesLookupTable_[i][currentIndicatorVariable];
2322 addIndicatorVariableConstraints(currentFactor, currentIndicatorVariable, currentLPVariable,
false);
2328 for(
IndexType i = 0; i < transferableFactors_.size(); ++i) {
2329 const IndexType currentTransferableFactorIndex = transferableFactors_[i];
2332 getLinearConstraintsFunctor.
constraints_ = &constraints;
2333 gm_[currentTransferableFactorIndex].callFunctor(getLinearConstraintsFunctor);
2334 for(
size_t j = 0; j < constraints.size(); ++j) {
2335 const LinearConstraintType& currentConstraint = constraints[j];
2337 for(
size_t k = 0; k < lpVariables.size(); ++k) {
2338 lpVariables[k] = transferedFactorsLPVariablesIndicesLookupTable_[i][currentConstraint.
indicatorVariablesBegin()[k]];
2341 std::stringstream constraintName;
2342 if(parameter_.nameConstraints_) {
2343 constraintName <<
"transfered factor " << currentTransferableFactorIndex <<
" constraint " << j <<
" of " << constraints.size();
2350 constraint.
name_ = constraintName.str();
2351 inactiveConstraints_.push_back(constraint);
2356 template <
class LP_INFERENCE_TYPE>
2358 addLocalPolytopeConstraints();
2363 for(
IndexType i = 0; i < linearConstraintFactors_.size(); ++i) {
2364 const IndexType currentLinearConstraintFactorIndex = linearConstraintFactors_[i];
2365 gm_[currentLinearConstraintFactorIndex].callFunctor(getLinearConstraintsBegin);
2366 LinearConstraintsIteratorType currentLinearConstraintsBegin = getLinearConstraintsBegin.
linearConstraintsBegin_;
2367 gm_[currentLinearConstraintFactorIndex].callFunctor(getLinearConstraintsEnd);
2368 const LinearConstraintsIteratorType currentLinearConstraintsEnd = getLinearConstraintsEnd.
linearConstraintsEnd_;
2369 while(currentLinearConstraintsBegin != currentLinearConstraintsEnd) {
2370 addLinearConstraint(i, *currentLinearConstraintsBegin);
2371 ++currentLinearConstraintsBegin;
2376 template <
class LP_INFERENCE_TYPE>
2380 return nodesLPVariablesOffset_[nodeID] + label;
2383 template <
class LP_INFERENCE_TYPE>
2388 return factorsLPVariablesOffset_[factorID] + labelingIndex;
2391 template <
class LP_INFERENCE_TYPE>
2392 template<
class LABELING_ITERATOR_TYPE>
2395 OPENGM_ASSERT(static_cast<IndexType>(std::distance(labelingBegin, labelingEnd)) == gm_[factorID].numberOfVariables());
2397 const size_t numVar = gm_[factorID].numberOfVariables();
2398 size_t labelingIndex = *labelingBegin;
2400 size_t strides = gm_[factorID].numberOfLabels(0);
2401 for(
size_t i = 1; i < numVar; i++){
2402 OPENGM_ASSERT(*labelingBegin < gm_[factorID].numberOfLabels(i));
2403 labelingIndex += strides * (*labelingBegin);
2404 strides *= gm_[factorID].numberOfLabels(i);
2410 return factorLPVariableIndex(factorID, labelingIndex);
2413 template <
class LP_INFERENCE_TYPE>
2414 template <
class HIGHER_ORDER_FACTORS_MAP_TYPE,
class INDICATOR_VARIABLES_MAP_TYPE>
2416 const size_t indicatorVariableSize = std::distance(indicatorVariable.
begin(), indicatorVariable.
end());
2419 if(indicatorVariableSize == 1) {
2420 const IndexType currentNode = gm_[linearConstraintFactorIndex].variableIndex(indicatorVariable.
begin()->first);
2421 const LabelType currentLabel = indicatorVariable.
begin()->second;
2423 if(gm_.numberOfLabels(currentNode) == 2) {
2426 lpVariableIndex = nodeLPVariableIndex(currentNode, currentLabel == 0 ?
LabelType(1) :
LabelType(0));
2432 lpVariableIndex = nodeLPVariableIndex(currentNode, currentLabel);
2438 std::vector<IndexType> currentVariables(indicatorVariableSize);
2439 std::vector<LabelType> currentLabeling(indicatorVariableSize);
2440 for(
size_t i = 0; i < indicatorVariableSize; ++i) {
2441 currentVariables[i] = gm_[linearConstraintFactorIndex].variableIndex((indicatorVariable.
begin() + i)->first);
2442 currentLabeling[i] = (indicatorVariable.
begin() + i)->second;
2444 const typename HIGHER_ORDER_FACTORS_MAP_TYPE::const_iterator iter = higherOrderFactorVariablesLookupTable.find(currentVariables);
2445 if(iter != higherOrderFactorVariablesLookupTable.end()) {
2447 lpVariableIndex = factorLPVariableIndex(iter->second, currentLabeling.begin(), currentLabeling.end());
2452 std::vector<std::pair<IndexType, LabelType> > currentVariableLabelPairs(indicatorVariableSize);
2453 for(
size_t i = 0; i < indicatorVariableSize; ++i) {
2454 currentVariableLabelPairs[i] = std::pair<IndexType, LabelType>(gm_[linearConstraintFactorIndex].variableIndex((indicatorVariable.
begin() + i)->first), (indicatorVariable.
begin() + i)->second);
2456 const typename INDICATOR_VARIABLES_MAP_TYPE::const_iterator iter = indicatorVariablesLookupTable.find(make_pair(indicatorVariable.
getLogicalOperatorType(), currentVariableLabelPairs));
2457 if(iter != indicatorVariablesLookupTable.end()) {
2459 lpVariableIndex = iter->second;
2467 template <
class LP_INFERENCE_TYPE>
2470 static std::vector<SolverIndexType> variableIDs;
2471 static std::vector<SolverValueType> coefficients;
2474 const LabelType size = gm_.numberOfLabels(variableID);
2475 if(variableIDs.size() != size) {
2476 variableIDs.resize(size);
2477 coefficients.resize(size, 1.0);
2480 variableIDs[j] = nodeLPVariableIndex(variableID, j);
2483 std::stringstream constraintName;
2484 if(parameter_.nameConstraints_) {
2485 constraintName <<
"local polytope variable constraint of variable " << variableID;
2488 static_cast<LPInferenceType*
>(
this)->addEqualityConstraint(variableIDs.begin(), variableIDs.end(), coefficients.begin(), 1.0, constraintName.str());
2494 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::Equal;
2495 constraint.
name_ = constraintName.str();
2496 inactiveConstraints_.push_back(constraint);
2500 template <
class LP_INFERENCE_TYPE>
2503 OPENGM_ASSERT(variable < gm_[higherOrderFactors_[factor]].numberOfVariables());
2504 OPENGM_ASSERT(label < gm_[higherOrderFactors_[factor]].shape(variable));
2506 static std::vector<SolverIndexType> variableIDs;
2507 static std::vector<SolverValueType> coefficients;
2508 if(addLocalPolytopeFactorConstraintCachePreviousFactorID_ != higherOrderFactors_[factor]) {
2510 addLocalPolytopeFactorConstraintCachePreviousFactorID_ = higherOrderFactors_[factor];
2511 addLocalPolytopeFactorConstraintCacheFactorLPVariableIDs_.
resize(gm_[higherOrderFactors_[factor]].shapeBegin(), gm_[higherOrderFactors_[factor]].shapeEnd());
2512 SolverIndexType counter = factorLPVariableIndex(higherOrderFactors_[factor], 0);
2513 for(
typename marray::Marray<SolverIndexType>::iterator factorLPVariableIDsIter = addLocalPolytopeFactorConstraintCacheFactorLPVariableIDs_.
begin(); factorLPVariableIDsIter != addLocalPolytopeFactorConstraintCacheFactorLPVariableIDs_.
end(); ++factorLPVariableIDsIter) {
2514 *factorLPVariableIDsIter = counter++;
2519 const IndexType node = gm_[higherOrderFactors_[factor]].variableIndex(variable);
2520 const size_t size = view.
size() + 1;
2521 const size_t containerSize = variableIDs.size();
2522 if(containerSize != size) {
2523 variableIDs.resize(size);
2525 if(containerSize > 0) {
2526 coefficients[containerSize - 1] = 1.0;
2528 coefficients.resize(size, 1.0);
2529 coefficients[size - 1] = -1.0;
2531 SolverIndexType currentVariableIDsIndex = 0;
2533 variableIDs[currentVariableIDsIndex] = *viewIter;
2534 currentVariableIDsIndex++;
2536 OPENGM_ASSERT(static_cast<size_t>(currentVariableIDsIndex) == size - 1);
2537 variableIDs[size - 1] = nodeLPVariableIndex(node, label);
2539 std::stringstream constraintName;
2540 if(parameter_.nameConstraints_) {
2541 constraintName <<
"local polytope factor constraint of higher order factor " << factor <<
" variable " << variable <<
" and label " << label;
2544 static_cast<LPInferenceType*
>(
this)->addEqualityConstraint(variableIDs.begin(), variableIDs.end(), coefficients.begin(), 0.0, constraintName.str());
2550 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::Equal;
2551 constraint.
name_ = constraintName.str();
2552 inactiveConstraints_.push_back(constraint);
2556 template <
class LP_INFERENCE_TYPE>
2559 OPENGM_ASSERT(indicatorVariableLPVariable < numLPVariables_ + numSlackVariables_);
2560 if(indicatorVariableLPVariable >= numLPVariables_) {
2563 if(indicatorVariableLPVariable >= factorsLPVariablesOffset_[factor]) {
2567 const SolverIndexType numVariables =
static_cast<const SolverIndexType
>(std::distance(indicatorVariable.
begin(), indicatorVariable.
end()));
2568 if(numVariables == 1) {
2572 std::vector<SolverValueType> coefficients(2, 1.0);
2573 std::vector<SolverIndexType> lpVariableIDs(2, indicatorVariableLPVariable);
2574 lpVariableIDs[0] = nodeLPVariableIndex(gm_[factor].variableIndex(indicatorVariable.
begin()->first), indicatorVariable.
begin()->second);
2575 std::stringstream constraintName;
2576 if(parameter_.nameConstraints_) {
2577 constraintName <<
"indicator variable constraint of factor " << factor <<
"of type Not for node" << indicatorVariable.
begin()->first <<
" and label " << indicatorVariable.
begin()->second;
2580 static_cast<LPInferenceType*
>(
this)->addEqualityConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(), 1.0, constraintName.str());
2586 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::Equal;
2587 constraint.
name_ = constraintName.str();
2588 inactiveConstraints_.push_back(constraint);
2596 std::vector<SolverValueType> coefficients(2, 1.0);
2598 coefficients.back() = -1.0;
2600 std::vector<SolverIndexType> lpVariableIDs(2, indicatorVariableLPVariable);
2601 for(VariableLabelPairsIteratorType iter = indicatorVariable.
begin(); iter != indicatorVariable.
end(); ++iter) {
2602 lpVariableIDs[1] = nodeLPVariableIndex(gm_[factor].variableIndex(iter->first), iter->second);
2603 std::stringstream constraintName;
2604 if(parameter_.nameConstraints_) {
2605 constraintName <<
"indicator variable constraint of factor " << factor <<
"of type ";
2607 case IndicatorVariableType::And : {
2608 constraintName <<
"And";
2611 case IndicatorVariableType::Or : {
2612 constraintName <<
"Or";
2617 constraintName <<
"Not";
2620 constraintName <<
" for node" << iter->first <<
" and label " << iter->second;
2625 case IndicatorVariableType::And : {
2626 static_cast<LPInferenceType*
>(
this)->addLessEqualConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(), 0.0, constraintName.str());
2629 case IndicatorVariableType::Or : {
2630 static_cast<LPInferenceType*
>(
this)->addGreaterEqualConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(), 0.0, constraintName.str());
2635 static_cast<LPInferenceType*
>(
this)->addLessEqualConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(), 1.0, constraintName.str());
2643 case IndicatorVariableType::And : {
2645 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::LessEqual;
2648 case IndicatorVariableType::Or : {
2650 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::GreaterEqual;
2656 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::LessEqual;
2659 constraint.
name_ = constraintName.str();
2660 inactiveConstraints_.push_back(constraint);
2668 coefficients.back() = 1.0;
2670 coefficients.resize(numVariables + 1, 1.0);
2672 coefficients.back() = -1.0;
2674 lpVariableIDs.clear();
2675 for(VariableLabelPairsIteratorType iter = indicatorVariable.
begin(); iter != indicatorVariable.
end(); ++iter) {
2676 lpVariableIDs.push_back(nodeLPVariableIndex(gm_[factor].variableIndex(iter->first), iter->second));
2678 lpVariableIDs.push_back(indicatorVariableLPVariable);
2679 std::stringstream constraintName;
2680 if(parameter_.nameConstraints_) {
2681 constraintName <<
"indicator variable sum constraint of factor " << factor <<
"of type ";
2683 case IndicatorVariableType::And : {
2684 constraintName <<
"And";
2687 case IndicatorVariableType::Or : {
2688 constraintName <<
"Or";
2693 constraintName <<
"Not";
2696 constraintName <<
" for lp variable" << indicatorVariableLPVariable;
2700 case IndicatorVariableType::And : {
2701 static_cast<LPInferenceType*
>(
this)->addLessEqualConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(),
static_cast<const SolverValueType
>(numVariables - 1.0), constraintName.str());
2704 case IndicatorVariableType::Or : {
2705 static_cast<LPInferenceType*
>(
this)->addGreaterEqualConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(),
static_cast<const SolverValueType
>(0.0), constraintName.str());
2710 static_cast<LPInferenceType*
>(
this)->addGreaterEqualConstraint(lpVariableIDs.begin(), lpVariableIDs.end(), coefficients.begin(),
static_cast<const SolverValueType
>(1.0), constraintName.str());
2718 case IndicatorVariableType::And : {
2719 constraint.
bound_ =
static_cast<const SolverValueType
>(numVariables - 1.0);
2720 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::LessEqual;
2723 case IndicatorVariableType::Or : {
2724 constraint.
bound_ =
static_cast<const SolverValueType
>(0.0);
2725 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::GreaterEqual;
2730 constraint.
bound_ =
static_cast<const SolverValueType
>(1.0);
2731 constraint.
operator_ = LinearConstraintType::LinearConstraintOperatorType::GreaterEqual;
2734 constraint.
name_ = constraintName.str();
2735 inactiveConstraints_.push_back(constraint);
2742 template <
class LP_INFERENCE_TYPE>
2744 OPENGM_ASSERT(linearConstraintFactor < linearConstraintsLPVariablesIndicesLookupTable_.size());
2746 for(
size_t i = 0; i < lpVariables.size(); ++i) {
2747 lpVariables[i] = linearConstraintsLPVariablesIndicesLookupTable_[linearConstraintFactor][constraint.
indicatorVariablesBegin()[i]];
2750 case LinearConstraintType::LinearConstraintOperatorType::LessEqual : {
2751 static_cast<LPInferenceType*
>(
this)->addLessEqualConstraint(lpVariables.begin(), lpVariables.end(), constraint.
coefficientsBegin(),
static_cast<const SolverValueType
>(constraint.
getBound()));
2754 case LinearConstraintType::LinearConstraintOperatorType::Equal : {
2755 static_cast<LPInferenceType*
>(
this)->addEqualityConstraint(lpVariables.begin(), lpVariables.end(), constraint.
coefficientsBegin(),
static_cast<const SolverValueType
>(constraint.
getBound()));
2760 static_cast<LPInferenceType*
>(
this)->addGreaterEqualConstraint(lpVariables.begin(), lpVariables.end(), constraint.
coefficientsBegin(),
static_cast<const SolverValueType
>(constraint.
getBound()));
2765 template <
class LP_INFERENCE_TYPE>
2766 template <
class VISITOR_TYPE>
2768 switch(parameter_.relaxation_){
2769 case Parameter::LocalPolytope : {
2770 return infer_impl_selectHeuristic<VISITOR_TYPE, Parameter::LocalPolytope>(visitor);
2772 case Parameter::LoosePolytope : {
2773 return infer_impl_selectHeuristic<VISITOR_TYPE, Parameter::LoosePolytope>(visitor);
2775 case Parameter::TightPolytope: {
2776 return infer_impl_selectHeuristic<VISITOR_TYPE, Parameter::TightPolytope>(visitor);
2784 template <
class LP_INFERENCE_TYPE>
2785 template <class VISITOR_TYPE, typename LPInferenceBase<LP_INFERENCE_TYPE>::Parameter::Relaxation RELAXATION>
2787 switch(parameter_.challengeHeuristic_){
2788 case Parameter::Random : {
2789 return infer_impl_selectIterations<VISITOR_TYPE, RELAXATION, Parameter::Random>(visitor);
2791 case Parameter::Weighted : {
2792 return infer_impl_selectIterations<VISITOR_TYPE, RELAXATION, Parameter::Weighted>(visitor);
2800 template <
class LP_INFERENCE_TYPE>
2803 if(parameter_.maxNumIterations_ == 0) {
2804 return infer_impl_selectViolatedConstraints<VISITOR_TYPE, RELAXATION, HEURISTIC, true>(visitor);
2806 return infer_impl_selectViolatedConstraints<VISITOR_TYPE, RELAXATION, HEURISTIC, false>(visitor);
2810 template <
class LP_INFERENCE_TYPE>
2813 if(parameter_.maxNumConstraintsPerIter_ == 0) {
2814 return infer_impl_selectLPType<VISITOR_TYPE, RELAXATION, HEURISTIC, USE_INFINITE_ITERATIONS, true>(visitor);
2816 return infer_impl_selectLPType<VISITOR_TYPE, RELAXATION, HEURISTIC, USE_INFINITE_ITERATIONS, false>(visitor);
2820 template <
class LP_INFERENCE_TYPE>
2823 if(parameter_.integerConstraintNodeVar_ || parameter_.integerConstraintFactorVar_) {
2824 return infer_impl<VISITOR_TYPE, RELAXATION, HEURISTIC, USE_INFINITE_ITERATIONS, ADD_ALL_VIOLATED_CONSTRAINTS, true>(visitor);
2826 return infer_impl<VISITOR_TYPE, RELAXATION, HEURISTIC, USE_INFINITE_ITERATIONS, ADD_ALL_VIOLATED_CONSTRAINTS, false>(visitor);
2830 template <
class LP_INFERENCE_TYPE>
2833 if(meta::Compare<VISITOR_TYPE, TimingVisitorType>::value) {
2834 visitor.addLog(
"LP Solver Time");
2835 visitor.addLog(
"Search Violated Constraints Time");
2836 visitor.addLog(
"Add Violated Constraints Time");
2839 visitor.begin(*
this);
2840 inferenceStarted_ =
true;
2841 for(
size_t i = 0; USE_INFINITE_ITERATIONS || (i < parameter_.maxNumIterations_);) {
2843 if(meta::Compare<VISITOR_TYPE, TimingVisitorType>::value) {
2844 SolverTimingType solverTime;
2845 const bool solveSuccess =
static_cast<LPInferenceType*
>(
this)->solve(solverTime);
2850 const size_t visitorReturnFlag = visitor(*
this);
2851 visitor.log(
"LP Solver Time", solverTime);
2857 if(!static_cast<LPInferenceType*>(
this)->solve()) {
2867 if(meta::Compare<VISITOR_TYPE, TimingVisitorType>::value) {
2868 static Timer searchViolatedConstraintsTimer;
2869 searchViolatedConstraintsTimer.
reset();
2870 searchViolatedConstraintsTimer.
tic();
2871 const bool newViolatedConstraintsFound = USE_INTEGER_CONSTRAINTS ? tightenPolytope<RELAXATION, HEURISTIC, ADD_ALL_VIOLATED_CONSTRAINTS>() : tightenPolytopeRelaxed<RELAXATION, HEURISTIC, ADD_ALL_VIOLATED_CONSTRAINTS>();
2872 searchViolatedConstraintsTimer.
toc();
2873 visitor.log(
"Search Violated Constraints Time", searchViolatedConstraintsTimer.
elapsedTime());
2874 if(newViolatedConstraintsFound){
2875 SolverTimingType addConstraintsTime;
2876 static_cast<LPInferenceType*
>(
this)->addConstraintsFinished(addConstraintsTime);
2877 visitor.log(
"Add Violated Constraints Time", addConstraintsTime);
2883 if(USE_INTEGER_CONSTRAINTS ? tightenPolytope<RELAXATION, HEURISTIC, ADD_ALL_VIOLATED_CONSTRAINTS>() : tightenPolytopeRelaxed<RELAXATION, HEURISTIC, ADD_ALL_VIOLATED_CONSTRAINTS>()){
2884 static_cast<LPInferenceType*
>(
this)->addConstraintsFinished();
2890 if(!USE_INFINITE_ITERATIONS) {
2898 template <
class LP_INFERENCE_TYPE>
2901 if(RELAXATION == Parameter::TightPolytope) {
2907 static std::vector<LabelType> currentArg;
2910 if(ADD_ALL_VIOLATED_CONSTRAINTS) {
2911 bool violatedConstraintAdded =
false;
2912 if(RELAXATION == Parameter::LoosePolytope) {
2913 double currentWeight;
2914 InactiveConstraintsListIteratorType inactiveConstraintsBegin = inactiveConstraints_.begin();
2915 InactiveConstraintsListIteratorType inactiveConstraintsEnd = inactiveConstraints_.end();
2916 while(inactiveConstraintsBegin != inactiveConstraintsEnd) {
2917 checkInactiveConstraint(*inactiveConstraintsBegin, currentWeight);
2918 if(currentWeight > parameter_.tolerance_) {
2919 addInactiveConstraint(*inactiveConstraintsBegin);
2920 violatedConstraintAdded =
true;
2921 const InactiveConstraintsListIteratorType removeInactiveConstraintIterator = inactiveConstraintsBegin;
2922 ++inactiveConstraintsBegin;
2923 inactiveConstraints_.erase(removeInactiveConstraintIterator);
2926 ++inactiveConstraintsBegin;
2929 while(inactiveConstraintsBegin != inactiveConstraintsEnd) {
2930 checkInactiveConstraint(*inactiveConstraintsBegin, currentWeight);
2931 if(currentWeight > parameter_.tolerance_) {
2932 addInactiveConstraint(*inactiveConstraintsBegin);
2933 const InactiveConstraintsListIteratorType removeInactiveConstraintIterator = inactiveConstraintsBegin;
2934 ++inactiveConstraintsBegin;
2935 inactiveConstraints_.erase(removeInactiveConstraintIterator);
2937 ++inactiveConstraintsBegin;
2945 addAllViolatedLinearConstraintsFunctor.
tolerance_ = parameter_.tolerance_;
2946 addAllViolatedLinearConstraintsFunctor.
lpInference_ =
this;
2948 if(!violatedConstraintAdded) {
2949 for(; i < linearConstraintFactors_.size(); ++i) {
2950 addAllViolatedLinearConstraintsFunctor.
labelingBegin_ = IntegerSolutionSubsequenceIterator(currentArg.begin(), linearConstraintLPVariablesSubsequenceIndices_[i].begin());
2952 const IndexType currentFactor = linearConstraintFactors_[i];
2953 gm_[currentFactor].callFunctor(addAllViolatedLinearConstraintsFunctor);
2955 violatedConstraintAdded =
true;
2960 for(; i < linearConstraintFactors_.size(); ++i) {
2961 for(; i < linearConstraintFactors_.size(); ++i) {
2962 addAllViolatedLinearConstraintsFunctor.
labelingBegin_ = IntegerSolutionSubsequenceIterator(currentArg.begin(), linearConstraintLPVariablesSubsequenceIndices_[i].begin());
2964 const IndexType currentFactor = linearConstraintFactors_[i];
2965 gm_[currentFactor].callFunctor(addAllViolatedLinearConstraintsFunctor);
2968 return violatedConstraintAdded;
2970 size_t numConstraintsAdded = 0;
2971 SortedViolatedConstraintsListType sortedViolatedConstraints;
2973 if(RELAXATION == Parameter::LoosePolytope) {
2974 double currentWeight;
2975 InactiveConstraintsListIteratorType inactiveConstraintsBegin = inactiveConstraints_.begin();
2976 InactiveConstraintsListIteratorType inactiveConstraintsEnd = inactiveConstraints_.end();
2977 while(inactiveConstraintsBegin != inactiveConstraintsEnd) {
2978 checkInactiveConstraint(*inactiveConstraintsBegin, currentWeight);
2979 if(currentWeight > parameter_.tolerance_) {
2980 if(HEURISTIC == Parameter::Random) {
2981 addInactiveConstraint(*inactiveConstraintsBegin);
2982 ++numConstraintsAdded;
2983 const InactiveConstraintsListIteratorType removeInactiveConstraintIterator = inactiveConstraintsBegin;
2984 ++inactiveConstraintsBegin;
2985 inactiveConstraints_.erase(removeInactiveConstraintIterator);
2986 if(numConstraintsAdded == parameter_.maxNumConstraintsPerIter_) {
2990 sortedViolatedConstraints.insert(
typename SortedViolatedConstraintsListType::value_type(currentWeight, std::make_pair(inactiveConstraintsBegin, std::make_pair(linearConstraintFactors_.size(),
static_cast<const LinearConstraintType*
>(NULL)))));
2991 if(sortedViolatedConstraints.size() > parameter_.maxNumConstraintsPerIter_) {
2993 sortedViolatedConstraints.erase(sortedViolatedConstraints.begin());
2994 OPENGM_ASSERT(sortedViolatedConstraints.size() == parameter_.maxNumConstraintsPerIter_);
2996 ++inactiveConstraintsBegin;
2999 ++inactiveConstraintsBegin;
3006 addViolatedLinearConstraintsFunctor.
tolerance_ = parameter_.tolerance_;
3007 addViolatedLinearConstraintsFunctor.
lpInference_ =
this;
3010 for(
size_t i = 0; i < linearConstraintFactors_.size(); ++i) {
3011 addViolatedLinearConstraintsFunctor.
labelingBegin_ = IntegerSolutionSubsequenceIterator(currentArg.begin(), linearConstraintLPVariablesSubsequenceIndices_[i].begin());
3013 const IndexType currentFactor = linearConstraintFactors_[i];
3014 gm_[currentFactor].callFunctor(addViolatedLinearConstraintsFunctor);
3015 if(addViolatedLinearConstraintsFunctor.
numConstraintsAdded_ == parameter_.maxNumConstraintsPerIter_) {
3021 typename SortedViolatedConstraintsListType::reverse_iterator sortedViolatedConstraintsListRBegin = sortedViolatedConstraints.rbegin();
3022 const typename SortedViolatedConstraintsListType::reverse_iterator sortedViolatedConstraintsListREnd = sortedViolatedConstraints.rend();
3023 OPENGM_ASSERT(sortedViolatedConstraints.size() <= parameter_.maxNumConstraintsPerIter_);
3024 while(sortedViolatedConstraintsListRBegin != sortedViolatedConstraintsListREnd) {
3025 if(sortedViolatedConstraintsListRBegin->second.first == inactiveConstraints_.end()) {
3026 addLinearConstraint(sortedViolatedConstraintsListRBegin->second.second.first, *(sortedViolatedConstraintsListRBegin->second.second.second));
3028 addInactiveConstraint(*(sortedViolatedConstraintsListRBegin->second.first));
3029 inactiveConstraints_.erase(sortedViolatedConstraintsListRBegin->second.first);
3031 ++numConstraintsAdded;
3032 ++sortedViolatedConstraintsListRBegin;
3034 if(numConstraintsAdded == 0) {
3042 template <
class LP_INFERENCE_TYPE>
3045 if(RELAXATION == Parameter::TightPolytope) {
3051 SolverSolutionIteratorType relaxedArgBegin =
static_cast<const LPInferenceType*
>(
this)->solutionBegin();
3053 if(ADD_ALL_VIOLATED_CONSTRAINTS) {
3054 bool violatedConstraintAdded =
false;
3055 if(RELAXATION == Parameter::LoosePolytope) {
3056 double currentWeight;
3057 InactiveConstraintsListIteratorType inactiveConstraintsBegin = inactiveConstraints_.begin();
3058 InactiveConstraintsListIteratorType inactiveConstraintsEnd = inactiveConstraints_.end();
3059 while(inactiveConstraintsBegin != inactiveConstraintsEnd) {
3060 checkInactiveConstraint(*inactiveConstraintsBegin, currentWeight);
3061 if(currentWeight > parameter_.tolerance_) {
3062 addInactiveConstraint(*inactiveConstraintsBegin);
3063 violatedConstraintAdded =
true;
3064 const InactiveConstraintsListIteratorType removeInactiveConstraintIterator = inactiveConstraintsBegin;
3065 ++inactiveConstraintsBegin;
3066 inactiveConstraints_.erase(removeInactiveConstraintIterator);
3069 ++inactiveConstraintsBegin;
3072 while(inactiveConstraintsBegin != inactiveConstraintsEnd) {
3073 checkInactiveConstraint(*inactiveConstraintsBegin, currentWeight);
3074 if(currentWeight > parameter_.tolerance_) {
3075 addInactiveConstraint(*inactiveConstraintsBegin);
3076 const InactiveConstraintsListIteratorType removeInactiveConstraintIterator = inactiveConstraintsBegin;
3077 ++inactiveConstraintsBegin;
3078 inactiveConstraints_.erase(removeInactiveConstraintIterator);
3080 ++inactiveConstraintsBegin;
3088 addAllViolatedLinearConstraintsRelaxedFunctor.
tolerance_ = parameter_.tolerance_;
3089 addAllViolatedLinearConstraintsRelaxedFunctor.
lpInference_ =
this;
3091 if(!violatedConstraintAdded) {
3092 for(; i < linearConstraintFactors_.size(); ++i) {
3093 addAllViolatedLinearConstraintsRelaxedFunctor.
labelingBegin_ = RelaxedSolutionSubsequenceIterator(relaxedArgBegin, linearConstraintLPVariablesSubsequenceIndices_[i].begin());
3095 const IndexType currentFactor = linearConstraintFactors_[i];
3096 gm_[currentFactor].callFunctor(addAllViolatedLinearConstraintsRelaxedFunctor);
3098 violatedConstraintAdded =
true;
3103 for(; i < linearConstraintFactors_.size(); ++i) {
3104 for(; i < linearConstraintFactors_.size(); ++i) {
3105 addAllViolatedLinearConstraintsRelaxedFunctor.
labelingBegin_ = RelaxedSolutionSubsequenceIterator(relaxedArgBegin, linearConstraintLPVariablesSubsequenceIndices_[i].begin());
3107 const IndexType currentFactor = linearConstraintFactors_[i];
3108 gm_[currentFactor].callFunctor(addAllViolatedLinearConstraintsRelaxedFunctor);
3111 return violatedConstraintAdded;
3113 size_t numConstraintsAdded = 0;
3114 SortedViolatedConstraintsListType sortedViolatedConstraints;
3116 if(RELAXATION == Parameter::LoosePolytope) {
3117 double currentWeight;
3118 InactiveConstraintsListIteratorType inactiveConstraintsBegin = inactiveConstraints_.begin();
3119 InactiveConstraintsListIteratorType inactiveConstraintsEnd = inactiveConstraints_.end();
3120 while(inactiveConstraintsBegin != inactiveConstraintsEnd) {
3121 checkInactiveConstraint(*inactiveConstraintsBegin, currentWeight);
3122 if(currentWeight > parameter_.tolerance_) {
3123 if(HEURISTIC == Parameter::Random) {
3124 addInactiveConstraint(*inactiveConstraintsBegin);
3125 ++numConstraintsAdded;
3126 const InactiveConstraintsListIteratorType removeInactiveConstraintIterator = inactiveConstraintsBegin;
3127 ++inactiveConstraintsBegin;
3128 inactiveConstraints_.erase(removeInactiveConstraintIterator);
3129 if(numConstraintsAdded == parameter_.maxNumConstraintsPerIter_) {
3133 sortedViolatedConstraints.insert(
typename SortedViolatedConstraintsListType::value_type(currentWeight, std::make_pair(inactiveConstraintsBegin, std::make_pair(linearConstraintFactors_.size(),
static_cast<LinearConstraintType*
>(NULL)))));
3134 if(sortedViolatedConstraints.size() > parameter_.maxNumConstraintsPerIter_) {
3136 sortedViolatedConstraints.erase(sortedViolatedConstraints.begin());
3137 OPENGM_ASSERT(sortedViolatedConstraints.size() == parameter_.maxNumConstraintsPerIter_);
3139 ++inactiveConstraintsBegin;
3142 ++inactiveConstraintsBegin;
3149 addViolatedLinearConstraintsRelaxedFunctor.
tolerance_ = parameter_.tolerance_;
3150 addViolatedLinearConstraintsRelaxedFunctor.
lpInference_ =
this;
3153 for(
size_t i = 0; i < linearConstraintFactors_.size(); ++i) {
3154 addViolatedLinearConstraintsRelaxedFunctor.
labelingBegin_ = RelaxedSolutionSubsequenceIterator(relaxedArgBegin, linearConstraintLPVariablesSubsequenceIndices_[i].begin());
3156 const IndexType currentFactor = linearConstraintFactors_[i];
3157 gm_[currentFactor].callFunctor(addViolatedLinearConstraintsRelaxedFunctor);
3158 if(addViolatedLinearConstraintsRelaxedFunctor.
numConstraintsAdded_ == parameter_.maxNumConstraintsPerIter_) {
3164 typename SortedViolatedConstraintsListType::reverse_iterator sortedViolatedConstraintsListRBegin = sortedViolatedConstraints.rbegin();
3165 const typename SortedViolatedConstraintsListType::reverse_iterator sortedViolatedConstraintsListREnd = sortedViolatedConstraints.rend();
3166 OPENGM_ASSERT(sortedViolatedConstraints.size() <= parameter_.maxNumConstraintsPerIter_);
3167 while(sortedViolatedConstraintsListRBegin != sortedViolatedConstraintsListREnd) {
3168 if(sortedViolatedConstraintsListRBegin->second.first == inactiveConstraints_.end()) {
3169 addLinearConstraint(sortedViolatedConstraintsListRBegin->second.second.first, *(sortedViolatedConstraintsListRBegin->second.second.second));
3171 addInactiveConstraint(*(sortedViolatedConstraintsListRBegin->second.first));
3172 inactiveConstraints_.erase(sortedViolatedConstraintsListRBegin->second.first);
3174 ++numConstraintsAdded;
3175 if(numConstraintsAdded == parameter_.maxNumConstraintsPerIter_) {
3178 ++sortedViolatedConstraintsListRBegin;
3180 if(numConstraintsAdded == 0) {
3188 template <
class LP_INFERENCE_TYPE>
3190 const SolverSolutionIteratorType currentSolution =
static_cast<const LPInferenceType*
>(
this)->solutionBegin();
3192 for(
size_t i = 0; i < constraint.
variableIDs_.size(); ++i) {
3196 case LinearConstraintType::LinearConstraintOperatorType::LessEqual : {
3197 if(sum <= constraint.
bound_) {
3200 weight = sum - constraint.
bound_;
3204 case LinearConstraintType::LinearConstraintOperatorType::Equal : {
3205 if(sum == constraint.
bound_) {
3214 if(sum >= constraint.
bound_) {
3217 weight = constraint.
bound_ - sum;
3224 template <
class LP_INFERENCE_TYPE>
3227 case LinearConstraintType::LinearConstraintOperatorType::LessEqual : {
3231 case LinearConstraintType::LinearConstraintOperatorType::Equal : {
3243 template <
class LP_INFERENCE_TYPE>
3244 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3249 template <
class LP_INFERENCE_TYPE>
3250 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3252 throw RuntimeError(std::string(
"GetIndicatorVariablesOrderBeginFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3255 template <
class LP_INFERENCE_TYPE>
3256 template<
class FUNCTION_TYPE>
3261 template <
class LP_INFERENCE_TYPE>
3262 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3267 template <
class LP_INFERENCE_TYPE>
3268 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3270 throw RuntimeError(std::string(
"GetIndicatorVariablesOrderEnd: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3273 template <
class LP_INFERENCE_TYPE>
3274 template<
class FUNCTION_TYPE>
3279 template <
class LP_INFERENCE_TYPE>
3280 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3285 template <
class LP_INFERENCE_TYPE>
3286 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3288 throw RuntimeError(std::string(
"GetLinearConstraintsBeginFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3291 template <
class LP_INFERENCE_TYPE>
3292 template<
class FUNCTION_TYPE>
3297 template <
class LP_INFERENCE_TYPE>
3298 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3303 template <
class LP_INFERENCE_TYPE>
3304 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3306 throw RuntimeError(std::string(
"GetLinearConstraintsEndFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3309 template <
class LP_INFERENCE_TYPE>
3310 template<
class FUNCTION_TYPE>
3315 template <
class LP_INFERENCE_TYPE>
3316 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3321 template <
class LP_INFERENCE_TYPE>
3322 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3324 throw RuntimeError(std::string(
"AddAllViolatedLinearConstraintsFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3327 template <
class LP_INFERENCE_TYPE>
3328 template<
class FUNCTION_TYPE>
3330 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsBegin;
3331 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsEnd;
3332 typename FUNCTION_TYPE::ViolatedLinearConstraintsWeightsIteratorType violatedConstraintsWeightsBegin;
3333 function.challenge(violatedConstraintsBegin, violatedConstraintsEnd, violatedConstraintsWeightsBegin, myself.
labelingBegin_, myself.
tolerance_);
3334 if(std::distance(violatedConstraintsBegin, violatedConstraintsEnd) > 0) {
3335 while(violatedConstraintsBegin != violatedConstraintsEnd) {
3337 ++violatedConstraintsBegin;
3343 template <
class LP_INFERENCE_TYPE>
3344 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3349 template <
class LP_INFERENCE_TYPE>
3350 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3352 throw RuntimeError(std::string(
"AddAllViolatedLinearConstraintsRelaxedFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3355 template <
class LP_INFERENCE_TYPE>
3356 template<
class FUNCTION_TYPE>
3358 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsBegin;
3359 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsEnd;
3360 typename FUNCTION_TYPE::ViolatedLinearConstraintsWeightsIteratorType violatedConstraintsWeightsBegin;
3361 function.challengeRelaxed(violatedConstraintsBegin, violatedConstraintsEnd, violatedConstraintsWeightsBegin, myself.
labelingBegin_, myself.
tolerance_);
3362 if(std::distance(violatedConstraintsBegin, violatedConstraintsEnd) > 0) {
3363 while(violatedConstraintsBegin != violatedConstraintsEnd) {
3365 ++violatedConstraintsBegin;
3371 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
3372 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3377 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
3378 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3380 throw RuntimeError(std::string(
"AddViolatedLinearConstraintsFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3383 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
3384 template<
class FUNCTION_TYPE>
3386 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsBegin;
3387 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsEnd;
3388 typename FUNCTION_TYPE::ViolatedLinearConstraintsWeightsIteratorType violatedConstraintsWeightsBegin;
3389 function.challenge(violatedConstraintsBegin, violatedConstraintsEnd, violatedConstraintsWeightsBegin, myself.
labelingBegin_, myself.
tolerance_);
3390 if(std::distance(violatedConstraintsBegin, violatedConstraintsEnd) > 0) {
3391 while(violatedConstraintsBegin != violatedConstraintsEnd) {
3392 if(HEURISTIC == LP_INFERENCE_BASE_TYPE::Parameter::Random) {
3394 ++violatedConstraintsBegin;
3406 ++violatedConstraintsBegin;
3407 ++violatedConstraintsWeightsBegin;
3413 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
3414 template<
class LINEAR_CONSTRAINT_FUNCTION_TYPE>
3419 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
3420 template<
class FUNCTION_TYPE,
bool IS_LINEAR_CONSTRAINT_FUNCTION>
3422 throw RuntimeError(std::string(
"AddViolatedLinearConstraintsRelaxedFunctor: Unsupported linear constraint function type") +
typeid(FUNCTION_TYPE).
name());
3425 template <
class LP_INFERENCE_BASE_TYPE,
typename LP_INFERENCE_BASE_TYPE::Parameter::ChallengeHeuristic HEURISTIC>
3426 template<
class FUNCTION_TYPE>
3428 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsBegin;
3429 typename FUNCTION_TYPE::ViolatedLinearConstraintsIteratorType violatedConstraintsEnd;
3430 typename FUNCTION_TYPE::ViolatedLinearConstraintsWeightsIteratorType violatedConstraintsWeightsBegin;
3431 function.challengeRelaxed(violatedConstraintsBegin, violatedConstraintsEnd, violatedConstraintsWeightsBegin, myself.
labelingBegin_, myself.
tolerance_);
3432 if(std::distance(violatedConstraintsBegin, violatedConstraintsEnd) > 0) {
3433 while(violatedConstraintsBegin != violatedConstraintsEnd) {
3434 if(HEURISTIC == LP_INFERENCE_BASE_TYPE::Parameter::Random) {
3436 ++violatedConstraintsBegin;
3448 ++violatedConstraintsBegin;
3449 ++violatedConstraintsWeightsBegin;
LPInferenceBase(const GraphicalModelType &gm, const Parameter ¶meter=Parameter())
LPInferenceBase constructor.
InactiveConstraintsListType::iterator InactiveConstraintsListIteratorType
Typedef of the iterator type used to iterate over a set of LPInferenceBase::ConstraintStorage objects...
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method linearConstraintsBegin() of the underlying linear constraint funct...
Helper struct to distinguish between linear constraint functions and other function types...
LPInferenceTraitsType::SolverIndexType SolverIndexType
Typedef of the index type used by the LP/MIP solver.
Functor to call LPFunctionTransfer::getLinearConstraints() for a factor of the graphical model...
Functor used to access the method challengeRelaxed() of the underlying linear constraint function of ...
LinearConstraintsContainerType::const_iterator LinearConstraintsIteratorType
Typedef of the iterator type used to iterate over a set of linear constraints.
static void getLinearConstraintsBeginFunctor_impl(GetLinearConstraintsBeginFunctor &myself, const FUNCTION_TYPE &function)
Actual access to the method linearConstraintsBegin() of the underlying linear constraint function of ...
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method indicatorVariablesOrderBegin() of the underlying linear constraint...
IndexType linearConstraintID_
Index of the linear constraint factor.
LinearConstraintType::IndicatorVariableType IndicatorVariableType
Typedef of the indicator variable type used within linear constraints.
LPInferenceTraitsType::GraphicalModelType GraphicalModelType
Typedef of the graphical model type.
LPInferenceBase< LPInferenceType > LPInferenceBaseType
Typedef of the opengm::LPInferenceBase class with appropriate template parameter. ...
IndicatorVariablesIteratorType indicatorVariablesOrderEnd_
Storage for the iterator returned by the method indicatorVariablesOrderEnd().
LinearConstraintType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
Typedef of the iterator type used to iterate over a set of indicator variables.
Base class for Linear Programming based inference.
LocalPolytope will use a first order local polytope approximation of the marginal polytope...
InferenceTermination infer_impl_selectHeuristic(VISITOR_TYPE &visitor)
Helper function for LPInferenceBase::infer_impl to select the challenge heuristic template parameter...
std::vector< IndexType > linearConstraintFactors_
List of all linear constraint factors.
std::vector< SolverIndexType > variableIDs_
The variables of the LP/MIP model which are used in the constraint.
STL-compliant random access iterator for View and Marray.
virtual std::string name() const =0
LinearConstraintType::IndicatorVariablesContainerType IndicatorVariablesContainerType
Typedef of the container type used to store a set of indicator variables.
IndicatorVariablesContainerType * order_
Pointer to the storage for the return value of the LPFunctionTransfer::getSlackVariablesOrder() metho...
LoosePolytope will add no constraints at all. All linear constraints will be added iteratively only i...
LPInferenceTraitsType::SolverValueType SolverValueType
Typedef of the value type used by the LP/MIP solver.
TightPolytope will add all constraints of the LocalPolytope relaxation and furthermore all constraint...
IndicatorVariablesContainerType::const_iterator IndicatorVariablesIteratorType
Defines the const iterator type to iterate over the set of indicator variables.
bool useFunctionTransfer_
Use function transfer if available to generate more efficient LP/MIP models.
static void addAllViolatedLinearConstraintsFunctor_impl(AddAllViolatedLinearConstraintsFunctor &myself, const FUNCTION_TYPE &function)
Actual access to the method challenge() of the underlying linear constraint function of a graphical m...
void addLoosePolytopeConstraints()
Add all constraints to the lp model which are required by the loose polytope relaxation.
SolverIndexType numSlackVariables_
The number of slack variables for the transferable factors of the graphical model.
static void getIndicatorVariablesOrderBeginFunctor_impl(GetIndicatorVariablesOrderBeginFunctor &myself, const FUNCTION_TYPE &function)
Actual access to the method indicatorVariablesOrderBegin() of the underlying linear constraint functi...
Provides interface for liner constraint functions.
void addLinearConstraint(const IndexType linearConstraintFactor, const LinearConstraintType &constraint)
Add a new linear constraint from a linear constraint function to the lp model.
static void addViolatedLinearConstraintsRelaxedFunctor_impl(AddViolatedLinearConstraintsRelaxedFunctor< LP_INFERENCE_BASE_TYPE, HEURISTIC > &myself, const FUNCTION_TYPE &function)
Actual access to the method challengeRelaxed() of the underlying linear constraint function of a grap...
IndicatorVariableType::IteratorType VariableLabelPairsIteratorType
Defines the const iterator type to iterate over the variable label pairs of an indicator variable...
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method linearConstraintsEnd() of the underlying linear constraint functio...
static void getLinearConstraintsEndFunctor_impl(GetLinearConstraintsEndFunctor &myself, const FUNCTION_TYPE &function)
Actual access to the method linearConstraintsEnd() of the underlying linear constraint function of a ...
virtual ~LPInferenceBase()
LPInferenceBase destructor.
Helper struct to distinguish between linear constraint functions and other function types...
const GraphicalModelType & gm_
Reference to the graphical model.
Functor used to access the method linearConstraintsBegin() of the underlying linear constraint functi...
iterator end()
Get the end-iterator.
LP_INFERENCE_BASE_TYPE::RelaxedSolutionSubsequenceIterator labelingBegin_
Iterator used to iterate over the current solution.
Helper struct to distinguish between linear constraint functions and other function types...
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method indicatorVariablesOrderEnd() of the underlying linear constraint f...
std::vector< LinearConstraintType > LinearConstraintsContainerType
Typedef of the container type used to store a set of linear constraints.
bool tightenPolytope()
Search for linear constraints which are violated by the current integer solution and add them to the ...
std::vector< IndexType > higherOrderFactors_
List of all higher order factors.
void addLPVariables()
Add the number of lp variables computed by LPInferenceBase::countLPVariables to the lp model...
IteratorType begin() const
Get the iterator over the sequence of variable label pairs from the indicator variable.
std::vector< IndicatorVariableType > IndicatorVariablesContainerType
Defines the storage type for the set of indicator variables.
void addInactiveConstraint(const ConstraintStorage &constraint)
Add a linear constraint from the local polytope constraint to the LP/MIP model.
LP_INFERENCE_BASE_TYPE::ValueType tolerance_
The tolerance used for the method challenge() of the underlying linear constraint function of a graph...
Helper struct to distinguish between linear constraint functions and other function types...
static void getIndicatorVariablesOrderEndFunctor_impl(GetIndicatorVariablesOrderEndFunctor &myself, const FUNCTION_TYPE &function)
Actual access to the method indicatorVariablesOrderEnd() of the underlying linear constraint function...
SolverIndexType factorLPVariableIndex(const IndexType factorID, const size_t labelingIndex) const
Get the lp variable which corresponds to the labeling of the factor.
LP_INFERENCE_BASE_TYPE * lpInference_
Pointer pointing to the instance of opengm::LPInferenceBase to get access to the LP/MIP model...
Array-Interface to an interval of memory.
void countLPVariables()
Count the number of lp variables required to build a lp model for inference of the graphical model...
Defines the const iterator type to iterate over the subset of a sequence.
Platform-independent runtime measurements.
BoundType getBound() const
Get the bound of the linear constraint.
Functor used to access the method linearConstraintsEnd() of the underlying linear constraint function...
Helper struct to distinguish between linear constraint functions and other function types...
size_t numConstraintsAdded_
Indicator used to tell how many constraints were added to the LP/MIP model.
IteratorType end() const
Get the end iterator of the sequence of variable label pairs from the indicator variable.
visitors::TimingVisitor< LPInferenceBaseType > TimingVisitorType
Typedef of the opengm::visitors::TimingVisitor class with appropriate template parameter.
Functor to call LPFunctionTransfer::numSlackVariables() for a graphical model factor.
LPInferenceTraitsType::SolverType SolverType
Typedef of the solver type used to solve the LP or MIP which is generated from the graphical model...
SolverIndexType nodeLPVariableIndex(const IndexType nodeID, const LabelType label) const
Get the lp variable which corresponds to the variable label pair of the graphical model...
bool mergeParallelFactors_
Merge factors which are connected to the same set of variables. Might increase construction time but ...
#define OPENGM_ASSERT(expression)
visitors::VerboseVisitor< LPInferenceBaseType > VerboseVisitorType
Typedef of the opengm::visitors::VerboseVisitor class with appropriate template parameter.
SolverIndexType numTransferedFactorsLPVariables
The number of lp variables for the transferable factors of the graphical model.
virtual InferenceTermination infer()
Run inference with empty visitor.
ValueType tolerance_
Tolerance for violation of linear constraints.
std::list< ConstraintStorage > InactiveConstraintsListType
Typedef of the container type used to sore a set of LPInferenceBase::ConstraintStorage objects...
InferenceTermination infer_impl_selectLPType(VISITOR_TYPE &visitor)
Helper function for LPInferenceBase::infer_impl to select the use integer constraints template parame...
LP_INFERENCE_BASE_TYPE::IndexType linearConstraintID_
Index of the linear constraint factor.
Storage class for linear constraints representing the local polytope constraints. They are generated ...
std::vector< ValueType > SlackVariablesObjectiveCoefficientsContainerType
Defines the container type which is used to store the coefficients of the slack variables for the obj...
void setAccumulation()
Set the accumulation for the lp solver.
Relaxation
This enum defines the type of the linear programming model which is used for inference.
virtual ValueType bound() const
Get the current bound.
LPInferenceTraitsType::SolverTimingType SolverTimingType
Typedef of the type used by the LP/MIP solver to measure timings.
LPInferenceTraitsType::SolverParameterType SolverParameterType
Typedef of the parameter class used by the LP/MIP solver.
void createObjectiveFunction()
Create the objective function for the lp model.
visitors::EmptyVisitor< LPInferenceBaseType > EmptyVisitorType
Typedef of the opengm::visitors::EmptyVisitor class with appropriate template parameter.
LP_INFERENCE_TYPE LPInferenceType
Typedef of the child class which inherits from opengm::LPInferenceBase.
std::string name_
The name of the constraint.
bool tightenPolytopeRelaxed()
Search for linear constraints which are violated by the current relaxed solution and add them to the ...
iterator begin()
Get an iterator to the beginning.
size_t maxNumIterations_
Maximum number of tightening iterations (infinite if set to 0).
ChallengeHeuristic challengeHeuristic_
Heuristic on how to select violated constraints.
InactiveConstraintsListType inactiveConstraints_
Storage for all linear constraints representing the local polytope constraints. They are generated an...
Helper struct to distinguish between linear constraint functions and other function types...
static void addViolatedLinearConstraintsFunctor_impl(AddViolatedLinearConstraintsFunctor< LP_INFERENCE_BASE_TYPE, HEURISTIC > &myself, const FUNCTION_TYPE &function)
Actual access to the method challenge() of the underlying linear constraint function of a graphical m...
IndicatorVariablesIteratorType indicatorVariablesOrderBegin_
Storage for the iterator returned by the method indicatorVariablesOrderBegin().
IndicatorVariablesIteratorType indicatorVariablesBegin() const
Get the begin iterator to the set of indicator variables.
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.
LP_INFERENCE_BASE_TYPE * lpInference_
Pointer pointing to the instance of opengm::LPInferenceBase to get access to the LP/MIP model...
void addLocalPolytopeVariableConstraint(const IndexType variableID, const bool addToModel)
Add a new variable constraint to the lp model.
SolverIndexType numLinearConstraintsLPVariables_
The number of lp variables for the linear constraint factors of the graphical model.
size_t maxNumConstraintsPerIter_
Maximum number of violated constraints which are added per tightening iteration (all if set to 0)...
LPInferenceBaseType * lpInference_
Pointer pointing to the instance of opengm::LPInferenceBase to get access to the LP/MIP model...
LinearConstraintOperatorValueType getConstraintOperator() const
Get the constraint operator of the linear constraint.
Parameter()
Parameter constructor setting default value for all options.
SolverValueType bound_
The value for the right hand side of the constraint.
GraphicalModelType::IndexType IndexType
void sortFactors()
Sorts the factors of the graphical model into the lists unaryFactors_, higherOrderFactors_, linearConstraintFactors_ and transferableFactors_.
LPInferenceBaseType * lpInference_
Pointer pointing to the instance of opengm::LPInferenceBase to get access to the LP/MIP model...
size_t numConstraintsAdded_
Indicator used to tell how many constraints were added to the LP/MIP model.
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...
ValueType tolerance_
The tolerance used for the method challenge() of the underlying linear constraint function of a graph...
SolverIndexType numLPVariables_
The total number of lp variables except slack variables.
virtual ValueType value() const
Get the current value.
SubsequenceIterator< typename std::vector< LabelType >::const_iterator, typename std::vector< size_t >::const_iterator > IntegerSolutionSubsequenceIterator
Typedef of the iterator type used to iterate over a subset of the computed solution. This iterator type is used to challenge the linear constraint functions present in the model. Only used when the problem is solved as a MIP.
Relaxation relaxation_
Selected relaxation method.
View< T, isConst, A > boundView(const size_t, const size_t=0) const
Get a View where one coordinate is bound to a value.
Functor to call LPFunctionTransfer::getSlackVariablesOrder() for a factor of the graphical model...
double elapsedTime() const
void addTightPolytopeConstraints()
Add all constraints to the lp model which are required by the tight polytope relaxation.
std::vector< IndicatorVariableType > IndicatorVariablesContainerType
Defines the indicator variables container type which is used to store multiple indicator variables...
meta::GetLinearConstraintFunctionTypeList< typename GraphicalModelType::FunctionTypeList >::type LinearConstraintFunctionTypeList
Typelist of all linear constraint function types which are present in the graphical model type...
bool violatedConstraintAdded_
Indicator used to tell if at least one constraint was added to the LP/MIP model.
LPFunctionTransfer< ValueType, IndexType, LabelType > LPFunctionTransferType
Typedef of the opengm::LPFunctionTransfer class with appropriate template parameter.
InferenceTermination infer_impl_selectViolatedConstraints(VISITOR_TYPE &visitor)
Helper function for LPInferenceBase::infer_impl to select the add all violated constraints template p...
IndicatorVariablesContainerType * variables_
Pointer to the storage for the return value of the LPFunctionTransfer::getIndicatorVariables() method...
bool integerConstraintNodeVar_
Use integer constraints for node variables.
LPInferenceTraitsType::SolverSolutionIteratorType SolverSolutionIteratorType
Typedef of the iterator type used to iterate over the computed solution from the LP/MIP solver...
const size_t size() const
Get the number of data items.
bool getLPVariableIndexFromIndicatorVariable(const HIGHER_ORDER_FACTORS_MAP_TYPE &higherOrderFactorVariablesLookupTable, const INDICATOR_VARIABLES_MAP_TYPE &indicatorVariablesLookupTable, const IndicatorVariableType &indicatorVariable, const IndexType linearConstraintFactorIndex, SolverIndexType &lpVariableIndex) const
Get the index of the lp variable associated with an indicator variable.
GraphicalModelType::ValueType ValueType
LPInferenceTraits< LPInferenceType > LPInferenceTraitsType
Typedef of the opengm::LPInferenceTraits class with appropriate template parameter.
ValueType tolerance_
The tolerance used for the method challengeRelaxed() of the underlying linear constraint function of ...
ValueType constValue_
Constant value offset.
IndicatorVariablesIteratorType indicatorVariablesEnd() const
Get the end iterator to the set of indicator variables.
Combine a group of variables to a new variable.
Inference algorithm interface.
std::vector< IndexType > unaryFactors_
List of all unary factors.
void addLocalPolytopeFactorConstraint(const IndexType factor, const IndexType variable, const LabelType label, const bool addToModel)
Add a new factor constraint to the lp model.
LinearConstraintsIteratorType linearConstraintsEnd_
Storage for the iterator returned by the method linearConstraintsEnd().
Weighted will add constraints sorted by their weights. This is only meaningful if the maximum number ...
CoefficientsIteratorType coefficientsBegin() const
Get the begin iterator to the set of coefficients for the indicator variables.
CoefficientsIteratorType coefficientsEnd() const
Get the end iterator to the set of coefficients for the indicator variables.
bool integerConstraintFactorVar_
Use integer constraints for factor variables.
marray::Marray< SolverIndexType > addLocalPolytopeFactorConstraintCacheFactorLPVariableIDs_
Lookup table for the factor lp variable ids required by the LPInferenceBase::addLocalPolytopeFactorCo...
Provides implementation for class LinearConstraint.
LPInferenceTraitsType::AccumulationType AccumulationType
Typedef of the Accumulation type.
SolverIndexType numFactorsLPVariables_
The number of lp variables for the factors of the graphical model.
std::vector< std::map< const IndicatorVariableType, SolverIndexType > > transferedFactorsLPVariablesIndicesLookupTable_
Lookup table for the lp variable indices of each transferable factor.
std::multimap< double, InactiveConstraintFactorConstraintPairType > SortedViolatedConstraintsListType
Typedef of the map type used to store a set of violated constraints sorted by their weights...
Functor used to access the method indicatorVariablesOrderEnd() of the underlying linear constraint fu...
Functor used to access the method challengeRelaxed() of the underlying linear constraint function of ...
bool isTransferable_
Storage for the return value of the LPFunctionTransfer::isTransferable() method.
bool nameConstraints_
Create unique names for the linear constraints added to the model (might be helpful for debugging mod...
InferenceTermination infer_impl(VISITOR_TYPE &visitor)
The implementation of the inference method.
LP_INFERENCE_BASE_TYPE::SortedViolatedConstraintsListType * sortedViolatedConstraintsList_
Storage for the violated linear constraints sorted by their weights. Only used when LPInferenceBase::...
std::vector< SolverIndexType > nodesLPVariablesOffset_
The offsets for the indices of the lp variables for each node of the graphical model.
Functor used to access the method challenge() of the underlying linear constraint function of a graph...
Functor to call LPFunctionTransfer::getSlackVariablesObjectiveCoefficients() for a factor of the grap...
LP_INFERENCE_BASE_TYPE::IntegerSolutionSubsequenceIterator labelingBegin_
Iterator used to iterate over the current solution.
virtual InferenceTermination arg(std::vector< LabelType > &x, const size_t N=1) const
Get the current argument.
LinearConstraint< ValueType, IndexType, LabelType > LinearConstraintType
Typedef of the opengm::LinearConstraint class with appropriate template parameter. Used to represent linear constraints.
Functor to call LPFunctionTransfer::isTransferable() for a factor of the graphical model...
InferenceTermination infer_impl_selectIterations(VISITOR_TYPE &visitor)
Helper function for LPInferenceBase::infer_impl to select the use infinite iterations template parame...
IndexType addLocalPolytopeFactorConstraintCachePreviousFactorID_
Cache for the function LPInferenceBase::addLocalPolytopeFactorConstraint. It is used to store the fac...
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method challengeRelaxed() of the underlying linear constraint function of...
bool useSoftConstraints_
If constraint factors are present in the model add them as soft constraints e.g. treat them as normal...
Functor used to access the method indicatorVariablesOrderBegin() of the underlying linear constraint ...
ChallengeHeuristic
This enum defines the heuristic by which the violated constraints are added to the LP/MIP model...
const Parameter parameter_
Parameter which stores the settings for the inference.
void checkInactiveConstraint(const ConstraintStorage &constraint, double &weight) const
Check if a given linear constraint from the local polytope constraints is violated.
RelaxedSolutionSubsequenceIterator labelingBegin_
Iterator used to iterate over the current solution.
LinearConstraintType::LinearConstraintOperatorValueType operator_
The operator type used to compare the left hand side of the constraint against the right hand side (<...
void addIndicatorVariableConstraints(const IndexType factor, const IndicatorVariableType &indicatorVariable, const SolverIndexType indicatorVariableLPVariable, const bool addToModel)
Add constraints for an indicator variable to the lp model.
Provides implementation for class SubsequenceIterator.
Functor used to access the method challenge() of the underlying linear constraint function of a graph...
void fillLinearConstraintLPVariablesSubsequenceIndices()
Fill the variable LPInferenceBase::linearConstraintLPVariablesSubsequenceIndices_ with the appropriat...
SubsequenceIterator< SolverSolutionIteratorType, typename std::vector< size_t >::const_iterator > RelaxedSolutionSubsequenceIterator
Typedef of the iterator type used to iterate over a subset of the computed solution. This iterator type is used to challenge the linear constraint functions present in the model. Only used when the problem is solved as a LP.
Random will add violated constraints in a random order.
ValueType
This enum defines the operator type for the linear constraint.
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method challengeRelaxed() of the underlying linear constraint function of...
std::vector< LinearConstraintType > LinearConstraintsContainerType
Defines the linear constraints container type which is used to store multiple linear constraints...
Parameter class for opengm::LPInferenceBase.
SolverIndexType numNodesLPVariables_
The number of lp variables for the nodes of the graphical model.
void addLocalPolytopeConstraints()
Add all constraints to the lp model which are required by the local polytope relaxation.
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method challenge() of the underlying linear constraint function of a grap...
void operator()(const LINEAR_CONSTRAINT_FUNCTION_TYPE &linearConstraintFunction)
Operator used to access the method challenge() of the underlying linear constraint function of a grap...
LP_INFERENCE_BASE_TYPE::IndexType linearConstraintID_
Index of the linear constraint factor.
virtual const GraphicalModelType & graphicalModel() const
Get graphical model.
Traits class for lp inference classes.
IndexType linearConstraintID_
Index of the linear constraint factor.
Helper struct to distinguish between linear constraint functions and other function types...
LP_INFERENCE_BASE_TYPE::SortedViolatedConstraintsListType * sortedViolatedConstraintsList_
Storage for the violated linear constraints sorted by their weights. Only used when LPInferenceBase::...
InferenceTermination infer_impl_selectRelaxation(VISITOR_TYPE &visitor)
Helper function for LPInferenceBase::infer_impl to select the relaxation template parameter...
GraphicalModelType::LabelType LabelType
LP_INFERENCE_BASE_TYPE::ValueType tolerance_
The tolerance used for the method challengeRelaxed() of the underlying linear constraint function of ...
std::pair< IndexType, const LinearConstraintType * > FactorIndexConstraintPointerPairType
Typedef of the pair type used to store a pointer to a linear constraint in combination with the linea...
std::vector< IndexType > transferableFactors_
List of all transferable factors.
Functor to call LPFunctionTransfer::getIndicatorVariables() for a factor of the graphical model...
static void addAllViolatedLinearConstraintsRelaxedFunctor_impl(AddAllViolatedLinearConstraintsRelaxedFunctor &myself, const FUNCTION_TYPE &function)
Actual access to the method challengeRelaxed() of the underlying linear constraint function of a grap...
LogicalOperatorType getLogicalOperatorType() const
Get the logical operator type of the indicator variable.
bool violatedConstraintAdded_
Indicator used to tell if at least one constraint was added to the LP/MIP model.
std::vector< std::map< const IndicatorVariableType, SolverIndexType > > linearConstraintsLPVariablesIndicesLookupTable_
Lookup table for the lp variable indices of each linear constraint.
Define a linear constraint for a set of indicatorVariables.
static const size_t ContinueInf
std::vector< SolverValueType > coefficients_
The coefficients for the variables of the LP/MIP model which are used in the constraint.
bool inferenceStarted_
Tell if inference was already started.
std::vector< SolverIndexType > factorsLPVariablesOffset_
The offsets for the indices of the lp variables for each factor of the graphical model.
LinearConstraintType::VariableLabelPairsIteratorType VariableLabelPairsIteratorType
Typedef of the iterator type used to iterate over a set of varible label pairs used within an indicat...
void resize(ShapeIterator, ShapeIterator, const T &=T())
Resize (existing entries are preserved, new entries are initialized).
LinearConstraintsIteratorType linearConstraintsBegin_
Storage for the iterator returned by the method linearConstraintsBegin().
IntegerSolutionSubsequenceIterator labelingBegin_
Iterator used to iterate over the current solution.
Helper struct to distinguish between linear constraint functions and other function types...
std::pair< InactiveConstraintsListIteratorType, FactorIndexConstraintPointerPairType > InactiveConstraintFactorConstraintPairType
Typedef of the pair type used to store a pointer to an inactive constraint of the local polytope cons...
std::vector< std::vector< size_t > > linearConstraintLPVariablesSubsequenceIndices_
The indices of the subset of the solution variables which are relevant for each linear constraint...