Fix division by zero error in case of empty graph (#474)
authorPeter Kovacs <kpeter@inf.elte.hu>
Mon, 19 Aug 2013 22:35:54 +0200
changeset 1317b40c2bbb8da5
parent 991 fb932bcfd803
child 1318 ce1533650f7d
Fix division by zero error in case of empty graph (#474)
lemon/network_simplex.h
test/min_cost_flow_test.cc
     1.1 --- a/lemon/network_simplex.h	Sat Sep 04 23:58:03 2010 +0200
     1.2 +++ b/lemon/network_simplex.h	Mon Aug 19 22:35:54 2013 +0200
     1.3 @@ -929,7 +929,7 @@
     1.4        for (NodeIt n(_graph); n != INVALID; ++n, ++i) {
     1.5          _node_id[n] = i;
     1.6        }
     1.7 -      if (_arc_mixing) {
     1.8 +      if (_arc_mixing && _node_num > 1) {
     1.9          // Store the arcs in a mixed order
    1.10          const int skip = std::max(_arc_num / _node_num, 3);
    1.11          int i = 0, j = 0;
     2.1 --- a/test/min_cost_flow_test.cc	Sat Sep 04 23:58:03 2010 +0200
     2.2 +++ b/test/min_cost_flow_test.cc	Mon Aug 19 22:35:54 2013 +0200
     2.3 @@ -395,6 +395,12 @@
     2.4    mcf3.upperMap(neg2_u);
     2.5    checkMcf(mcf3, mcf3.run(param), neg2_gr, neg2_l, neg2_u, neg2_c, neg2_s,
     2.6             mcf3.OPTIMAL, true,     -300, test_str + "-18", GEQ);
     2.7 +
     2.8 +  // Tests for empty graph
     2.9 +  Digraph gr0;
    2.10 +  MCF mcf0(gr0);
    2.11 +  mcf0.run(param);
    2.12 +  check(mcf0.totalCost() == 0, "Wrong total cost");  
    2.13  }
    2.14  
    2.15  template < typename MCF, typename Param >