43 template<
typename TCost>
78 int infinity()
const {
return std::numeric_limits<int>::max(); }
162 template<
typename TCost>
185 mcfSupply[i] = supply[v];
210 mcfTail[i] = vIndex[e->
source()];
211 mcfHead[i] = vIndex[e->
target()];
212 mcfLb[i] = lowerBound[e];
213 mcfUb[i] = upperBound[e];
214 mcfCost[i] = cost[e];
230 flow[eFirst] = lowerBound[eFirst];
233 retCode =
mcf(n, m - nSelfLoops, mcfSupply, mcfTail, mcfHead, mcfLb, mcfUb, mcfCost, mcfFlow, mcfDual, &objVal);
241 flow[e] = lowerBound[e];
245 flow[e] = mcfFlow[i];
256 dual[v] = mcfDual[i];
265 template<
typename TCost>
283 for (
int i = 1; i <=
nn; ++i) {
285 if (supply[i - 1] >= 0) {
302 if (supply[i - 1] < 0) {
303 nodes[i].orientation =
false;
304 nodes[i].dual = -highCost;
306 nodes[i].orientation =
true;
307 nodes[i].dual = highCost;
309 nodes[i].flow = abs(supply[i - 1]);
310 nodes[i].nr_of_nodes = 1;
312 nodes[i].arc_id = ep;
319 template<
typename TCost>
331 if (*pre !=
nullptr) {
340 while (*eplus !=
nullptr && !found) {
341 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
355 while (*eplus !=
nullptr && !found) {
356 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
371 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
384 while (*eplus !=
nullptr && !found) {
385 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
398 while (*eplus !=
nullptr && !found) {
399 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
414 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
439 template<
typename TCost>
458 while (*eplus !=
nullptr && !found) {
459 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
477 while (*eplus !=
nullptr && !found) {
478 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
493 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
510 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
529 while (*eplus !=
nullptr && !found) {
530 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
547 while (*eplus !=
nullptr && !found) {
548 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
562 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
577 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
606 template<
typename TCost>
636 int artificials =
nn;
642 for(i = 1; i <=
nn; ++i)
650 int from = mcfTail[0];
651 int toh = mcfHead[0];
654 TCost c = mcfCost[0];
655 if (from <= 0 || from >
nn || toh <= 0 || toh >
nn || up < 0 || low > up || low < 0) {
658 TCost abs_c = c < 0 ? -c : c;
669 supply[from - 1] -= low;
670 supply[toh - 1] += low;
676 for (lower = 2; lower <=
mm; ++lower) {
677 from = mcfTail[lower-1];
678 toh = mcfHead[lower-1];
679 low = mcfLb[lower-1];
681 c = mcfCost[lower-1];
682 if (from <= 0 || from >
nn || toh <= 0 || toh >
nn || up < 0 || low > up || low < 0) {
685 abs_c = c < 0 ? -c : c;
697 supply[from-1] -= low;
698 supply[toh-1] += low;
699 lb_cost += ep->
cost * low;
705 bool feasible =
true;
723 bool finished =
false;
725 bool from_ub =
false;
728 startsearchpre =
nullptr;
739 if (eplus ==
nullptr) {
766 else if (delta > np->
flow) {
784 else if (delta > np->
flow) {
798 if (iminus ==
nullptr) {
815 bool artif_to_lb =
false;
816 if (artificials > 1) {
817 if (iminus ==
root || jminus ==
root) {
818 if (jplus !=
root && iplus !=
root) {
822 else if (eminus == eplus) {
840 if (eminus == eplus) {
841 if (from_ub) delta = -delta;
844 s_orientation = eminus->
tail == iplus;
871 if (eplus->
tail == iplus)
879 if (newsuc == iminus) {
888 bool s_orientation = (eplus->
tail != jplus);
891 bool eplus_ori = s_orientation;
908 while (nd != jminus) {
916 lastnode->
dual += sigma;
922 if (nd != iminus) lastnode->
successor = f;
932 if (w_orientation == eplus_ori) {
933 w_flow = nd->
flow + delta;
936 w_flow = nd->
flow - delta;
944 s_orientation = w_orientation;
961 while (np != iplus) {
1000 if (eminus == eplus) {
1018 TCost wcost = eminus->
cost;
1020 int wnum = eminus->
arcnum;
1028 eplus->
tail = w_tail;
1029 eplus->
head = w_head;
1031 eplus->
cost = wcost;
1057 if (artificials == 1) {
1096 }
while (!finished);
1101 if (artificials != 0
1112 }
while (np !=
root);
1115 while (ep !=
nullptr && feasible) {
1130 while (np !=
root) {
1131 if (np->
flow != 0) {
1137 while (ep !=
nullptr) {
1141 *mcfObj = zfw + lb_cost;
1146 while (np !=
root) {
1153 for (i = 0; i <
mm; ++i)
1154 mcfFlow[i] = mcfLb[i];
1157 while (np !=
root) {
1168 while (ep !=
nullptr) {
1178 for(i = 1; i <=
nn; ++i)
1182 delete nodes[i].arc_id;
node target() const
Returns the target node of the edge.
Data type for general directed graphs (adjacency list representation).
int mcf(int mcfNrNodes, int mcfNrArcs, Array< int > &mcfSupply, Array< int > &mcfTail, Array< int > &mcfHead, Array< int > &mcfLb, Array< int > &mcfUb, Array< TCost > &mcfCost, Array< int > &mcfFlow, Array< TCost > &mcfDual, TCost *mcfObj)
Interface for min-cost flow algorithms.
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
static bool checkProblem(const Graph &G, const EdgeArray< int > &lowerBound, const EdgeArray< int > &upperBound, const NodeArray< int > &supply)
Checks if a given min-cost flow problem instance satisfies the preconditions.
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
edge firstEdge() const
Returns the first edge in the list of all edges.
Definition of ogdf::MinCostFlowModule class template.
Class for the representation of edges.
Class for the representation of nodes.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
bool isSelfLoop() const
Returns true iff the edge is a self-loop (source node = target node).
node source() const
Returns the source node of the edge.
void start(Array< int > &supply)
The namespace for all OGDF objects.
Computes a min-cost flow using a network simplex method.
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.
int numberOfNodes() const
Returns the number of nodes in the graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
void beadouble(arctype **eplus, arctype **pre, bool *from_ub)
void beacircle(arctype **eplus, arctype **pre, bool *from_ub)
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.