46 template<
typename TCost>
81 int infinity()
const {
return numeric_limits<int>::max(); }
166 template<
typename TCost>
189 mcfSupply[i] = supply[v];
214 mcfTail[i] = vIndex[e->
source()];
215 mcfHead[i] = vIndex[e->
target()];
216 mcfLb[i] = lowerBound[e];
217 mcfUb[i] = upperBound[e];
218 mcfCost[i] = cost[e];
234 flow[eFirst] = lowerBound[eFirst];
237 retCode =
mcf(n, m - nSelfLoops, mcfSupply, mcfTail, mcfHead, mcfLb, mcfUb, mcfCost, mcfFlow, mcfDual, &objVal);
245 flow[e] = lowerBound[e];
249 flow[e] = mcfFlow[i];
260 dual[v] = mcfDual[i];
269 template<
typename TCost>
287 for (
int i = 1; i <=
nn; ++i) {
289 if (supply[i - 1] >= 0) {
306 if (supply[i - 1] < 0) {
307 nodes[i].orientation =
false;
308 nodes[i].dual = -highCost;
310 nodes[i].orientation =
true;
311 nodes[i].dual = highCost;
313 nodes[i].flow = abs(supply[i - 1]);
314 nodes[i].nr_of_nodes = 1;
316 nodes[i].arc_id = ep;
323 template<
typename TCost>
335 if (*pre !=
nullptr) {
344 while (*eplus !=
nullptr && !found) {
345 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
359 while (*eplus !=
nullptr && !found) {
360 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
375 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
388 while (*eplus !=
nullptr && !found) {
389 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
402 while (*eplus !=
nullptr && !found) {
403 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
418 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
443 template<
typename TCost>
462 while (*eplus !=
nullptr && !found) {
463 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
481 while (*eplus !=
nullptr && !found) {
482 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
497 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
514 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
533 while (*eplus !=
nullptr && !found) {
534 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
551 while (*eplus !=
nullptr && !found) {
552 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
566 if (
m_eps.
less((*eplus)->cost + (*eplus)->head->dual, (*eplus)->tail->dual)) {
581 if (
m_eps.
less((*eplus)->tail->dual, (*eplus)->head->dual + (*eplus)->cost)) {
610 template<
typename TCost>
640 int artificials =
nn;
646 for(i = 1; i <=
nn; ++i)
654 int from = mcfTail[0];
655 int toh = mcfHead[0];
658 TCost c = mcfCost[0];
659 if (from <= 0 || from >
nn || toh <= 0 || toh >
nn || up < 0 || low > up || low < 0) {
662 TCost abs_c = c < 0 ? -c : c;
673 supply[from - 1] -= low;
674 supply[toh - 1] += low;
680 for (l = 2; l <=
mm; ++l) {
686 if (from <= 0 || from >
nn || toh <= 0 || toh >
nn || up < 0 || low > up || low < 0) {
689 abs_c = c < 0 ? -c : c;
701 supply[from-1] -= low;
702 supply[toh-1] += low;
703 lb_cost += ep->
cost * low;
709 bool feasible =
true;
727 bool finished =
false;
729 bool from_ub =
false;
732 startsearchpre =
nullptr;
743 if (eplus ==
nullptr) {
770 else if (delta > np->
flow) {
788 else if (delta > np->
flow) {
802 if (iminus ==
nullptr) {
819 bool artif_to_lb =
false;
820 if (artificials > 1) {
821 if (iminus ==
root || jminus ==
root) {
822 if (jplus !=
root && iplus !=
root) {
826 else if (eminus == eplus) {
844 if (eminus == eplus) {
845 if (from_ub) delta = -delta;
848 s_orientation = eminus->
tail == iplus;
875 if (eplus->
tail == iplus)
883 if (newsuc == iminus) {
892 bool s_orientation = (eplus->
tail != jplus);
895 bool eplus_ori = s_orientation;
912 while (nd != jminus) {
920 lastnode->
dual += sigma;
926 if (nd != iminus) lastnode->
successor = f;
936 if (w_orientation == eplus_ori) {
937 w_flow = nd->
flow + delta;
940 w_flow = nd->
flow - delta;
948 s_orientation = w_orientation;
965 while (np != iplus) {
1004 if (eminus == eplus) {
1022 TCost wcost = eminus->
cost;
1024 int wnum = eminus->
arcnum;
1032 eplus->
tail = w_tail;
1033 eplus->
head = w_head;
1035 eplus->
cost = wcost;
1061 if (artificials == 1) {
1100 }
while (!finished);
1105 if (artificials != 0
1116 }
while (np !=
root);
1119 while (ep !=
nullptr && feasible) {
1134 while (np !=
root) {
1135 if (np->
flow != 0) {
1141 while (ep !=
nullptr) {
1145 *mcfObj = zfw + lb_cost;
1150 while (np !=
root) {
1157 for (i = 0; i <
mm; ++i)
1158 mcfFlow[i] = mcfLb[i];
1161 while (np !=
root) {
1172 while (ep !=
nullptr) {
1182 for(i = 1; i <=
nn; ++i)
1186 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.
Template of base class of min-cost-flow algorithms.
Class for the representation of edges.
Class for the representation of nodes.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
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.