[opengm] 37/50: add option to add all cycles of length 3 in the beginning
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Nov 1 17:14:47 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository opengm.
commit 0a9d0da7abaa294f404d4c1a147c41504d7e4d6a
Author: joergkappes <kappes at math.uni-heidelberg.de>
Date: Fri Oct 23 14:53:12 2015 +0200
add option to add all cycles of length 3 in the beginning
---
include/opengm/inference/multicut.hxx | 69 +++++++++++++++++++++++-
src/interfaces/common/caller/multicut_caller.hxx | 1 +
2 files changed, 68 insertions(+), 2 deletions(-)
diff --git a/include/opengm/inference/multicut.hxx b/include/opengm/inference/multicut.hxx
index 2b7ed47..7933d17 100644
--- a/include/opengm/inference/multicut.hxx
+++ b/include/opengm/inference/multicut.hxx
@@ -118,6 +118,7 @@ public:
bool useOldPriorityQueue_;
bool useChordalSearch_;
bool useBufferedStates_;
+ bool initializeWith3Cycles_;
/// \param numThreads number of threads that should be used (default = 0 [automatic])
/// \param cutUp value which the optima at least has (helps to cut search-tree)
@@ -128,7 +129,8 @@ public:
)
: numThreads_(numThreads), verbose_(false),verboseCPLEX_(false), cutUp_(cutUp),
timeOut_(36000000), maximalNumberOfConstraintsPerRound_(1000000),
- edgeRoundingValue_(0.00000001),MWCRounding_(NEAREST), reductionMode_(3),useOldPriorityQueue_(false), useChordalSearch_(false), useBufferedStates_(false)
+ edgeRoundingValue_(0.00000001),MWCRounding_(NEAREST), reductionMode_(3),useOldPriorityQueue_(false), useChordalSearch_(false), useBufferedStates_(false),
+ initializeWith3Cycles_(false)
{};
template<class OTHER_PARAM>
@@ -139,7 +141,8 @@ public:
: numThreads_(p.numThreads_), verbose_(p.verbose_),verboseCPLEX_(p.verboseCPLEX_), cutUp_(p.cutUp_),
timeOut_(p.timeOut_), maximalNumberOfConstraintsPerRound_(p.maximalNumberOfConstraintsPerRound_),
edgeRoundingValue_(p.edgeRoundingValue_),MWCRounding_(p.MWCRounding_), reductionMode_(p.reductionMode_),
- useOldPriorityQueue_(p.useOldPriorityQueue_), useChordalSearch_(p.useChordalSearch_)
+ useOldPriorityQueue_(p.useOldPriorityQueue_), useChordalSearch_(p.useChordalSearch_),
+ initializeWith3Cycles_(false)
{};
};
@@ -217,6 +220,7 @@ private:
size_t findOddWheelConstraints(IloRangeArray&);
size_t removeUnusedConstraints(); //TODO: implement
size_t enforceIntegerConstraints();
+ size_t add3CycleConstraints();
bool readWorkFlow(std::string);
@@ -343,6 +347,9 @@ Multicut<GM, ACC>::Multicut
obj_.setLinearCoefs(x_,obj);
model_.add(obj_);
+ if(para.initializeWith3Cycles_){
+ add3CycleConstraints();
+ }
// initialize solver
cplex_ = IloCplex(model_);
}
@@ -920,6 +927,9 @@ Multicut<GM, ACC>::Multicut
model_.add(obj_);
if(constraintCounter>0) {
model_.add(c_);
+ }
+ if(para.initializeWith3Cycles_){
+ add3CycleConstraints();
}
// initialize solver
@@ -1266,6 +1276,61 @@ size_t Multicut<GM, ACC>::findIntegerTerminalTriangleConstraints(IloRangeArray&
return constraintCounter_-tempConstrainCounter;
}
+/// Add all cycle constraints of length 3
+/// * add at most |E_I| constraints
+///
+///
+template<class GM, class ACC>
+size_t Multicut<GM, ACC>::add3CycleConstraints()
+{
+ //TODO: The search can be made faster, on should consider this later.
+ IloRangeArray constraint = IloRangeArray(env_);
+ size_t constraintCounter =0;
+ LPIndexType edge1,edge2,edge3;
+ typename EdgeMapType::const_iterator it2;
+ typename EdgeMapType::const_iterator it3;
+ typename EdgeMapType::const_iterator it4;
+ for(IndexType node1=0; node1<numberOfNodes_; ++node1){
+ for(it2=neighbours[node1].begin() ; it2 != neighbours[node1].end(); ++it2) {
+ const IndexType node2=(*it2).first;
+ edge1 = (*it2).second;
+ if(node2<=node1) continue;
+ for(it3=neighbours[node1].begin() ; it3 != neighbours[node1].end(); ++it3) {
+ const IndexType node3=(*it3).first;
+ edge2 = (*it3).second;
+ if(node3<=node1) continue;
+ if(node3<=node2) continue;
+ it4 = neighbours[node2].find(node3);
+ if(it4 != neighbours[node2].end()) {
+ edge3 = (*it4).second;
+ //found 3cycle -> add it.
+ constraint.add(IloRange(env_, 0 , 1000000000));
+ constraint[constraintCounter].setLinearCoef(x_[edge1],-1);
+ constraint[constraintCounter].setLinearCoef(x_[edge2],1);
+ constraint[constraintCounter].setLinearCoef(x_[edge3],1);
+ ++constraintCounter;
+ //
+ constraint.add(IloRange(env_, 0 , 1000000000));
+ constraint[constraintCounter].setLinearCoef(x_[edge1],1);
+ constraint[constraintCounter].setLinearCoef(x_[edge2],-1);
+ constraint[constraintCounter].setLinearCoef(x_[edge3],1);
+ ++constraintCounter;
+ //
+ constraint.add(IloRange(env_, 0 , 1000000000));
+ constraint[constraintCounter].setLinearCoef(x_[edge1],1);
+ constraint[constraintCounter].setLinearCoef(x_[edge2],1);
+ constraint[constraintCounter].setLinearCoef(x_[edge3],-1);
+ ++constraintCounter;
+ }
+ }
+ }
+ }
+ if(constraintCounter>0){
+ std::cout << "Add "<<constraintCounter<<" constraints for the initial relaxation"<<std::endl;
+ model_.add(constraint);
+ }
+ return constraintCounter;
+}
/// Find violate cycle constrains
/// * add at most |E_I| constrains
diff --git a/src/interfaces/common/caller/multicut_caller.hxx b/src/interfaces/common/caller/multicut_caller.hxx
index 4881f00..41b99f0 100644
--- a/src/interfaces/common/caller/multicut_caller.hxx
+++ b/src/interfaces/common/caller/multicut_caller.hxx
@@ -55,6 +55,7 @@ inline MultiCutCaller<IO, GM, ACC>::MultiCutCaller(IO& ioIn)
addArgument(BoolArgument(multicutParameter_.useOldPriorityQueue_, "", "useOldPQ", "use older and slower priority queue for shortest path"));
addArgument(BoolArgument(multicutParameter_.useChordalSearch_, "", "useCSP", "check for chordality during shortest path search for facet defining cycle constraints instead of post check"));
addArgument(BoolArgument(multicutParameter_.useBufferedStates_, "", "useBuffer", "buffer optimal state so far after each itteration"));
+ addArgument(BoolArgument(multicutParameter_.initializeWith3Cycles_, "", "use3Cycles", "initialize the outter polytope by taking all cycles of length 3 into account."));
}
template <class IO, class GM, class ACC>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opengm.git
More information about the debian-science-commits
mailing list