35 #include <coin/CoinPackedVector.hpp> 36 #include <coin/OsiClpSolverInterface.hpp> 47 #define OGDF_STEINERTREE_GOEMANS139_SEPARATE_CONNECTED_COMPONENTS // this is faster 48 #define OGDF_STEINERTREE_GOEMANS139_SEPARATE_YVAR_CONSTRAINTS // if not defined: generate all yvar constraints in the beginning 49 #define OGDF_STEINERTREE_GOEMANS139_LOSS_ON_METRIC_CLOSURE // faster and better 88 , m_separateCycles(false)
120 m_use2approx = use2approx;
188 #ifdef OGDF_STEINERTREE_GOEMANS139_SEPARATE_CONNECTED_COMPONENTS 240 witness[e].pushBack(f);
251 isInTree.
init(G,
false);
254 int contractedID = uf.
makeSet();
256 for (
node t : terminals) {
257 setID[t] = contractedID;
261 setID[v] = uf.makeSet();
270 edgePermutation.
permute(m_rng);
273 for (
edge e : edgePermutation) {
274 const int v = setID[e->
source()];
275 const int w = setID[e->
target()];
276 if (uf.find(v) != uf.find(w)) {
278 uf.link(uf.find(v), uf.find(w));
300 witnessCard.
init(blowupGraph, 0);
301 witness.
init(blowupGraph);
305 computeRandomCoreEdges(blowupGraph, terminals, isLossEdge);
311 if (!isLossEdge[e]) {
312 splitMap[e] = blowupGraph.
newNode();
319 for (
node t : terminals) {
322 while (!stack.
empty()) {
329 if (!pred[v] || w != pred[v]->theNode()) {
334 for (
node x = v; pred[x]; x = pred[x]->theNode()) {
335 addWitness(splitMap[e], pred[x]->theEdge());
344 for (
edge e : coreEdges) {
345 const T w = blowupGraph.
weight(e);
346 const node x = splitMap[e];
347 const int cap = capacity[e];
349 capacity[blowupGraph.
newEdge(e->source(), x, w)] = cap;
350 capacity[blowupGraph.
newEdge(x, e->target(), w)] = cap;
361 const edge eO = pair.key();
362 const edge eC = pair.info();
365 witnessCard[eC] = witnessCard[eO];
375 for (
edge e : witness[vO]) {
376 witness[vC].pushBack(edgeMap[e]);
399 for (
edge f : witness[e]) {
409 return witnessCard[e];
446 componentRootEdge.
push(rootEdge);
448 List<node> &terms = componentTerminals[maxId];
449 if (!bgOriginal[start]) {
450 componentCost.
push(blowupGraph.
weight(rootEdge));
452 componentCost.
push(0);
454 T &cost = componentCost[maxId];
456 while (!queue.
empty()) {
458 componentId[v] = maxId;
461 if (componentId[w] < 0) {
480 const std::vector<node> &ignores,
482 : componentId(blowupGraph, -1)
485 for (
node v : ignores) {
489 for (
node t : bgTerminals) {
490 for (
adjEntry rootAdj : t->adjEntries) {
492 if (rootEdge->
source() != t) {
497 if (componentId[r] < 0) {
498 initializeComponent(rootEdge, blowupGraph, bgOriginal);
504 for (
node t : bgTerminals) {
513 return componentTerminals[
id-1];
519 return componentId[v];
526 return componentCost[
id-1];
539 return componentRootEdge[
id-1];
546 componentRootEdge[
id-1] = e;
559 void findFullComponents();
567 if (m_predAPSP[u][v] ==
nullptr) {
585 void generateProblem(
bool perturb =
false);
587 void generateObjective(
bool perturb);
589 void addTerminalCoverConstraint();
591 bool addSubsetCoverConstraint(
const List<node> &subset);
593 void addYConstraint(
const node t);
622 for (
node t : m_terminals) {
626 for (
int j = 0; j < activeComponents.
size(); ++j) {
627 const int i = activeComponents[j];
628 const double cap = m_fullCompStore.
extra(i);
632 const auto it0 = terminals.
begin();
634 capacity[G.
newEdge(source, rC)] = cap;
635 if (terminals.
size() > 2) {
637 capacity[G.
newEdge(rC, v)] = cap;
638 for (
auto it = it0 + 1; it != terminals.
end(); ++it) {
640 capacity[G.
newEdge(v, w)] = cap;
649 for (
node t : m_terminals) {
656 y_v += capacity[adj->
theEdge()];
660 #ifdef OGDF_STEINERTREE_GOEMANS139_SEPARATE_YVAR_CONSTRAINTS 668 capacity[G.
newEdge(v, target)] = y_v;
678 cout <<
" " << e->
source();
686 cout <<
" " << capacity[e] <<
"\n";
702 while (k < m_fullCompStore.
size()) {
703 if (m_fullCompStore.
extra(k) > m_eps) {
706 m_fullCompStore.
remove(k);
715 for (
int i = ids.
size() - 1; i >= 0; --i) {
716 m_fullCompStore.
remove(ids[i]);
724 isNewTerminal[v] =
true;
737 for (
int i = 0; i < m_fullCompStore.
size(); ++i) {
765 if (innerNodes <= 1) {
767 addComponent(isNewTerminal,
id[c]);
770 inactive.
push(
id[c]);
779 removeComponents(inactive);
796 && !m_G.isTerminal(s)) {
801 for (
edge e = m_predAPSP[s][t]; e; t = e->opposite(t), e = m_predAPSP[s][t]) {
802 const node x = e->opposite(t);
826 for (
int i = 0; i < m_fullCompStore.
size(); ++i) {
835 for (
int denom : denominators) {
840 bgOriginal.
init(blowupGraph,
nullptr);
841 for (
node t : m_terminals) {
849 capacity.
init(blowupGraph);
850 for (
int i = 0; i < m_fullCompStore.
size(); ++i) {
851 int cap = int(lcm * m_fullCompStore.
extra(i) + m_eps);
862 while (!queueT.
empty()) {
868 if (m_isTerminal[wO]) {
869 #ifdef OGDF_STEINERTREE_GOEMANS139_LOSS_ON_METRIC_CLOSURE 870 capacity[blowupGraph.
newEdge(vC, blowupGraph.
copy(wO), m_fullCompStore.
graph().weight(inAdj->
theEdge()))] = cap;
872 insertShortestPathIntoBlowupGraph(blowupGraph, bgOriginal, capacity, m_fullCompStore.
original(vT), wO, vC, blowupGraph.
copy(wO), cap);
877 #ifdef OGDF_STEINERTREE_GOEMANS139_LOSS_ON_METRIC_CLOSURE 878 capacity[blowupGraph.
newEdge(vC, wC, m_fullCompStore.
graph().weight(inAdj->
theEdge()))] = cap;
880 insertShortestPathIntoBlowupGraph(blowupGraph, bgOriginal, capacity, m_fullCompStore.
original(vT), wO, vC, wC, cap);
895 if ((*it)->degree() == 0) {
903 cw.
init(blowupGraph, capacity, bgTerminals);
906 source = blowupGraph.
newNode();
907 while (!roots.
empty()) {
912 target = blowupGraph.
newNode();
913 for (
node v : bgTerminals) {
918 for (
adjEntry adj : v->adjEntries) {
920 y_v += capacity[adj->
theEdge()];
926 capacity[blowupGraph.
newEdge(v, target, 0)] = y_v;
936 const node source,
const node target)
const 970 double weight = (double)blowupGraph.
weight(tmp);
978 capacity[e] = capacity[tmp];
988 for (
int id = 1;
id <= gamma.
size(); ++id) {
1017 capacity[e] = N * y_R;
1023 int rank = gammoidGetRank(blowupGraph, capacity, source, target);
1024 supply[source] = rank;
1025 supply[target] = -rank;
1029 bool feasible = mcf.
call(blowupGraph, lB, capacity, cost, supply, flow);
1034 mcf.
call(blowupGraph, lB, capacity, cost, supply, flow);
1037 for (
edge e : sourceCoreEdges) {
1039 basis->
pushBack(std::pair<node,int>(e->target(), flow[e]));
1040 weight -= flow[e] * cost[e];
1045 for (
edge e : Q_to_target) {
1052 if (gamma.
cost(
id) * N <= weight + m_eps) {
1054 for (
edge e : sourceCoreEdges) {
1074 for (
int id = 1;
id <= gamma.
size(); ++id) {
1075 if (gamma.
cost(
id) > cost) {
1076 cost = gamma.
cost(
id);
1083 edge tmp = v->lastAdj()->theEdge();
1084 maxBasis->pushBack(std::pair<node,int>(v, capacity[tmp]));
1093 const edge rootEdge)
1098 while (!stack.
empty()) {
1103 const node vO = bgOriginal[v];
1105 isNewTerminal[vO] =
true;
1121 const edge origEdge,
1122 const int origCap,
const int copyCap)
1132 while (!todo.
empty()) {
1139 bgOriginal[wC] = bgOriginal[wO];
1142 capacity[eC] = copyCap;
1143 capacity[eO] = origCap;
1161 const node pseudotarget,
1171 while (!cleanup.
empty()) {
1179 if (v->
indeg() == 0) {
1209 const node pseudotarget,
1216 for (std::pair<node,int> p : basis) {
1217 const node v = p.first;
1218 const int count = p.second;
1222 if (count < origCap) {
1227 removeBasisAndCleanup(blowupGraph, gamma, v, source, pseudotarget, N);
1232 const node v = p.item();
1233 const int count = -p.priority();
1238 copyComponent(blowupGraph, capacity, cw, bgOriginal, gamma.
rootEdge(gamma.
id(v)), count, origCap - count);
1241 removeBasisAndCleanup(blowupGraph, gamma, v, source, pseudotarget, N);
1250 const node pseudotarget,
1259 if (adj->twinNode() == source) {
1261 blowupGraph.
delEdge(adj->theEdge());
1264 if (adj->twinNode() == pseudotarget) {
1266 delta -= capacity[adj->theEdge()];
1267 blowupGraph.
delEdge(adj->theEdge());
1271 capTarget += capacity[adj->theEdge()];
1273 if (v != adj->theEdge()->target()) {
1274 capSource += capacity[adj->theEdge()];
1279 if (capTarget > 0) {
1280 capacity[blowupGraph.
newEdge(v, pseudotarget, 0)] = capTarget;
1282 if (capSource > 0) {
1283 capacity[blowupGraph.
newEdge(source, v, 0)] = capSource;
1286 return delta + capTarget;
1298 , m_isTerminal(isTerminal)
1299 , m_terminals(terminals)
1301 , m_fullCompStore(G, m_terminals, isTerminal)
1304 , m_osiSolver(
CoinManager::createCorrectOsiSolverInterface())
1306 , m_objective(nullptr)
1307 , m_lowerBounds(nullptr)
1308 , m_upperBounds(nullptr)
1311 , m_ssspDistances(true)
1312 , m_separateCycles(false)
1314 , m_separationStage(0)
1317 , m_approx2SteinerTree(nullptr)
1324 delete[] m_objective;
1326 delete[] m_lowerBounds;
1327 delete[] m_upperBounds;
1334 if (m_use2approx != Approx2State::Off) {
1336 m_approx2Weight = mstT.
call(m_G, m_terminals, m_isTerminal, m_approx2SteinerTree, m_G.
firstNode());
1339 if (m_restricted > m_terminals.
size()) {
1340 m_restricted = m_terminals.
size();
1344 if (!m_isTerminal[u]) {
1349 m_distance.
init(m_G);
1350 m_predAPSP.
init(m_G);
1352 && m_restricted <= 3) {
1354 for (
node u : m_terminals) {
1362 m_ssspDistances =
false;
1371 findFullComponents();
1373 generateProblem(perturb);
1374 addTerminalCoverConstraint();
1376 #ifndef OGDF_STEINERTREE_GOEMANS139_SEPARATE_YVAR_CONSTRAINTS 1377 for (
node t : m_terminals) {
1386 m_restricted = restricted;
1392 m_use2approx = use2approx ? Approx2State::On : Approx2State::Off;
1398 m_separateCycles = add;
1404 m_ssspDistances = !force;
1411 T getApproximation(
EdgeWeightedGraphCopy<T> *&finalSteinerTree,
const std::minstd_rand &rng,
const bool doPreprocessing =
true);
1414 template<
typename T>
1427 const int N = generateGammoidGraph(source, pseudotarget, cw, blowupGraph, bgOriginal, bgTerminals, capacity, y_R);
1434 capacity[blowupGraph.
newEdge(pseudotarget, target, 0)] = y_R;
1436 while (bgTerminals.
size() > 1) {
1439 BlowupComponents gamma(blowupGraph, bgTerminals, {source, pseudotarget, target}, bgOriginal);
1445 int compId = y_R > 0
1446 ? findComponentAndMaxBasis(maxBasis, blowupGraph, bgTerminals, cw,
1447 capacity, gamma, N, y_R, source, target)
1448 : findCheapestComponentAndRemainingBasis(maxBasis, cw, capacity, gamma);
1452 addComponent(isNewTerminal, blowupGraph, bgOriginal, gamma.rootEdge(compId));
1455 removeFractionalBasisAndCleanup(*maxBasis, blowupGraph, bgOriginal, capacity, gamma, cw, source, pseudotarget, N);
1475 if (bgTerminals.
size() > 1) {
1477 y_R += updateSourceAndTargetArcCapacities(blowupGraph, capacity, v, source, pseudotarget, N);
1480 for (
node t : bgTerminals) {
1481 y_R += updateSourceAndTargetArcCapacities(blowupGraph, capacity, t, source, pseudotarget, N);
1485 capacity[target->firstAdj()->theEdge()] = y_R;
1490 template<
typename T>
1496 finalSteinerTree = m_approx2SteinerTree;
1497 return m_approx2Weight;
1501 const double *constSol = m_osiSolver->getColSolution();
1502 const int numberOfColumns = m_osiSolver->getNumCols();
1504 for (
int i = 0; i < numberOfColumns; i++) {
1505 m_fullCompStore.extra(i) = constSol[i];
1508 removeInactiveComponents();
1511 for (
node v : m_terminals) {
1512 isNewTerminal[v] =
true;
1515 if (doPreprocessing) {
1516 preprocess(isNewTerminal);
1519 if (!m_fullCompStore.isEmpty()) {
1520 doGoemansApproximation(isNewTerminal);
1525 if (m_approx2Weight < cost) {
1526 delete finalSteinerTree;
1527 finalSteinerTree = m_approx2SteinerTree;
1529 delete m_approx2SteinerTree;
1536 template<
typename T>
1540 int n = m_fullCompStore.size();
1542 m_matrix =
new CoinPackedMatrix;
1543 m_matrix->setDimensions(0, n);
1545 m_lowerBounds =
new double[n];
1546 m_upperBounds =
new double[n];
1547 for (
int i = 0; i < n; ++i) {
1548 m_lowerBounds[i] = 0;
1549 m_upperBounds[i] = 1;
1552 generateObjective(perturb);
1553 m_osiSolver->loadProblem(*m_matrix, m_lowerBounds, m_upperBounds, m_objective,
nullptr,
nullptr);
1556 CoinPackedVector row;
1557 row.setFull(m_fullCompStore.size(), m_objective);
1558 m_osiSolver->addRow(row, 0, m_approx2Weight);
1562 template<
typename T>
1566 int n = m_fullCompStore.size();
1567 m_objective =
new double[n];
1569 for (
int i = 0; i < n; ++i) {
1570 double w = m_fullCompStore.cost(i);
1573 w += (rand() % 1000)*1e-9;
1580 template<
typename T>
1584 CoinPackedVector row;
1586 for (
int i = 0; i < m_fullCompStore.size(); ++i) {
1587 if (m_fullCompStore.isTerminal(i, t)) {
1592 m_osiSolver->addRow(row, 1, m_osiSolver->getInfinity());
1596 template<
typename T>
1600 CoinPackedVector row;
1603 for (
int i = 0; i < m_fullCompStore.size(); ++i) {
1605 int intersectionCard = 0;
1606 auto terminals = m_fullCompStore.terminals(i);
1607 node *it1 = terminals.begin();
1608 auto it2 = subset.
begin();
1609 while (it1 != terminals.end()
1611 if ((*it1)->index() < (*it2)->index()) {
1614 if ((*it1)->index() > (*it2)->index()) {
1623 if (intersectionCard > 1) {
1624 row.insert(i, intersectionCard - 1);
1625 test += (intersectionCard - 1) * m_fullCompStore.extra(i);
1628 if (test > (subset.
size() - 1)) {
1629 m_osiSolver->addRow(row, 0, subset.
size() - 1);
1635 template<
typename T>
1641 CoinPackedVector row;
1643 for (
int i = 0; i < m_fullCompStore.size(); ++i) {
1644 row.insert(i, m_fullCompStore.terminals(i).size() - 1);
1647 int value = m_terminals.size() - 1;
1648 m_osiSolver->addRow(row, value, value);
1651 template<
typename T>
1655 for (terminalSubset.
begin(2); terminalSubset.
valid(); terminalSubset.
next()) {
1656 const node s = terminalSubset[0];
1657 const node t = terminalSubset[1];
1658 if (m_predAPSP[s][t]) {
1662 m_fullCompStore.insert(minComp);
1667 template<
typename T>
1671 for (terminalSubset.
begin(3); terminalSubset.
valid(); terminalSubset.
next()) {
1672 const node t0 = terminalSubset[0];
1673 const node t1 = terminalSubset[1];
1674 const node t2 = terminalSubset[2];
1675 OGDF_ASSERT(m_distance[t0][t1] < numeric_limits<T>::max());
1676 OGDF_ASSERT(m_distance[t0][t2] < numeric_limits<T>::max());
1677 OGDF_ASSERT(m_distance[t1][t2] < numeric_limits<T>::max());
1679 min(m_distance[t0][t1] + m_distance[t0][t2],
1680 min(m_distance[t1][t0] + m_distance[t1][t2],
1681 m_distance[t2][t0] + m_distance[t2][t1]));
1682 node minCenter =
nullptr;
1683 for (
node center : m_nonterminals) {
1684 OGDF_ASSERT(m_distance[t0][center] < numeric_limits<T>::max());
1685 OGDF_ASSERT(m_distance[t1][center] < numeric_limits<T>::max());
1686 OGDF_ASSERT(m_distance[t2][center] < numeric_limits<T>::max());
1687 const T cost = m_distance[t0][center] + m_distance[t1][center] + m_distance[t2][center];
1688 if (cost < minCost) {
1694 && m_predAPSP[t0][minCenter]
1695 && m_predAPSP[t1][minCenter]
1696 && m_predAPSP[t2][minCenter]) {
1701 minComp.
newEdge(minComp.
newNode(t0), minCenterC, m_distance[t0][minCenter]);
1702 minComp.
newEdge(minComp.
newNode(t1), minCenterC, m_distance[t1][minCenter]);
1703 minComp.
newEdge(minComp.
newNode(t2), minCenterC, m_distance[t2][minCenter]);
1704 m_fullCompStore.insert(minComp);
1709 template<
typename T>
1719 terminalSubset.
list(terminals);
1721 if (isValidComponent(component)) {
1722 m_fullCompStore.insert(component);
1726 findFull2Components(terminalSubset);
1728 findFull3Components(terminalSubset);
1733 template<
typename T>
1737 bool initialIteration =
true;
1740 if (initialIteration) {
1741 m_osiSolver->initialSolve();
1742 initialIteration =
false;
1744 m_osiSolver->resolve();
1747 if (!m_osiSolver->isProvenOptimal()) {
1753 cerr <<
"Failed to optimize LP!" << endl;
1757 }
while (separate());
1760 template<
typename T>
1764 const double *constSol = m_osiSolver->getColSolution();
1767 for (
int i = 0; i < m_fullCompStore.size(); ++i) {
1768 m_fullCompStore.extra(i) = constSol[i];
1769 if (m_fullCompStore.extra(i) > m_eps) {
1770 activeComponents.
push(i);
1774 #ifdef OGDF_STEINERTREE_GOEMANS139_SEPARATE_CONNECTED_COMPONENTS 1775 if (!m_separationStage) {
1776 if (separateConnected(activeComponents)) {
1779 m_separationStage = 1;
1782 if (separateMinCut(activeComponents)) {
1788 template<
typename T>
1794 for (
node t : m_terminals) {
1795 setID[t] = uf.makeSet();
1799 for (
int j = 0; j < activeComponents.
size(); ++j) {
1800 auto terminals = m_fullCompStore.terminals(activeComponents[j]);
1801 auto it = terminals.
begin();
1802 const int s1 = setID[*it];
1803 for (++it; it != terminals.end(); ++it) {
1804 uf.link(uf.find(s1), uf.find(setID[*it]));
1808 if (uf.getNumberOfSets() == 1) {
1814 for (
node t : m_terminals) {
1815 const int k = uf.find(setID[t]);
1816 if (components[k].empty()) {
1817 usedComp.pushBack(k);
1819 components[k].pushBack(t);
1824 cutsFound += addSubsetCoverConstraint(components[k]);
1829 template<
typename T>
1838 double y_R = generateMinCutSeparationGraph(activeComponents, source, pseudotarget, auxG, capacity, cutsFound);
1840 #ifdef OGDF_STEINERTREE_GOEMANS139_SEPARATE_YVAR_CONSTRAINTS 1841 if (cutsFound > 0) {
1847 capacity[auxG.
newEdge(pseudotarget, target)] = y_R;
1852 for (
node t : m_terminals) {
1856 capacity[v_to_target] = numeric_limits<double>::max();
1858 maxFlow.
init(auxG, &flow);
1860 const double cutVal = maxFlow.
computeValue(capacity, source, target);
1861 if (cutVal - y_R < 1 - m_eps) {
1862 minSTCut.
call(auxG, capacity, flow, source, target);
1864 for (
node tOrig : m_terminals) {
1865 const node tCopy = auxG.
copy(tOrig);
1871 cutsFound += addSubsetCoverConstraint(subset);
1876 return cutsFound != 0;
1879 template<
typename T>
1888 for (
int i : activeComponents) {
1892 const int i1 =
id[u1];
1893 const Array<node> &terminals1 = m_fullCompStore.terminals(i1);
1895 const int i2 =
id[u2];
1896 const Array<node> &terminals2 = m_fullCompStore.terminals(i2);
1898 int intersectionCard = 0;
1901 while (it1 != terminals1.
end()
1902 && it2 != terminals2.
end()) {
1903 if ((*it1)->index() < (*it2)->index()) {
1906 if ((*it1)->index() > (*it2)->index()) {
1910 if (intersectionCard == 2) {
1933 if (idx >= maxClique) {
1934 idx = maxClique - 1;
1937 degrees[idx].pushBack(v);
1940 for (
int k = degrees.
size(); k >= 2; --k) {
1941 degrees[k-2].conc(degrees[k-1]);
1942 if (degrees[k-2].size() >= k) {
1944 for (nodeSubset.
begin(k); nodeSubset.
valid(); nodeSubset.
next()) {
1945 int countEdges = (k * (k-1)) / 2;
1946 for (
int j = 0; j < nodeSubset.
size(); ++j) {
1947 test[nodeSubset[j]] =
true;
1956 if (countEdges == 0) {
1959 CoinPackedVector row;
1961 for (
int j = 0; j < nodeSubset.
size(); ++j) {
1962 int i =
id[nodeSubset[j]];
1963 val += m_fullCompStore.extra(i);
1966 if (val >= 1 + m_eps) {
1967 m_osiSolver->addRow(row, 0, 1);
1971 for (
int j = 0; j < nodeSubset.
size(); ++j) {
1972 test[nodeSubset[j]] =
false;
1980 template<
typename T>
1983 std::minstd_rand rng(
m_seed);
1984 UFCR ufcr(G, terminals, isTerminal);
int gammoidGetRank(EdgeWeightedGraphCopy< T > &blowupGraph, EdgeArray< int > &capacity, const node source, const node target) const
Computes the rank of the gammoid (given by the blowup graph)
node target() const
Returns the target node of the edge.
const List< node > & core() const
Return list of core edges (implemented by nodes)
EdgeWeightedGraphCopy< T > * m_approx2SteinerTree
static void allPairShortestPathsDetour(const EdgeWeightedGraph< T > &G, const List< node > &nonterminals, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
A generator for full components (for Steiner tree approximations) based on the Dreyfus-Wagner algorit...
bool separateConnected(const ArrayBuffer< int > &activeComponents)
Separate to ensure that the solution is connected.
edge theEdge() const
Returns the edge associated with this adjacency entry.
bool addSubsetCoverConstraint(const List< node > &subset)
Add subset cover constraints to the LP for a given subset of terminals.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
NodeArray< NodeArray< edge > > m_predAPSP
Declaration of min-cost-flow algorithm (class MinCostFlowReinelt)
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
void init()
Reinitializes the array. Associates the array with no graph.
iterator pushBack(const E &x)
Adds element x at the end of the list.
bool separateMinCut(const ArrayBuffer< int > &activeComponents)
Perform the general cut-based separation algorithm.
Data type for general directed graphs (adjacency list representation).
void addCore(node e)
Add a core edge.
T getSteinerTreeFor(const List< node > &terminals, EdgeWeightedGraphCopy< T > &tree)
Construct a Steiner tree for the given set of terminals.
List< node > m_coreEdges
the core edges as nodes
void preprocess(NodeArray< bool > &isNewTerminal)
Preprocess LP solution.
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
Declaration of stopwatch classes.
ArrayBuffer< List< node > > componentTerminals
void call(int restricted)
void init()
Reinitializes the array. Associates the array with no graph.
void forceAPSP(bool force=true)
Force full APSP algorithm even if consecutive SSSP algorithms may work.
void addComponent(NodeArray< bool > &isNewTerminal, int id)
Add a full component to the final solution (by changing nonterminals to terminals) ...
This class serves as an interface for various methods to compute minimum or approximations of minimum...
virtual void init(const Graph &graph, EdgeArray< TCap > *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.
Indexed arrays using hashing for element access.
int degree() const
Returns the degree of the node (indegree + outdegree).
edge newEdge(node u, node v, T weight)
void insertShortestPathIntoBlowupGraph(EdgeWeightedGraphCopy< T > &blowupGraph, NodeArray< node > &bgOriginal, EdgeArray< int > &capacity, node s, node t, const node vC, const node wC, int cap)
Inserts (based on m_distance and m_predAPSP) a shortest path from a component, directed, into the blowupGraph and sets weights and capacity accordingly.
List< node > m_terminals
List of terminals.
int size() const
Return number of components.
int indeg() const
Returns the indegree of the node.
iterator begin()
Returns an iterator to the first element of the list.
const Array< node > & terminals(int id) const
Returns the list of terminals in the full component with given id.
CoreWitness(std::minstd_rand &rng)
static void sortTerminals(List< node > &terminals)
Sort terminals by index.
Class managing LP and LP-based approximation.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
int generateGammoidGraph(node &source, node &target, CoreWitness &cw, EdgeWeightedGraphCopy< T > &blowupGraph, NodeArray< node > &bgOriginal, List< node > &bgTerminals, EdgeArray< int > &capacity, int &y_R) const
Generates a special-purpose blowup graph for gammoid computation: directed, with special source and t...
node firstNode() const
Returns the first node in the list of all nodes.
Min-st-cut algorithm, that calculates the cut via maxflow.
ArrayBuffer< T > componentCost
void push(E e)
Puts a new element in the buffer.
bool separate()
Perform all available separation algorithms.
E popBackRet()
Removes the last element from the list and returns it.
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
void findFullComponents()
Find full components.
void delCore(node e)
Remove a core edge.
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
List< node > m_nonterminals
List of non-terminals.
bool valid() const
Is the current subset valid? If not, all subsets have already been enumerated.
NodeArray< List< edge > > witness
ArrayBuffer< edge > componentRootEdge
node succ() const
Returns the successor in the list of all nodes.
virtual ~MinSteinerTreeGoemans139()
void quicksort()
Sorts buffer using Quicksort.
CoinPackedMatrix * m_matrix
void init(EdgeWeightedGraphCopy< T > &blowupGraph, EdgeArray< int > &capacity, const List< node > &terminals)
Find a "random" set of core edges and "replace" found edges by nodes, also find the witness sets for ...
int findComponentAndMaxBasis(List< std::pair< node, int >> *&maxBasis, EdgeWeightedGraphCopy< T > &blowupGraph, const List< node > &bgTerminals, const CoreWitness &cw, EdgeArray< int > &capacity, const BlowupComponents &gamma, const int N, const int y_R, const node source, const node target)
Finds the best component and its maximum-weight basis in the given blowup graph with given core and w...
int id(node v) const
Return the component id a given node is contained in.
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
void removeFractionalBasisAndCleanup(List< std::pair< node, int >> &basis, EdgeWeightedGraphCopy< T > &blowupGraph, NodeArray< node > &bgOriginal, EdgeArray< int > &capacity, BlowupComponents &gamma, CoreWitness &cw, const node source, const node pseudotarget, const int N)
Remove a given basis and cleanup, the basis may be given fractionally.
Augments any data elements of type X with keys of type Priority. This class is also its own Comparer...
Declaration and implementation of Goldberg-Tarjan max-flow algorithm with global relabeling and gap r...
const List< edge > & witnessList(node e) const
Return list of loss edges f in W(e)
ListIteratorBase< E, isConst > succ() const
Returns successor iterator.
static void getFraction(double d, int &num, int &denom, const double epsilon=5e-10, const int count=10)
Converts a double to a fraction.
void addWitness(node e, edge f)
Add e to W(f)
void makeCopy(const HashArray< edge, edge > &edgeMap)
Copy witness sets and core edges for a given copy map.
void del(iterator it)
Removes it from the list.
T weight(const edge e) const
void use2Approximation(bool use2approx)
Define if we want to use a 2-approximation as bound.
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
virtual void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
const List< node > & terminals(int id) const
Return list of terminals for a given component.
void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter)
Moves adjacency entry adjMove after adjAfter.
NodeArray< int > componentId
iterator rbegin()
Returns an iterator to the last element.
BlowupComponents(const EdgeWeightedGraphCopy< T > &blowupGraph, const List< node > &bgTerminals, const std::vector< node > &ignores, const NodeArray< node > &bgOriginal)
Find all components in the blowup graph and initialize information them.
void createEmpty(const Graph &wG)
double generateMinCutSeparationGraph(const ArrayBuffer< int > &activeComponents, node &source, node &target, GraphCopy &G, EdgeArray< double > &capacity, int &cutsFound)
Generates an auxiliary multi-graph for separation (during LP solving): directed, with special source ...
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Builds a minimum Steiner tree for a given weighted graph with terminals.
void findFull2Components(SubsetEnumerator< node > &terminalSubset)
Find full components of size 2.
void quicksort()
Sorts the list using Quicksort.
void initializeComponent(edge rootEdge, const EdgeWeightedGraphCopy< T > &blowupGraph, const NodeArray< node > &bgOriginal)
Initialize all information about the component starting with rootEdge in the blowup graph...
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree, const node startNode)
An extended call method with specific start node.
Iterators for hash tables.
void begin(int low, int high)
Initialize the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
bool empty() const
Returns true if the buffer is empty, false otherwise.
edge firstEdge() const
Returns the first edge in the list of all edges.
static void copy(const T &from, T &to)
INDEX size() const
Returns the size (number of elements) of the array.
int numberOfWitnesses(edge e) const
Return the number of witnesses of an edge.
node contract(edge e)
Contracts edge e while preserving the order of adjacency entries.
Enumerator for k-subsets of a given type.
Definition and implementation of FullComponentStore, a data structure to store full components...
Manage witness set and core edges of a blowup graph.
T getApproximation(EdgeWeightedGraphCopy< T > *&finalSteinerTree, const std::minstd_rand &rng, const bool doPreprocessing=true)
Obtain an (1.39+epsilon)-approximation based on the LP solution.
Doubly linked lists (maintaining the length of the list).
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
TCap computeValue(const EdgeArray< TCap > &cap, const node &s, const node &t)
Compute only the value of the flow.
bool separateCycles(const ArrayBuffer< int > &activeComponents)
Perform the separation algorithm for cycle constraints (to obtain stronger LP solution) ...
void copyComponent(EdgeWeightedGraphCopy< T > &blowupGraph, EdgeArray< int > &capacity, CoreWitness &cw, NodeArray< node > &bgOriginal, const edge origEdge, const int origCap, const int copyCap)
Copy a component in the blowup graph and set original capacity to origCap and capacity of copy to cop...
A Union/Find data structure for maintaining disjoint sets.
bool isLoopFree(const Graph &G)
Returns true iff G contains no self-loop.
EdgeArray< int > witnessCard
static T gcd(T a, T b)
Returns the greatest common divisor of two numbers.
const EdgeWeightedGraph< T > & m_G
void setMaxComponentSize(int restricted)
Set the maximum full component size to generate.
const T & cost(int id) const
Return total cost of a given component.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
void addCycleConstraints(bool add=true)
Define if we want to use cycle constraints for a stronger LP.
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
void generateObjective(bool perturb)
Generate the LP objective.
E popFrontRet()
Removes the first element from the list and returns it.
steiner_tree::FullComponentWithExtraStore< T, double > m_fullCompStore
all enumerated full components, with solution
Copies of graphs supporting edge splitting.
void addTerminalCoverConstraint()
Add terminal cover constraints to the LP.
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Class for the representation of nodes.
Obtain and provides information about components in a given blowup graph.
node original(node v) const
Encapsulates a pointer to a list element.
void generateProblem(bool perturb=false)
Generate the LP model.
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
edge rootEdge(int id) const
Return the edge coming from the root of a given component.
bool isValidComponent(const EdgeWeightedGraphCopy< T > &graph)
Check if a given (sub)graph is a valid full component.
INDEX size() const
Returns number of elements in the buffer.
const Graph & original() const
Returns a reference to the original graph.
static void singleSourceShortestPathsDetour(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
const NodeArray< bool > & m_isTerminal
iterator begin()
Returns an iterator to the first element.
This class implements the minimum Steiner tree 2-approximation algorithm by Takahashi and Matsuyama w...
int makeSet()
Initializes a singleton set.
static T lcm(T a, T b)
Returns the least common multipler of two numbers.
void computeRandomCoreEdges(const EdgeWeightedGraphCopy< T > &G, const List< node > &terminals, EdgeArray< bool > &isInTree)
Compute a random set of core edges.
void setMaxComponentSize(int k)
Sets the maximal number of terminals in a full component.
E popRet()
Removes the newest element from the buffer and returns it.
void init(bool perturb=false)
Perform basic initialization algorithms: find shortest paths, find the full components, generate the LP model.
bool removeFirst(const E &x)
Removes the first occurrence of x (if any) from the list.
iterator end()
Returns an iterator to one past the last element.
void doGoemansApproximation(NodeArray< bool > &isNewTerminal)
Perform the actual approximation algorithm on the LP solution.
void list(List< T > &list) const
Obtain (append) a list of the elements in the subset.
OsiSolverInterface * m_osiSolver
void next()
Obtain the next subset if possible. The result should be checked using the valid() method...
adjEntry succ() const
Returns the successor in the adjacency list.
int size() const
Returns the number of elements in the list.
void removeInactiveComponents()
Remove inactive components from m_fullCompStore (since we do not need them any longer) ...
void setRootEdge(int id, edge e)
Set the edge coming from the root for a given component.
iterator begin()
Returns an iterator to the first entry in the node array.
adjEntry start(int i) const
void addComponent(NodeArray< bool > &isNewTerminal, const EdgeWeightedGraphCopy< T > &blowupGraph, const NodeArray< node > &bgOriginal, const edge rootEdge)
Add a component of the blowup graph to the final solution (by changing nonterminals to terminals) ...
int findCheapestComponentAndRemainingBasis(List< std::pair< node, int >> *&maxBasis, const CoreWitness &cw, EdgeArray< int > &capacity, const BlowupComponents &gamma)
For the end of the algorithm: find cheapest component and choose all remaining core edges as basis...
virtual bool call(const Graph &graph, const EdgeArray< TCost > &weight, node s, node t, List< edge > &edgeList, edge e_st) override
The actual algorithm call.
HashConstIterator< I, E, H > begin() const
Returns an iterator to the first element in the list of all elements.
static bool checkComputedFlow(const Graph &G, EdgeArray< int > &lowerBound, EdgeArray< int > &upperBound, EdgeArray< TCost > &cost, NodeArray< int > &supply, EdgeArray< int > &flow, TCost &value)
checks if a computed flow is a feasible solution to the given problem instance.
node source() const
Returns the source node of the edge.
#define OGDF_STEINERTREE_GOEMANS139_SEPARATE_CONNECTED_COMPONENTS
Handles connection to the COIN library, by offering helper classes.
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
void findFull3Components(SubsetEnumerator< node > &terminalSubset)
Find full components of size 3.
const EdgeWeightedGraph< T > & graph() const
bool isInBackCut(const node v) const
Returns whether this node is part of the back cut.
void addYConstraint(const node t)
Add constraint that the sum of x_C over all components C spanning terminal t is at least 1 to ensure ...
int size() const
Return the cardinality of the subset.
The namespace for all OGDF objects.
void solve()
Solve the LP.
static void allPairShortestPathsStrict(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
void removeComponents(ArrayBuffer< int > &ids)
Remove the full components with the given ids.
Computes a min-cost flow using a network simplex method.
UFCR(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal)
Initialize all attributes, sort the terminal list.
virtual bool call(const Graph &G, const EdgeArray< int > &lowerBound, const EdgeArray< int > &upperBound, const EdgeArray< TCost > &cost, const NodeArray< int > &supply, EdgeArray< int > &flow, NodeArray< TCost > &dual) override
Computes a min-cost flow in the directed graph G using a network simplex method.
MinSteinerTreeGoemans139()
int numberOfNodes() const
Returns the number of nodes in the graph.
node newNode()
Creates a new node and returns it.
virtual void delNode(node v) override
Removes node v and all its adjacent edges cleaning-up their corresponding lists of original edges...
int size() const
Returns the number of full components in the store.
NodeArray< NodeArray< T > > m_distance
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
This class implements the (1.39+epsilon)-approximation algorithm for the Steiner tree problem by Goem...
Definition and implementation of a full component generator based on the Dreyfus-Wagner algorithm...
void forceAPSP(bool force=true)
Define if APSP shortest path algorithm should be used even if SSSP can be used.
void foreachNode(int id, Fun f) const
static void singleSourceShortestPathsStrict(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
Approx2State m_use2approx
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
void setSeed(int seed)
Set seed for the random number generation.
bool empty() const
Returns true iff the list is empty.
Computes a max flow via Preflow-Push (global relabeling and gap relabeling heuristic).
void use2Approximation(bool use2approx=true)
Use Takahashi-Matsuyama 2-approximation as upper bounds.
Class for adjacency list elements.
void separateCycles(bool separateCycles=true)
Use stronger LP relaxation (not recommended in general)
void permute()
Randomly permutes the elements in the list.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
int updateSourceAndTargetArcCapacities(EdgeWeightedGraphCopy< T > &blowupGraph, EdgeArray< int > &capacity, const node v, const node source, const node pseudotarget, const int N)
Update arc capacities s->v and v->t.
T weight(const edge e) const
void removeBasisAndCleanup(EdgeWeightedGraphCopy< T > &blowupGraph, BlowupComponents &gamma, node v, const node source, const node pseudotarget, const int N)
Remove basis (given by v, a core edge node of the maximum basis) and cleanup.
Declaration of min-st-cut algorithms parameterized by max-flow alorithm.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.