Open
Graph Drawing
Framework

 v.2012.05
 

MinCostFlowReinelt.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 #ifndef OGDF_MIN_COST_FLOW_REINELT_H
00049 #define OGDF_MIN_COST_FLOW_REINELT_H
00050 
00051 
00052 #include <ogdf/module/MinCostFlowModule.h>
00053 #include <limits.h>
00054 
00055 
00056 namespace ogdf {
00057 
00058 
00059 class OGDF_EXPORT MinCostFlowReinelt : public MinCostFlowModule
00060 {
00061 public:
00062     MinCostFlowReinelt() { }
00063 
00064     // computes min-cost flow
00065     // Precond.: graph must be connected, lowerBound[e] <= upperBound[e]
00066     //   for all edges e, sum over all supply[v] equals 0
00067     // returns true iff a feasible min-cost flow exists
00068     bool call(
00069         const Graph &G,                   // directed graph
00070         const EdgeArray<int> &lowerBound, // lower bound for flow
00071         const EdgeArray<int> &upperBound, // upper bound for flow
00072         const EdgeArray<int> &cost,       // cost of an edge
00073         const NodeArray<int> &supply,     // supply (if neg. demand) of a node
00074         EdgeArray<int> &flow);            // computed flow
00075 
00076     bool call(
00077         const Graph &G,                   // directed graph
00078         const EdgeArray<int> &lowerBound, // lower bound for flow
00079         const EdgeArray<int> &upperBound, // upper bound for flow
00080         const EdgeArray<int> &cost,       // cost of an edge
00081         const NodeArray<int> &supply,     // supply (if neg. demand) of a node
00082         EdgeArray<int> &flow,             // computed flow
00083         NodeArray<int> &dual);            // computed dual variables
00084 
00085     int infinity() const { return INT_MAX; }
00086 
00087 private:
00088 
00089     struct arctype;
00090 
00091     struct nodetype {
00092         nodetype *father;     /* ->father in basis tree */
00093         nodetype *successor;  /* ->successor in preorder */
00094         arctype *arc_id;      /* ->arc (node,father) */
00095         bool orientation;     /* false<=>basic arc=(father->node)*/
00096         int dual;             /* value of dual variable */
00097         int flow;             /* flow in basic arc (node,father) */
00098         int name;             /* identification of node = node-nr*/
00099         nodetype *last;       /* last node in subtree */
00100         int nr_of_nodes;      /* number of nodes in subtree */
00101     };
00102 
00103     struct arctype {
00104         arctype *next_arc;    /* -> next arc in list */
00105         nodetype *tail;       /* -> tail of arc */
00106         nodetype *head;       /* -> head of arc */
00107         int cost;             /* cost of unit flow */
00108         int upper_bound;      /* capacity of arc */
00109         int arcnum;           /* number of arc in input */
00110 
00111         OGDF_NEW_DELETE
00112     };
00113 
00114 
00115     int mcf(
00116         int mcfNrNodes,
00117         int mcfNrArcs,
00118         Array<int> &mcfSupply,
00119         Array<int> &mcfTail,
00120         Array<int> &mcfHead,
00121         Array<int> &mcfLb,
00122         Array<int> &mcfUb,
00123         Array<int> &mcfCost,
00124         Array<int> &mcfFlow,
00125         Array<int> &mcfDual,
00126         int *mcfObj
00127     );
00128 
00129     void start(Array<int> &supply);
00130 
00131     void beacircle(arctype **eplus, arctype **pre, bool *from_ub);
00132     void beadouble(arctype **eplus, arctype **pre, bool *from_ub);
00133 
00134 
00135     Array<nodetype> nodes;     /* node space */
00136     Array<arctype> arcs;       /* arc space */
00137     //Array<nodetype *> p;    /*used for starting procedure*/
00138 
00139     nodetype *root;         /*->root of basis tree*/
00140     nodetype rootStruct;
00141 
00142     arctype *last_n1;       /*->start for search for entering arc in N' */
00143     arctype *last_n2;       /*->start for search for entering arc in N''*/
00144     arctype *start_arc;     /* -> initial arc list*/
00145     arctype *start_b;       /* -> first basic arc*/
00146     arctype *start_n1;      /* -> first nonbasic arc in n'*/
00147     arctype *start_n2;      /* -> first nonbasic arc in n''*/
00148     arctype *startsearch;   /* ->start of search for basis entering arc */
00149     arctype *searchend;     /* ->end of search for entering arc in bea */
00150     arctype *searchend_n1;  /*->end of search for entering arc in N' */
00151     arctype *searchend_n2;  /*->end of search for entering arc in N''*/
00152 
00153     //int artvalue;          /*cost and upper_bound of artificial arc */
00154     int m_maxCost;         // maximum of the cost of all input arcs
00155 
00156     int nn;                /*number of original nodes*/
00157     int mm;                /*number of original arcs*/
00158 
00159 };
00160 
00161 
00162 } // end namespace ogdf
00163 
00164 
00165 #endif