76 #ifdef OGDF_STP_EXACT_LOGGING 113 m_configFile = configfile;
115 #ifdef OGDF_STP_EXACT_LOGGING 119 m_outputLevel = outputLevel;
125 m_maxFlowModuleOption.reset(module);
130 m_addDegreeConstraints = b;
135 m_addIndegreeEdgeConstraints = b;
140 m_addGSEC2Constraints = b;
145 m_addFlowBalanceConstraints = b;
150 m_maxNrAddedCuttingPlanes = b;
155 m_shuffleTerminals = b;
160 m_backCutComputation = b;
165 m_nestedCutComputation = b;
170 m_separationStrategy = b;
175 m_saturationStrategy = b;
180 m_minCardinalityCuts = b;
184 m_primalHeuristic = b;
191 m_callPrimalHeuristic = b;
196 m_poolSizeInitFactor = b;
200 : m_configFile(nullptr)
202 #ifdef OGDF_STP_EXACT_LOGGING
206 , m_addDegreeConstraints(true)
207 , m_addIndegreeEdgeConstraints(true)
208 , m_addGSEC2Constraints(true)
209 , m_addFlowBalanceConstraints(true)
210 , m_maxNrAddedCuttingPlanes(500)
211 , m_shuffleTerminals(true)
212 , m_backCutComputation(true)
213 , m_nestedCutComputation(true)
214 , m_separationStrategy(1)
215 , m_saturationStrategy(1)
216 , m_minCardinalityCuts(true)
217 , m_callPrimalHeuristic(1)
218 , m_primalHeuristic(nullptr)
219 , m_poolSizeInitFactor(5)
246 bool relaxed =
false);
251 delete[] m_bestSolution;
252 delete[] m_terminals;
256 delete m_pWeightedGraphPH;
263 m_configfile = filename;
265 #ifdef OGDF_STP_EXACT_LOGGING 266 void setOutputLevel(
Level outputLevel)
269 this->globalLogLevel(Level::Default);
270 this->localLogMode(LogMode::Log);
271 if (outputLevel >= Level::Minor
272 && outputLevel <= Level::Force) {
273 this->localLogLevel((
Level)outputLevel);
274 this->globalMinimumLogLevel((
Level)outputLevel);
280 m_maxFlowModule = module;
286 return m_maxFlowModule;
376 return new Sub(
this);
382 return m_isSolutionEdge[m_mapToBidirectedGraph1[e]]
383 || m_isSolutionEdge[m_mapToBidirectedGraph2[e]];
390 int nNodes()
const {
return m_pGraph->numberOfNodes();}
392 int nEdges()
const {
return m_pGraph->numberOfEdges();}
449 void updateBestSolution(
double *values);
451 void updateBestSolutionByEdges(
const List<edge> &sol);
483 if (m_poolSizeMax < m_pCutPool->size())
484 m_poolSizeMax = m_pCutPool->size();
528 virtual void initializeOptimization()
override;
530 virtual void terminateOptimization()
override;
532 virtual void initializeParameters()
override;
701 #ifdef OGDF_STP_EXACT_LOGGING 702 void printCurrentSolution(
bool onlyNonZeros =
true);
708 virtual bool feasible()
override;
713 if (m_alreadySeparated == -1) {
714 m_alreadySeparated = mySeparate();
716 return m_alreadySeparated;
724 #ifdef OGDF_STP_EXACT_LOGGING 725 void printMainInfosInFeasible(
bool header =
false)
const;
730 #ifdef OGDF_STP_EXACT_LOGGING 767 return new Sub(master_,
this, rule);
787 :
abacus::
Variable(master, nullptr , false, false, coeff, lb, ub, vartype)
796 int id()
const {
return m_id;}
835 if (e != m_e1 && e != m_e2)
864 , m_coeffOut(coeffOut)
873 if (e->
target() == m_node) {
876 if (e->
source() == m_node) {
911 , m_coeffEdge(coeffEdge)
924 if (e->
target() != m_edge->source())
927 if (e->
source() == m_edge->target())
955 #ifdef OGDF_STP_EXACT_LOGGING 956 std::cout <<
"Creating new DirectedCutConstraint: " << std::endl;
963 #ifdef OGDF_STP_EXACT_LOGGING 966 std::cout <<
" marked node " << n << std::endl;
975 m_hashKey += n->index();
979 #ifdef OGDF_STP_EXACT_LOGGING 980 std::cout <<
" front cut edges:" << std::endl;
983 std::cout <<
" " << e << std::endl;
986 std::cout <<
" back cut edges:" << std::endl;
989 std::cout <<
" " << e << std::endl;
1003 return m_marked[e->
source()] && !m_marked[e->
target()];
1010 unsigned hashKey()
const override {
return m_hashKey; };
1012 bool equal(
const ConVar *cv)
const override;
1014 const char *
name()
const override {
return m_name; }
1037 template<
typename T>
1044 :
abacus::
Master(
"MinSteinerTreeDirectedCut::Master", true, false,
abacus::OptSense::Min, eps)
1045 , m_maxFlowModule(nullptr)
1046 , m_configfile(nullptr)
1047 , m_relaxed(relaxed)
1048 , m_relaxedSolValue(-1)
1051 , m_pCutPool(nullptr)
1069 #ifdef OGDF_STP_EXACT_LOGGING 1071 <<
"Master::Master(): default LP solver: " 1086 #ifdef OGDF_STP_EXACT_LOGGING 1088 <<
"Master::Master(): nTerminals=" 1097 nodeMapping[nOrig] = n;
1102 #ifdef OGDF_STP_EXACT_LOGGING 1109 #ifdef OGDF_STP_EXACT_LOGGING 1126 nodeMapping[eOrig->
target()]);
1139 #ifdef OGDF_STP_EXACT_LOGGING 1140 lout(
Level::Minor) <<
" " << eOrig <<
"[" << e1 <<
", " << e2 <<
"]" << std::flush;
1143 #ifdef OGDF_STP_EXACT_LOGGING 1159 #ifdef OGDF_STP_EXACT_LOGGING 1196 template<
typename T>
1201 bool objectiveInteger =
false;
1206 #ifdef OGDF_STP_EXACT_LOGGING 1208 <<
"Master::initializeParameters(): Error reading parameters." 1209 <<
"Using default values." << std::endl;
1212 #ifdef OGDF_STP_EXACT_LOGGING 1215 setOutputLevel(static_cast<Level>(outputLevel));
1236 #ifdef OGDF_STP_EXACT_LOGGING 1238 <<
"Master::initializeParameters(): parameters:" << std::endl
1258 <<
"\tObjective integer " << this->
objInteger() << std::endl
1264 template<
typename T>
1268 #ifdef OGDF_STP_EXACT_LOGGING 1270 <<
"Master::initializeOptimization(): Instance properties:" << std::endl
1272 <<
", " <<
m_nEdgesU <<
")" << std::endl
1273 <<
"\tNumber of terminals : " <<
m_nTerminals << std::endl
1274 <<
"\tRoot node : " <<
m_root << std::endl
1296 #ifdef OGDF_STP_EXACT_LOGGING 1297 lout(
Level::Minor) <<
"\tadding variable x_" << i <<
", edge " << e << std::endl;
1304 #ifdef OGDF_STP_EXACT_LOGGING 1305 lout(
Level::Minor) <<
"\tmuting variable x_" << i <<
", edge " << e << std::endl;
1308 variables.push(eVar);
1333 basicConstraints.
push(newCon);
1335 marked[
m_twin[e]] =
true;
1337 #ifdef OGDF_STP_EXACT_LOGGING 1338 lout(
Level::Minor) <<
"\tadding constraint " << i++ <<
" GSEC2: edge " << e << std::endl;
1366 basicConstraints.
push(newCon);
1368 #ifdef OGDF_STP_EXACT_LOGGING 1369 lout(
Level::Minor) <<
"\tadding constraint " << i++ <<
" Degree: node " << n << std::endl;
1379 basicConstraints.
push(newCon);
1381 #ifdef OGDF_STP_EXACT_LOGGING 1382 lout(
Level::Minor) <<
"\tadding constraint " << i++ <<
" Indegree: edge " << e << std::endl;
1393 basicConstraints.
push(newCon);
1395 #ifdef OGDF_STP_EXACT_LOGGING 1396 lout(
Level::Minor) <<
"\tadding constraint " << i++ <<
" Flow-Balance: node " << n << std::endl;
1414 #ifdef OGDF_STP_EXACT_LOGGING 1415 lout(
Level::Minor) <<
"Master::initializeOptimization() done." << std::endl;
1420 template<
typename T>
1432 #ifdef OGDF_STP_EXACT_LOGGING 1444 <<
"Finished optimization. Statistics:" << std::endl
1445 <<
"Solution " << std::endl
1447 <<
" rounded sol. value " << ((int)this->
primalBound()) << std::endl
1448 <<
" nr edges " << nOnesInSol << std::endl
1452 <<
"Nr subproblems " << this->
nSub() << std::endl
1453 <<
"Nr solved LPs " << this->
nLp() << std::endl
1454 <<
"nr solved LPs in root " <<
m_nIterRoot << std::endl
1460 <<
"Objective integer " << (this->
objInteger()?
"true":
"false") << std::endl
1464 <<
"Total time " << *this->
totalTime() << std::endl
1465 <<
"Total cow-time " << *this->
totalCowTime() << std::endl
1466 <<
"LP time " << *this->
lpTime() << std::endl
1467 <<
"LP solver time " << *this->
lpSolverTime() << std::endl
1474 <<
"Maximum cutpool size " << this->
m_poolSizeMax << std::endl
1477 int nDuplicates, nCollisions;
1480 <<
"Cutpool duplications " << nDuplicates << std::endl
1481 <<
"Cutpool collisions " << nCollisions << std::endl
1487 template<
typename T>
1491 double eps = this->
eps();
1492 double oneMinusEps = 1.0 -
eps;
1494 if (values[i] > oneMinusEps)
1497 if (values[i] < eps)
1504 template<
typename T>
1517 template<
typename T>
1520 , m_alreadySeparated(-1)
1534 template<
typename T>
1536 :
abacus::
Sub(master, father, branchRule)
1540 #ifdef OGDF_STP_EXACT_LOGGING 1542 << std::setw(7) << this->
id()
1543 << std::setw(7) << this->
nIter_ 1544 <<
" new subproblem, parent=" << father->
id() << std::endl;
1556 #ifdef OGDF_STP_EXACT_LOGGING 1557 template<
typename T>
1565 << std::setw(7) <<
"id" 1566 << std::setw(7) <<
"iter" 1567 << std::setw(10) <<
"lp value" 1568 << std::setw(10) <<
"gl. LB" 1569 << std::setw(10) <<
"gl. UB" 1570 << std::setw(10) <<
"nSub" 1571 << std::setw(10) <<
"nOpenSub" 1576 << std::setw(7) << this->
id()
1577 << std::setw(7) << this->
nIter_ 1579 if (this->
id() == 1)
1592 <<
"\tcurrent LP:" << std::endl;
1599 template<
typename T>
1604 double oneMinusEps = 1.0 - eps;
1606 #ifdef OGDF_STP_EXACT_LOGGING 1608 this->printMainInfosInFeasible(
true);
1611 this->printMainInfosInFeasible(
false);
1624 if (this->
id() == 1) {
1633 if (
xVal_[i] > eps &&
xVal_[i] < oneMinusEps) {
1641 #ifdef OGDF_STP_EXACT_LOGGING 1643 <<
"\tsolution is fractional -> Branching." << std::endl;
1651 #ifdef OGDF_STP_EXACT_LOGGING 1653 << std::setw(7) << this->
id()
1654 << std::setw(7) << this->
nIter_ 1655 <<
" found better integer solution with value " <<
lp_->
value();
1658 printCurrentSolution();
1670 #ifdef OGDF_STP_EXACT_LOGGING 1671 template<
typename T>
1677 double oneMinusEps = 1.0 - eps;
1678 for (
int i = 0; i <
nVar(); i++) {
1680 if (!onlyNonZeros) {
1685 else if (
xVal_[i] > oneMinusEps &&
xVal_[i] < 1+eps) {
1699 template<
typename T>
1703 #ifdef OGDF_STP_EXACT_LOGGING 1705 <<
"Sub::mySeparate(): id=" 1706 << this->
id() <<
", iter=" << this->
nIter_ << std::endl;
1710 double cardEps = eps / 100;
1711 double oneMinusEps = 1 - eps;
1720 for (
int i = 0; i < nTerminals; i++) {
1721 terminal[i] = masterTerminals[i];
1728 for (
int i = 0; i < nTerminals-1; i++) {
1731 terminal[i] = terminal[j];
1736 #ifdef OGDF_STP_EXACT_LOGGING 1739 <<
"Sub::mySeparate(): considered terminal ordering: ";
1740 for (
int i = 0; i < nTerminals; i++)
1747 capacities.
init(g, 0);
1752 capacities[e] += cardEps;
1755 #ifdef OGDF_STP_EXACT_LOGGING 1757 <<
"Sub::mySeparate(): current capacities (>0) for mincut computation:" << std::endl;
1759 if (capacities[e] >= 2*cardEps) {
1771 double cutValue = 2.0;
1773 double cutValueBack = 0.0;
1775 int nOtherNodes = 0;
1777 double uBound = 1 + nEdgesU*cardEps;
1785 int cardinalityCut, cardinalityBackcut;
1786 cardinalityCut = cardinalityBackcut = 0;
1797 #ifdef OGDF_STP_EXACT_LOGGING 1799 <<
"Sub::mySeparate(): computing minimum cut between root " << r <<
" and " << t << std::flush;
1815 cutValue = mf->
computeFlow(capacities, r, t, flow);
1816 #ifdef OGDF_STP_EXACT_LOGGING 1820 <<
" " << flowEdge <<
" : " 1821 << flow[flowEdge] <<
" / " << capacities[flowEdge] << std::endl;
1827 minSTCut.
call(g, capacities, flow, r, t);
1832 #ifdef OGDF_STP_EXACT_LOGGING 1840 cutValue -= cardEps;
1843 cutValueBack += capacities[e] - cardEps;
1849 cutValueBack += capacities[e];
1855 cardinalityCut = cardinalityBackcut = 0;
1860 cardinalityBackcut++;
1864 #ifdef OGDF_STP_EXACT_LOGGING 1866 <<
", actual cutvalue=" << cutValue;
1869 <<
", actual cutValueBack=" << cutValueBack;
1874 if (cutValue < oneMinusEps) {
1880 newConstraints.
push(newCut);
1882 #ifdef OGDF_STP_EXACT_LOGGING 1884 <<
"Sub::mySeparate(): found violated cut:" << std::endl;
1890 && cutValueBack <= oneMinusEps) {
1895 newConstraints.
push(newBackCut);
1897 #ifdef OGDF_STP_EXACT_LOGGING 1899 <<
"Sub::mySeparate(): found violated cut (backcut):" << std::endl;
1910 capacities[e] = 1.0/(double)cardinalityCut + eps;
1912 capacities[e] = 1.0 + eps;
1920 && cutValueBack <= oneMinusEps
1923 capacities[e] = 1.0/(double)cardinalityBackcut + eps;
1925 capacities[e] = 1.0 + eps;
1939 if (cutValue > oneMinusEps || r == t) {
1942 while (!modified.
empty()) {
1946 capacities[e] += cardEps;
1955 if (cutsFound > 0) {
1961 if (nAdded != cutsFound) {
1966 #ifdef OGDF_STP_EXACT_LOGGING 1968 <<
"Sub::mySeparate(): id=" 1969 << this->
id() <<
", iter=" << this->
nIter_ 1970 <<
" separated " << cutsFound <<
" directed cuts" << std::endl;
1977 template<
typename T>
1983 #ifdef OGDF_STP_EXACT_LOGGING 1985 <<
"Sub::myImprove(): id=" 1986 << this->
id() <<
", iter=" << this->
nIter_ << std::endl;
1992 #ifdef OGDF_STP_EXACT_LOGGING 1995 <<
"Sub::myImprove(): current solution:" << std::endl;
1999 <<
", edge " << e << std::endl;
2006 double currWeight, twinWeight;
2011 if (twinWeight < currWeight)
2012 currWeight = twinWeight;
2018 #ifdef OGDF_STP_EXACT_LOGGING 2021 <<
"Sub::myImprove(): edge weights:" << std::endl;
2035 #ifdef OGDF_STP_EXACT_LOGGING 2037 double tmpHeuristicSolutionValue =
2040 primalHeuristic->call(
2044 heuristicSolutionWg);
2051 *heuristicSolutionWg);
2053 #ifdef OGDF_STP_EXACT_LOGGING 2055 <<
"Sub::myImprove(): primal heuristic algorithm returned solution with " 2056 <<
"value " << tmpHeuristicSolutionValue <<
", isSteinerTree=" << isSteinerTree << std::endl;
2059 if (isSteinerTree) {
2061 double heuristicSolutionValue = 0.0;
2065 for (
edge e : heuristicSolutionWg->
edges) {
2069 #ifdef OGDF_STP_EXACT_LOGGING 2075 #ifdef OGDF_STP_EXACT_LOGGING 2077 <<
"Sub::myImprove(): found integer solution with value " 2078 << heuristicSolutionValue << std::endl;
2081 #ifdef OGDF_STP_EXACT_LOGGING 2083 << std::setw(7) << this->
id()
2084 << std::setw(7) << this->
nIter_ 2085 <<
" primal heuristic founds better integer solution with value " << heuristicSolutionValue << std::endl;
2091 #ifdef OGDF_STP_EXACT_LOGGING 2094 <<
"Sub::myImprove(): id=" 2095 << this->
id() <<
", iter=" << this->
nIter_ 2096 <<
": computed solution is no Steiner tree!" << std::endl;
2100 delete heuristicSolutionWg;
2104 #ifdef OGDF_STP_EXACT_LOGGING 2105 template<
typename T>
2113 for (
int i = 0; i <
nVar(); i++) {
2115 val = constraint->
coeff(var);
2116 if (val > eps || val < -eps) {
2118 if (val > 1-eps && val < 1+eps) {
2128 if (val < -1+eps && val > -1-eps) {
2146 <<
" " << *(constraint->
sense()) <<
" " 2147 << constraint->
rhs() << std::endl;
2151 template<
typename T>
2155 if (m_hashKey != cv->hashKey()) {
2161 for (
node n : m_pGraph->nodes) {
2162 if (m_marked[n] != dirCut->
marked(n)) {
2170 template<
typename T>
2175 if (this->cutedge(edgeVar->
theEdge())) {
2182 template<
typename T>
2185 Master stpMaster(G, terminals, isTerminal,
m_eps);
2189 #ifdef OGDF_STP_EXACT_LOGGING 2190 stpMaster.setOutputLevel(m_outputLevel);
2220 const node vO = e->source();
2221 node vC = finalSteinerTree->
copy(vO);
2223 vC = finalSteinerTree->
newNode(vO);
2225 const node wO = e->target();
2226 node wC = finalSteinerTree->
copy(wO);
2228 wC = finalSteinerTree->
newNode(wO);
2230 T edgeCost = G.
weight(e);
2231 finalSteinerTree->
newEdge(e, edgeCost);
EdgeArray< edge > m_mapToOrigGraph
the undirected edge in the original graph for each arc in m_pGraph
static const char * ENUMSTRAT_[]
Literal values for the enumerators of the corresponding enumeration type.
node target() const
Returns the target node of the edge.
const ogdf::StopwatchCPU * lpSolverTime() const
Return a pointer to the timer measuring the cpu time required by the LP solver.
CSense * sense()
Returns a pointer to the sense of the constraint.
bool marked(node n) const
returns status of node n
const ogdf::StopwatchWallClock * totalCowTime() const
Returns a pointer to the timer measuring the total wall clock time.
double primalBound() const
Returns the value of the primal bound.
node theNode() const
the associated node
node m_root
the virtual root of our graph. This node is a terminal.
void useIndegreeEdgeConstraints(bool b)
Switch usage of indegree edge constraints (indeg(v) >= outgoing edge(v,x) for all x) on or off...
bool betterPrimal(double x) const
Can be used to check if a value is better than the best know primal bound.
const char * name() const override
return the name of the cut; required method for nonduplpool
void setPoolSizeInitFactor(int b)
Set factor for the initial size of the cutting pool.
void setSeparationStrategy(int b)
Set separation strategy for nested cuts.
void useNestedCuts(bool b)
Switch computation of nested cuts on or off.
const EdgeWeightedGraph< T > & m_wG
the original weighted graph
bool m_addDegreeConstraints
std::unique_ptr< MaxFlowModule< double > > m_maxFlowModuleOption
virtual Sub * generateSon(abacus::BranchRule *rule) override
generates a b&b node
void useNestedCuts(bool b)
Switch computation of nested cuts on or off.
DegreeEdgeConstraint(abacus::Master *master, edge e, double coeffIn, double coeffEdge, abacus::CSense::SENSE sense, double rhs)
EdgeArray< edge > m_edgesWgToGPH
edge mapping m_pWeightedGraphPH -> m_pGraph
bool isTerminal(node n) const
true if n is a terminal
void setEpsilonTest(EpsilonTest *et)
Assigns a new epsilon test.
int nEdges() const
returns the number of edges
bool m_minCardinalityCuts
void useEpsilonTest(const double &eps)
Change the used EpsilonTest from StandardEpsilonTest to a user given EpsilonTest. ...
node m_node
the associated node
void setConfigFile(const char *configfile)
Set a configuration file to use. The contents of the configuration file can override all other used o...
const EdgeArray< int > & edgeIDs() const
lp variable ids of edges
edge m_e2
twin of m_e1, i.e., if m_e1 = (u,v) it holds m_e2 = (v,u)
const NodeArray< bool > isTerminal() const
boolean array of terminal status
bool isBackCutEdge(const edge e) const
Returns whether this edge is entering the back cut.
EdgeArray< double > m_capacities
edge costs
std::ostream & lout(Level level=Level::Default) const
stream for logging-output (local)
void updateBestSolutionByEdges(const List< edge > &sol)
updates best found solution by list of edges
The master of the optimization.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
double eps() const
Returns the zero tolerance.
This class implements the Directed Cut Integer Linear Program for the Steiner tree problem...
int m_poolSizeMax
maximal size of the pool
Class for directed cuts (i.e., separated Steiner cuts)
bool frontCutIsComplementOfBackCut() const
Returns whether the front cut is the complement of the backcut.
bool m_addFlowBalanceConstraints
parameter: add flow balance constraints for Steiner nodes n: outdeg(n) >= indeg(n) ...
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
node rootNode() const
the designated root node (special terminal)
void init()
Reinitializes the array. Associates the array with no graph.
bool active(node n) const
returns true iff the node n is separated by this cut
int m_maxNrAddedCuttingPlanes
iterator pushBack(const E &x)
Adds element x at the end of the list.
bool m_backCutComputation
Data type for general directed graphs (adjacency list representation).
int m_factor
factor for edge coefficients in the constraint
void useBackCuts(bool b)
Switch computation of back-cuts on or off.
virtual void initializePools(ArrayBuffer< Constraint *> &constraints, ArrayBuffer< Variable *> &variables, int varPoolSize, int cutPoolSize, bool dynamicCutPool=false)
Sets up the default pools for variables, constraints, and cutting planes.
MinSteinerTreeModule< double > * m_primalHeuristic
int maxPoolSize() const
the maximum pool size during the algorithm
virtual double rhs() const
Returns the right hand side of the constraint.
void incNrCutsTotal(int val)
increases the number of separated directed cuts
EdgeArray< EdgeVariable * > m_edgeToVar
edge -> lp variable
const char * m_name
name of the cut; required method for nonduplpool
static bool isSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const EdgeWeightedGraphCopy< T > &steinerTree)
Checks in O(n) time if a given tree is acually a Steiner Tree.
int nSub() const
returns the number of generated subproblems.
void init()
Reinitializes the array. Associates the array with no graph.
void setMaxFlowModule(MaxFlowModule< double > *module)
Set the maximum flow module to be used for separation.
edge getEdge(int i) const
id -> edge
void setMaxNumberAddedCuttingPlanes(int b)
Set maximum number of added cutting planes per iteration.
BRANCHINGSTRAT branchingStrategy() const
Returns the branching strategy.
int saturationStrategy() const
strategy for saturating edges during separation; Only relevant for nested cuts
bool m_nestedCutComputation
parameter: compute nested cuts yes/no i.e., saturate all cut edges and recompute the mincut ...
int randomNumber(int low, int high)
Returns random integer between low and high (including).
void useFlowBalanceConstraints(bool b)
Switch usage of flow balance constraints on or off.
bool computeBackCuts() const
parameter: back cut computation
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
virtual void init(const Graph &graph, EdgeArray< T > *flow=nullptr)
Initialize the problem with a graph and optional flow array. If no flow array is given, a new ("internal") array will be created. If a flow array is given, the algorithm uses this "external" array.
int degree() const
Returns the degree of the node (indegree + outdegree).
edge newEdge(node u, node v, T weight)
edge twin(edge e) const
the twin edge, i.e. twin[(u,v)] = (v,u)
void useIndegreeEdgeConstraints(bool b)
Switch usage of indegree edge constraints (indeg(v) >= outgoing edge(v,x) for all x) on or off...
iterator begin()
Returns an iterator to the first element of the list.
bool m_addIndegreeEdgeConstraints
add constraints concerning the indegree of a node w.r.t. one outgoing edge: indeg(v) >= outgoing edge...
int findParameter(const char *name, unsigned nFeasible, const int *feasible) const
Searches for parameter name in the parameter table.
void useGSEC2Constraints(bool b)
Switch usage of constraints x_uv + x_vu <= 1 on or off.
edge m_edge
the associated edge
void setWeight(const edge e, T weight)
DirectedCutConstraint(abacus::Master *master, const Graph &g, const MinSTCutMaxFlow< double > *minSTCut, MinSTCutMaxFlow< double >::cutType _cutType)
Min-st-cut algorithm, that calculates the cut via maxflow.
const NodeArray< bool > & isTerminalPH() const
terminal yes/no (in m_pWeightedGraphPH)
static const char * OSISOLVER_[]
Array for the literal values for possible Osi solvers.
unsigned int m_hashKey
hashkey of the cut; required method for nonduplpool
void useTerminalShuffle(bool b)
Switch terminal shuffling before separation on or off.
OSISOLVER defaultLpSolver() const
returns the Lp Solver.
void push(E e)
Puts a new element in the buffer.
void setSaturationStrategy(int b)
Set saturation strategy for nested cuts.
int getParameter(const char *name, int ¶m) const
Searches for parameter name in the parameter table and returns its value in param.
StopwatchWallClock m_timerMinSTCut
timer for minimum st-cut computations. Measures updates + algorithm
bool shuffleTerminals() const
shuffle ordering of terminals before each separation routine
bool isSolutionEdge(edge e) const
returns true iff original edge is contained in optimum solution
bool minCardinalityCuts() const
parameter: compute minimum cardinality cuts
A variable having value 0 or 1.
DegreeConstraint(abacus::Master *master, node n, double coeffIn, double coeffOut, abacus::CSense::SENSE sense, double rhs)
Implementation of the 2(1-1/l)-approximation algorithm for the minimum Steiner tree problem by Matsuy...
double solutionValue() const
solution value after solving the problem, i.e., returns final primal bound
Master problem of Steiner tree branch&cut algorithm
void useDegreeConstraints(bool b)
Switch usage of degree constraints (like indeg <= 1) on or off.
void stop()
Stops the stopwatch and adds the difference between the current time and the starting time to the tot...
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Extends the GraphCopy concept to weighted graphs.
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
int m_nrCutsTotal
total number of separated directed cuts
Variable for directed edges.
int m_maxNrAddedCuttingPlanes
parameter: maximum nr of cutting planes per iteration
double uBound(int i) const
Can be used to access the upper of an active variable of the subproblem.
const Graph * m_pGraph
the graph
Representation of levels in hierarchies.
void setSaturationStrategy(int b)
Set saturation strategy for nested cuts.
void useMinCardinalityCuts(bool b)
Switch usage of the cardinality heuristic (minimum-cardinality cuts) on or off.
int poolSizeInit() const
initial pool size
node source() const
source node
T computeFlow(EdgeArray< T > &cap, node &s, node &t, EdgeArray< T > &flow)
Only a shortcut for computeValue and computeFlowAfterValue.
cutType
The three types of cuts.
edge edgeWgToGPH(edge e) const
edge mapping m_pWeightedGraphPH -> m_pGraph
bool cutedge(edge e) const
returns true iff the edge is contained in the cut
const node * terminals() const
terminals in an array
double m_coeffOut
coefficient of outgoing edges
EdgeArray< bool > m_isSolutionEdge
const char * m_configfile
problem dependent config file
int m_maxPoolSize
statistic number of cuts in pool
node * m_terminals
terminal index -> terminal node
node rootNodePH() const
root node (in m_pWeightedGraphPH)
void useBackCuts(bool b)
Switch computation of back-cuts on or off.
virtual int separate() override
calls mySeparate() if mySeparate wasn't called in another procedure
bool objInteger() const
If true then we assume that all feasible solutions have integral objective function values...
int mySeparate()
separation procedure
edge m_e1
base edge and twin of m_e2, i.e., if m_e1 = (u,v) it holds m_e2 = (v,u)
double * m_bestSolution
best found solution
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Computes the actual Steiner tree.
bool valid() const
Returns true iff the iterator points to an element.
OpenSub * openSub() const
Returns a pointer to the set of open subproblems.
EdgeArray< edge > m_mapToBidirectedGraph1
the first directed arc in m_pGraph for an original edge
int number() const
Returns the current number of open subproblems contained in this set.
int nodeID(node n) const
npde -> id of lp variable
void setPrimalHeuristicCallStrategy(int b)
Set primal heuristic call strategy.
T weight(const edge e) const
Level localLogLevel() const
gives the local log-level
bool m_relaxed
parameter: indicates whether we solve the relaxed problem (LP) or the ILP
void setMaxNumberAddedCuttingPlanes(int b)
Set maximum number of added cutting planes per iteration.
int m_alreadySeparated
nr of already separated cuts, default is -1
int nEdgesU() const
returns number of undirected edges, i.e., nEdges()/2
EdgeVariable * getVar(edge e) const
returns the variable assigned to edge e
std::unique_ptr< MinSteinerTreeModule< double > > & getPrimalHeuristic()
the primal heuristic module
NodeArray< int > m_nodeIDs
node -> id
bool m_addGSEC2Constraints
parameter: add GSEC2 constraints yes/no, i.e. x_uv + x_vu <= 1
void setPrimalHeuristicCallStrategy(int b)
Set primal heuristic call strategy.
virtual ~Sub()
The destructor only deletes the sons of the node.
Forms the virtual base class for all possible constraints given in pool format.
void setRelaxedSolValue(double val)
solution value of the root
bool isInFrontCut(const node v) const
Returns whether this node is part of the front cut.
edge newEdge(node v, node w, T weight)
STATUS optimize()
Performs the optimization by branch-and-bound.
void createEmpty(const Graph &wG)
double lowerBound() const
Returns the value of the global lower bound.
double * bestSolution() const
the best found solution
int id() const
Returns the identity number of the subproblem.
bool m_backCutComputation
parameter: compute back cuts yes/no i.e., outgoing edges of the root-set
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int m_separationStrategy
parameter: separation strategy, only important if nested cuts are computed
int numberOfEdges() const
Returns the number of edges in the graph.
double dualBound() const
Returns the value of the dual bound.
int level() const
Returns the level of the subproblem in the branch-and-bound tree.
bool m_minCardinalityCuts
parameter: compute minimum cardinality cuts
StopwatchWallClock m_separationTimer
timer for separation
NodeArray< bool > m_isTerminalPH
is terminal yes/no (in m_pWeightedGraphPH)
bool relaxed() const
solve relaxed LP or ILP
void setPrimalHeuristic(MinSteinerTreeModule< double > *b)
Set the module option for the primal heuristic (use MinSteinerTreeModule<double> types). Default: MinSteinerTreeModuleTakahashi.
int m_poolSizeInit
size of initial pool
void useTerminalShuffle(bool b)
Switch terminal shuffling before separation on or off.
Constraint for relating the indegree and one outgoing edge of a node.
virtual int addCons(ArrayBuffer< Constraint *> &constraints, Pool< Constraint, Variable > *pool=nullptr, ArrayBuffer< bool > *keepInPool=nullptr, ArrayBuffer< double > *rank=nullptr)
Tries to add new constraints to the constraint buffer and a pool.
abacus::NonDuplPool< abacus::Constraint, abacus::Variable > * cutPool()
the non-duplicate cutpool for the separated Steiner cuts
void myImprove()
primal heuristic procedure
EdgeArray< edge > m_edgesGToWgPH
edge mapping m_pGraph -> m_pWeightedGraphPH
bool computeNestedCuts() const
parameter: nested cut computation
void start(bool reset=false)
Starts the stopwatch.
edge firstEdge() const
Returns the first edge in the list of all edges.
virtual bool feasible() override
checks if the current solution is feasible, i.e., calls mySeparate()
Contains logging functionality.
double m_coeffEdge
coefficient of the edge
double m_coeffIn
coefficient of ingoing edges
int m_maxNrCuttingPlanes
maximum nr of cutting planes to be added
void setMaxFlowModule(MaxFlowModule< double > *module)
Set the maximum flow module to be used for separation.
EdgeVariable(abacus::Master *master, int id, edge e, double coeff, double lb=0.0, double ub=1.0, abacus::VarType::TYPE vartype=abacus::VarType::Binary)
bool feasibleFound() const
We use this function, e.g., to adapt the enumeration strategy in the DiveAndBest-Strategy.
double capacities(edge e) const
costs for edge e
EdgeArray< edge > m_mapToBidirectedGraph2
the second directed arc in m_pGraph for an original edge
Doubly linked lists (maintaining the length of the list).
int m_poolSizeInitFactor
parameter: factor for the initial size of the cutting pool
node terminal(int i) const
get terminal with index i
double m_coeffIn
coefficient of ingoing edges
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
virtual double value() const override
Returns the objective function value of the linear program.
int nrCutsTotal() const
total number of separated directed cuts
NodeArray< node > m_nodesGToWgPH
node mapping m_pGraph -> m_pWeightedGraphPH
bool m_minCardinalityCuts
int m_nMarkedNodes
number of marked nodes
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing...
MaxFlowModule< double > * getMaxFlowModule()
Get the maximum flow module used by separation algorithm.
bool m_addGSEC2Constraints
node target() const
target node
StopwatchWallClock * timerMinSTCut()
timer for minimum st-cut computations. Measures updates + algorithm
const EdgeArray< double > & capacities() const
edge costs
EdgeArray< int > m_edgeIDs
edge -> id
int id() const
id of the edge (variable)
virtual void initializeParameters() override
read/set parameters from file
static std::ostream & ilout(Level level=Level::Default)
Class for the representation of edges.
std::unique_ptr< MinSteinerTreeModule< double > > m_primalHeuristic
Algorithm used for the primal heuristic.
E popFrontRet()
Removes the first element from the list and returns it.
Declaration of class EdgeWeightedGraph.
int nMarkedNodes() const
the number of marked nodes
void useFlowBalanceConstraints(bool b)
Switch usage of flow balance constraints on or off.
void statistics(int &nDuplications, int &nCollisions) const
Returns some statistic information in nDuplicates and nCollisions.
Abstract base class for all branching rules.
double * xVal_
The last LP-solution.
const List< node > & terminalListPH() const
list of terminals (in m_pWeightedGraphPH)
EdgeConstraint(abacus::Master *master, edge e1, edge e2, int factor=1.0, abacus::CSense::SENSE sense=abacus::CSense::Less, double rhs=1.0)
Class for the representation of nodes.
int separationStrategy() const
strategy for separating directed Steiner cuts; Only relevant for nested cuts
Implements a stopwatch measuring wall-clock time.
int callPrimalHeuristicStrategy() const
strategy for calling primal heuristic (PH)
Encapsulates a pointer to a list element.
virtual bool call(const Graph &graph, const EdgeArray< TCost > &weight, node s, node t, List< edge > &edgeList, edge e_st=nullptr) override
The actual algorithm call.
const ogdf::StopwatchCPU * totalTime() const
returns a pointer to the timer measuring the total cpu time for the optimization. ...
void setPoolSizeInitFactor(int b)
Set factor for the initial size of the cutting pool.
const ogdf::StopwatchCPU * lpTime() const
Returns a pointer to the timer measuring the cpu time spent in members of the LP-interface.
List< node > m_terminalListPH
list of terminal nodes (in m_pWeightedGraphPH)
NodeArray< bool > m_isTerminal
node is terminal yes/no
virtual ~Master()
destructor
double m_relaxedSolValue
statistics: solution value of the relaxed master problem
void useMinCardinalityCuts(bool b)
Switch usage of the cardinality heuristic (minimum-cardinality cuts) on or off.
Forms the virtual base class for all possible variables given in pool format.
bool callPrimalHeuristic() const
parameter: call primal heuristic yes/no
Graph * m_pGraph
the bidirected graph
virtual void initializeOptimization() override
insert variables and base constraints
bool isFrontCutEdge(const edge e) const
Returns whether this edge is leaving the front cut.
bool equal(const ConVar *cv) const override
tests if cuts are equal; required method for nonduplpool
const Graph & original() const
Returns a reference to the original graph.
int nVar() const
Returns the number of active variables.
bool m_addIndegreeEdgeConstraints
bool m_addDegreeConstraints
parameter: add constraints concerning the indegree of a node, like: indeg <= 1 for all vertices ...
double coeff(const abacus::Variable *v) const override
Returns the coefficient of the variable v in the constraint.
NodeArray< bool > m_marked
defines if a vertex is on the left side of the cut (false) or not
const char * m_configFile
node getNode(int i) const
id -> node
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
void useDegreeConstraints(bool b)
Switch usage of degree constraints (like indeg <= 1) on or off.
double upperBound() const
Returns the value of the global upper bound.
BranchRule * branchRule() const
Returns a pointer to the branching rule of the subproblem.
double coefficient() const
objective function coefficient
int nTerminals() const
number of terminals
void incNrCutsTotal()
increases the number of separated directed cuts by 1
OSISOLVER
This enumeration defines which solvers can be used to solve the LP-relaxations.
int m_nTerminals
nr of terminals
Sub(abacus::Master *master)
Constructor for the root problem of the b&b tree.
int nNodes() const
number of nodes of the graph
virtual void terminateOptimization() override
store solution in EdgeArray
EdgeVariable * getVarTwin(edge e) const
returns the variable assigned to the twin of edge e
int maxNrAddedCuttingPlanes() const
maximum nr of cutting planes
Includes declaration of graph class.
STATUS status() const
Returns the status of the Master.
Constraint for nodes, e.g., in/outdegree stuff.
bool is_lout(Level level=Level::Default) const
returns true if such an lout command will result in text being printed
bool isSelfLoop() const
Returns true iff the edge is a self-loop (source node = target node).
bool m_addFlowBalanceConstraints
Centralized global and local logging facility working on streams like std::cout.
Level
supported log-levels from lowest to highest importance
EdgeWeightedGraph< double > & weightedGraphPH()
Subproblem of Steiner tree algorithm.
TYPE
The enumeration with the different variable types.
double coeff(const abacus::Variable *v) const override
coefficient of variable in constraint
StopwatchWallClock m_primalHeuristicTimer
timer for primal heuristics
edge edgeGToWgPH(edge e) const
edge mapping m_pGraph -> m_pWeightedGraphPH
node m_rootPH
root node in m_pWeightedGraphPH
void setSeparationStrategy(int b)
Set separation strategy for nested cuts.
StopwatchWallClock * primalHeuristicTimer()
timer for primal heuristics
int size() const
Returns the number of elements in the list.
node * nodes() const
nodes of the graph
int nLp() const
Returns the number of optimized linear programs (only LP-relaxations).
bool isParallelDirected(edge e) const
Returns true iff edge e is parallel to this (directed) edge (or if it is the same edge) ...
StopwatchWallClock * separationTimer()
timer for separation
void readParameters(const string &fileName)
Opens the parameter file fileName, reads all parameters, and inserts them in the parameter table...
static const char * STATUS_[]
Literal values for the enumerators of the corresponding enumeration type.
const EdgeArray< edge > & twins() const
Constraint * constraint(int i) const
Returns a pointer to the i-th active constraint.
node source() const
Returns the source node of the edge.
Master(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, const NodeArray< bool > &isTerminal, double eps, bool relaxed=false)
Constructor of the master problem.
int m_nIterRoot
statistics: nr of iterations in the root node of the b&b tree
bool isInBackCut(const node v) const
Returns whether this node is part of the back cut.
virtual double coeff(const Variable *v) const =0
Returns the coefficient of the variable v in the constraint.
void setPrimalHeuristic(MinSteinerTreeModule< double > *pMinSteinerTreeModule)
Set the module option for the primal heuristic.
Master * master_
A pointer to the corresponding master of the optimization.
abacus::NonDuplPool< abacus::Constraint, abacus::Variable > * m_pCutPool
the non-duplicate cut pool for the directed Steiner cuts
The namespace for all OGDF objects.
bool m_nestedCutComputation
double coeff(const abacus::Variable *v) const override
coefficient of variable in constraint
MaxFlowModule< double > * m_maxFlowModule
bool m_shuffleTerminals
parameter: shuffle the list of terminals right before separation
static const char * BRANCHINGSTRAT_[]
Literal values for the enumerators of the corresponding enumeration type.
EdgeArray< edge > m_twin
the twin edges (u,v) <-> (v,u)
edge theEdge() const
the associated edge
virtual abacus::Sub * firstSub() override
generates the first subproblem
int numberOfNodes() const
Returns the number of nodes in the graph.
Variable * variable(int i) const
Returns a pointer to the i-th active variable.
node newNode()
Creates a new node and returns it.
ENUMSTRAT enumerationStrategy() const
Returns the enumeration strategy.
LpSub * lp_
A pointer to the corresponding linear program.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
void updateBestSolution(double *values)
updates best found solution
const Sub * father() const
Returns a pointer to the father of the subproblem in the branch-and-bound tree.
void setConfigFile(const char *filename)
Set the config file to use that overrides all other settings.
void setNIterRoot(int val)
nr of iterations in the root node
int nIter_
The number of iterations in the cutting plane phase.
int m_callPrimalHeuristic
int m_callPrimalHeuristic
Strategy for primal heuristic (PH) calls.
edge theEdge() const
the associated edge
unsigned hashKey() const override
retuns an hashkey for the cut; required method for nonduplpool
int m_nEdgesU
number of undirected edges
int edgeID(edge e) const
edge -> id of lp variable
bool empty() const
Returns true iff the list is empty.
Computes a max flow via Preflow-Push (global relabeling and gap relabeling heuristic).
const NodeArray< int > & nodeIDs() const
lp variable ids of nodes
void checkSetMaxPoolSize()
checks if current pool size is maximum and sets it if necessary
void setEpsilon(double eps)
Set the epsilon for the LP.
MinSteinerTreeDirectedCut()
const Graph & graph() const
the directed graph, i.e., the bidirection of the input graph
virtual double coeff(const abacus::Variable *v) const override
coefficient of variable in constraint
Master * master()
Returns the master of the optimization.
void useGSEC2Constraints(bool b)
Switch usage of constraints x_uv + x_vu <= 1 on or off.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Master * m_pMaster
the master problem of the b&c algorithm
EdgeWeightedGraph< double > * m_pWeightedGraphPH
edge weighted bidirected graph; used and modified for primal heuristics
int m_callPrimalHeuristic
parameter: primal heuristic (PH) call strategy
Declaration of min-st-cut algorithms parameterized by max-flow alorithm.
int m_saturationStrategy
parameter: saturation strategy, only important if nested cuts are computed
Constraint for edges, e.g., subtour elimination constraints of size 2 ((G)SEC2)