Index: lemon/network_simplex.h
===================================================================
--- lemon/network_simplex.h	(revision 606)
+++ lemon/network_simplex.h	(revision 607)
@@ -50,22 +50,26 @@
   ///
   /// \tparam GR The digraph type the algorithm runs on.
-  /// \tparam V The value type used in the algorithm.
-  /// By default it is \c int.
+  /// \tparam F The value type used for flow amounts, capacity bounds
+  /// and supply values in the algorithm. By default it is \c int.
+  /// \tparam C The value type used for costs and potentials in the
+  /// algorithm. By default it is the same as \c F.
   ///
-  /// \warning The value type must be a signed integer type.
+  /// \warning Both value types must be signed integer types.
   ///
   /// \note %NetworkSimplex provides five different pivot rule
   /// implementations. For more information see \ref PivotRule.
-  template <typename GR, typename V = int>
+  template <typename GR, typename F = int, typename C = F>
   class NetworkSimplex
   {
   public:
 
-    /// The value type of the algorithm
-    typedef V Value;
+    /// The flow type of the algorithm
+    typedef F Flow;
+    /// The cost type of the algorithm
+    typedef C Cost;
     /// The type of the flow map
-    typedef typename GR::template ArcMap<Value> FlowMap;
+    typedef typename GR::template ArcMap<Flow> FlowMap;
     /// The type of the potential map
-    typedef typename GR::template NodeMap<Value> PotentialMap;
+    typedef typename GR::template NodeMap<Cost> PotentialMap;
 
   public:
@@ -118,6 +122,7 @@
     TEMPLATE_DIGRAPH_TYPEDEFS(GR);
 
-    typedef typename GR::template ArcMap<Value> ValueArcMap;
-    typedef typename GR::template NodeMap<Value> ValueNodeMap;
+    typedef typename GR::template ArcMap<Flow> FlowArcMap;
+    typedef typename GR::template ArcMap<Cost> CostArcMap;
+    typedef typename GR::template NodeMap<Flow> FlowNodeMap;
 
     typedef std::vector<Arc> ArcVector;
@@ -125,5 +130,6 @@
     typedef std::vector<int> IntVector;
     typedef std::vector<bool> BoolVector;
-    typedef std::vector<Value> ValueVector;
+    typedef std::vector<Flow> FlowVector;
+    typedef std::vector<Cost> CostVector;
 
     // State constants for arcs
@@ -142,11 +148,11 @@
 
     // Parameters of the problem
-    ValueArcMap *_plower;
-    ValueArcMap *_pupper;
-    ValueArcMap *_pcost;
-    ValueNodeMap *_psupply;
+    FlowArcMap *_plower;
+    FlowArcMap *_pupper;
+    CostArcMap *_pcost;
+    FlowNodeMap *_psupply;
     bool _pstsup;
     Node _psource, _ptarget;
-    Value _pstflow;
+    Flow _pstflow;
 
     // Result maps
@@ -163,9 +169,9 @@
 
     // Node and arc data
-    ValueVector _cap;
-    ValueVector _cost;
-    ValueVector _supply;
-    ValueVector _flow;
-    ValueVector _pi;
+    FlowVector _cap;
+    CostVector _cost;
+    FlowVector _supply;
+    FlowVector _flow;
+    CostVector _pi;
 
     // Data for storing the spanning tree structure
@@ -185,5 +191,5 @@
     int first, second, right, last;
     int stem, par_stem, new_stem;
-    Value delta;
+    Flow delta;
 
   private:
@@ -197,7 +203,7 @@
       const IntVector  &_source;
       const IntVector  &_target;
-      const ValueVector &_cost;
+      const CostVector &_cost;
       const IntVector  &_state;
-      const ValueVector &_pi;
+      const CostVector &_pi;
       int &_in_arc;
       int _arc_num;
@@ -217,5 +223,5 @@
       // Find next entering arc
       bool findEnteringArc() {
-        Value c;
+        Cost c;
         for (int e = _next_arc; e < _arc_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
@@ -248,7 +254,7 @@
       const IntVector  &_source;
       const IntVector  &_target;
-      const ValueVector &_cost;
+      const CostVector &_cost;
       const IntVector  &_state;
-      const ValueVector &_pi;
+      const CostVector &_pi;
       int &_in_arc;
       int _arc_num;
@@ -265,5 +271,5 @@
       // Find next entering arc
       bool findEnteringArc() {
-        Value c, min = 0;
+        Cost c, min = 0;
         for (int e = 0; e < _arc_num; ++e) {
           c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]);
@@ -287,7 +293,7 @@
       const IntVector  &_source;
       const IntVector  &_target;
-      const ValueVector &_cost;
+      const CostVector &_cost;
       const IntVector  &_state;
-      const ValueVector &_pi;
+      const CostVector &_pi;
       int &_in_arc;
       int _arc_num;
@@ -315,5 +321,5 @@
       // Find next entering arc
       bool findEnteringArc() {
-        Value c, min = 0;
+        Cost c, min = 0;
         int cnt = _block_size;
         int e, min_arc = _next_arc;
@@ -359,7 +365,7 @@
       const IntVector  &_source;
       const IntVector  &_target;
-      const ValueVector &_cost;
+      const CostVector &_cost;
       const IntVector  &_state;
-      const ValueVector &_pi;
+      const CostVector &_pi;
       int &_in_arc;
       int _arc_num;
@@ -395,5 +401,5 @@
       /// Find next entering arc
       bool findEnteringArc() {
-        Value min, c;
+        Cost min, c;
         int e, min_arc = _next_arc;
         if (_curr_length > 0 && _minor_count < _minor_limit) {
@@ -464,7 +470,7 @@
       const IntVector  &_source;
       const IntVector  &_target;
-      const ValueVector &_cost;
+      const CostVector &_cost;
       const IntVector  &_state;
-      const ValueVector &_pi;
+      const CostVector &_pi;
       int &_in_arc;
       int _arc_num;
@@ -474,5 +480,5 @@
       int _next_arc;
       IntVector _candidates;
-      ValueVector _cand_cost;
+      CostVector _cand_cost;
 
       // Functor class to compare arcs during sort of the candidate list
@@ -480,7 +486,7 @@
       {
       private:
-        const ValueVector &_map;
+        const CostVector &_map;
       public:
-        SortFunc(const ValueVector &map) : _map(map) {}
+        SortFunc(const CostVector &map) : _map(map) {}
         bool operator()(int left, int right) {
           return _map[left] > _map[right];
@@ -591,7 +597,10 @@
       _node_id(graph)
     {
-      LEMON_ASSERT(std::numeric_limits<Value>::is_integer &&
-                   std::numeric_limits<Value>::is_signed,
-        "The value type of NetworkSimplex must be a signed integer");
+      LEMON_ASSERT(std::numeric_limits<Flow>::is_integer &&
+                   std::numeric_limits<Flow>::is_signed,
+        "The flow type of NetworkSimplex must be signed integer");
+      LEMON_ASSERT(std::numeric_limits<Cost>::is_integer &&
+                   std::numeric_limits<Cost>::is_signed,
+        "The cost type of NetworkSimplex must be signed integer");
     }
 
@@ -610,5 +619,5 @@
     ///
     /// \param map An arc map storing the lower bounds.
-    /// Its \c Value type must be convertible to the \c Value type
+    /// Its \c Value type must be convertible to the \c Flow type
     /// of the algorithm.
     ///
@@ -617,5 +626,5 @@
     NetworkSimplex& lowerMap(const LOWER& map) {
       delete _plower;
-      _plower = new ValueArcMap(_graph);
+      _plower = new FlowArcMap(_graph);
       for (ArcIt a(_graph); a != INVALID; ++a) {
         (*_plower)[a] = map[a];
@@ -630,8 +639,8 @@
     /// and \ref boundMaps() is used before calling \ref run(),
     /// the upper bounds (capacities) will be set to
-    /// \c std::numeric_limits<Value>::max() on all arcs.
+    /// \c std::numeric_limits<Flow>::max() on all arcs.
     ///
     /// \param map An arc map storing the upper bounds.
-    /// Its \c Value type must be convertible to the \c Value type
+    /// Its \c Value type must be convertible to the \c Flow type
     /// of the algorithm.
     ///
@@ -640,5 +649,5 @@
     NetworkSimplex& upperMap(const UPPER& map) {
       delete _pupper;
-      _pupper = new ValueArcMap(_graph);
+      _pupper = new FlowArcMap(_graph);
       for (ArcIt a(_graph); a != INVALID; ++a) {
         (*_pupper)[a] = map[a];
@@ -667,5 +676,5 @@
     /// and \ref boundMaps() is used before calling \ref run(),
     /// the upper bounds (capacities) will be set to
-    /// \c std::numeric_limits<Value>::max() on all arcs.
+    /// \c std::numeric_limits<Flow>::max() on all arcs.
     ///
     /// \param lower An arc map storing the lower bounds.
@@ -673,5 +682,5 @@
     ///
     /// The \c Value type of the maps must be convertible to the
-    /// \c Value type of the algorithm.
+    /// \c Flow type of the algorithm.
     ///
     /// \note This function is just a shortcut of calling \ref lowerMap()
@@ -691,5 +700,5 @@
     ///
     /// \param map An arc map storing the costs.
-    /// Its \c Value type must be convertible to the \c Value type
+    /// Its \c Value type must be convertible to the \c Cost type
     /// of the algorithm.
     ///
@@ -698,5 +707,5 @@
     NetworkSimplex& costMap(const COST& map) {
       delete _pcost;
-      _pcost = new ValueArcMap(_graph);
+      _pcost = new CostArcMap(_graph);
       for (ArcIt a(_graph); a != INVALID; ++a) {
         (*_pcost)[a] = map[a];
@@ -713,5 +722,5 @@
     ///
     /// \param map A node map storing the supply values.
-    /// Its \c Value type must be convertible to the \c Value type
+    /// Its \c Value type must be convertible to the \c Flow type
     /// of the algorithm.
     ///
@@ -721,5 +730,5 @@
       delete _psupply;
       _pstsup = false;
-      _psupply = new ValueNodeMap(_graph);
+      _psupply = new FlowNodeMap(_graph);
       for (NodeIt n(_graph); n != INVALID; ++n) {
         (*_psupply)[n] = map[n];
@@ -742,5 +751,5 @@
     ///
     /// \return <tt>(*this)</tt>
-    NetworkSimplex& stSupply(const Node& s, const Node& t, Value k) {
+    NetworkSimplex& stSupply(const Node& s, const Node& t, Flow k) {
       delete _psupply;
       _psupply = NULL;
@@ -875,5 +884,5 @@
     ///
     /// This function returns the total cost of the found flow.
-    /// The complexity of the function is \f$ O(e) \f$.
+    /// The complexity of the function is O(e).
     ///
     /// \note The return type of the function can be specified as a
@@ -882,5 +891,5 @@
     ///   ns.totalCost<double>();
     /// \endcode
-    /// It is useful if the total cost cannot be stored in the \c Value
+    /// It is useful if the total cost cannot be stored in the \c Cost
     /// type of the algorithm, which is the default return type of the
     /// function.
@@ -901,6 +910,6 @@
 
 #ifndef DOXYGEN
-    Value totalCost() const {
-      return totalCost<Value>();
+    Cost totalCost() const {
+      return totalCost<Cost>();
     }
 #endif
@@ -911,5 +920,5 @@
     ///
     /// \pre \ref run() must be called before using this function.
-    Value flow(const Arc& a) const {
+    Flow flow(const Arc& a) const {
       return (*_flow_map)[a];
     }
@@ -931,5 +940,5 @@
     ///
     /// \pre \ref run() must be called before using this function.
-    Value potential(const Node& n) const {
+    Cost potential(const Node& n) const {
       return (*_potential_map)[n];
     }
@@ -997,5 +1006,5 @@
       }
       if (_psupply) {
-        Value sum = 0;
+        Flow sum = 0;
         int i = 0;
         for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
@@ -1036,4 +1045,6 @@
 
       // Initialize arc maps
+      Flow max_cap = std::numeric_limits<Flow>::max();
+      Cost max_cost = std::numeric_limits<Cost>::max() / 4;
       if (_pupper && _pcost) {
         for (int i = 0; i != _arc_num; ++i) {
@@ -1058,7 +1069,6 @@
             _cap[i] = (*_pupper)[_arc_ref[i]];
         } else {
-          Value val = std::numeric_limits<Value>::max();
           for (int i = 0; i != _arc_num; ++i)
-            _cap[i] = val;
+            _cap[i] = max_cap;
         }
         if (_pcost) {
@@ -1074,5 +1084,5 @@
       if (_plower) {
         for (int i = 0; i != _arc_num; ++i) {
-          Value c = (*_plower)[_arc_ref[i]];
+          Flow c = (*_plower)[_arc_ref[i]];
           if (c != 0) {
             _cap[i] -= c;
@@ -1084,6 +1094,4 @@
 
       // Add artificial arcs and initialize the spanning tree data structure
-      Value max_cap = std::numeric_limits<Value>::max();
-      Value max_cost = std::numeric_limits<Value>::max() / 4;
       for (int u = 0, e = _arc_num; u != _node_num; ++u, ++e) {
         _thread[u] = u + 1;
@@ -1138,5 +1146,5 @@
       delta = _cap[in_arc];
       int result = 0;
-      Value d;
+      Flow d;
       int e;
 
@@ -1176,5 +1184,5 @@
       // Augment along the cycle
       if (delta > 0) {
-        Value val = _state[in_arc] * delta;
+        Flow val = _state[in_arc] * delta;
         _flow[in_arc] += val;
         for (int u = _source[in_arc]; u != join; u = _parent[u]) {
@@ -1317,5 +1325,5 @@
     // Update potentials
     void updatePotential() {
-      Value sigma = _forward[u_in] ?
+      Cost sigma = _forward[u_in] ?
         _pi[v_in] - _pi[u_in] - _cost[_pred[u_in]] :
         _pi[v_in] - _pi[u_in] + _cost[_pred[u_in]];
