Changeset 2629:84354c78b068 in lemon-0.x for lemon/network_simplex.h
- Timestamp:
- 11/13/08 16:29:04 (15 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3514
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/network_simplex.h
r2628 r2629 612 612 _node_ref(graph), _edge_ref(graph) 613 613 { 614 // Check ingthe sum of supply values614 // Check the sum of supply values 615 615 Supply sum = 0; 616 616 for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n) … … 618 618 if (!(_valid_supply = sum == 0)) return; 619 619 620 // Copy ing_graph_ref to _graph620 // Copy _graph_ref to _graph 621 621 _graph.reserveNode(countNodes(_graph_ref) + 1); 622 622 _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref)); 623 623 copyGraph(_graph, _graph_ref) 624 .edgeMap(_capacity, capacity) 624 625 .edgeMap(_cost, cost) 626 .nodeMap(_supply, supply) 625 627 .nodeRef(_node_ref) 626 628 .edgeRef(_edge_ref) 627 629 .run(); 628 630 629 // Remov ingnon-zero lower bounds631 // Remove non-zero lower bounds 630 632 for (typename Graph::EdgeIt e(_graph_ref); e != INVALID; ++e) { 633 if (lower[e] != 0) { 631 634 _capacity[_edge_ref[e]] = capacity[e] - lower[e]; 632 } 633 for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n) { 634 Supply s = supply[n]; 635 for (typename Graph::InEdgeIt e(_graph_ref, n); e != INVALID; ++e) 636 s += lower[e]; 637 for (typename Graph::OutEdgeIt e(_graph_ref, n); e != INVALID; ++e) 638 s -= lower[e]; 639 _supply[_node_ref[n]] = s; 635 _supply[_node_ref[_graph_ref.source(e)]] -= lower[e]; 636 _supply[_node_ref[_graph_ref.target(e)]] += lower[e]; 637 } 640 638 } 641 639 } … … 662 660 _node_ref(graph), _edge_ref(graph) 663 661 { 664 // Check ingthe sum of supply values662 // Check the sum of supply values 665 663 Supply sum = 0; 666 664 for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n) … … 668 666 if (!(_valid_supply = sum == 0)) return; 669 667 670 // Copying _graph_ref to graph 668 // Copy _graph_ref to _graph 669 _graph.reserveNode(countNodes(_graph_ref) + 1); 670 _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref)); 671 671 copyGraph(_graph, _graph_ref) 672 672 .edgeMap(_capacity, capacity) … … 698 698 typename SupplyMap::Value flow_value ) : 699 699 _graph(), _graph_ref(graph), _lower(&lower), _capacity(_graph), 700 _cost(_graph), _supply(_graph ), _flow(_graph),700 _cost(_graph), _supply(_graph, 0), _flow(_graph), 701 701 _potential(_graph), _depth(_graph), _parent(_graph), 702 702 _pred_edge(_graph), _thread(_graph), _forward(_graph), … … 706 706 _node_ref(graph), _edge_ref(graph) 707 707 { 708 // Copying _graph_ref to graph 708 // Copy _graph_ref to graph 709 _graph.reserveNode(countNodes(_graph_ref) + 1); 710 _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref)); 709 711 copyGraph(_graph, _graph_ref) 712 .edgeMap(_capacity, capacity) 710 713 .edgeMap(_cost, cost) 711 714 .nodeRef(_node_ref) … … 713 716 .run(); 714 717 715 // Removing non-zero lower bounds 718 // Remove non-zero lower bounds 719 _supply[_node_ref[s]] = flow_value; 720 _supply[_node_ref[t]] = -flow_value; 716 721 for (typename Graph::EdgeIt e(_graph_ref); e != INVALID; ++e) { 722 if (lower[e] != 0) { 717 723 _capacity[_edge_ref[e]] = capacity[e] - lower[e]; 718 } 719 for (typename Graph::NodeIt n(_graph_ref); n != INVALID; ++n) { 720 Supply sum = 0; 721 if (n == s) sum = flow_value; 722 if (n == t) sum = -flow_value; 723 for (typename Graph::InEdgeIt e(_graph_ref, n); e != INVALID; ++e) 724 sum += lower[e]; 725 for (typename Graph::OutEdgeIt e(_graph_ref, n); e != INVALID; ++e) 726 sum -= lower[e]; 727 _supply[_node_ref[n]] = sum; 724 _supply[_node_ref[_graph_ref.source(e)]] -= lower[e]; 725 _supply[_node_ref[_graph_ref.target(e)]] += lower[e]; 726 } 728 727 } 729 728 _valid_supply = true; … … 756 755 _node_ref(graph), _edge_ref(graph) 757 756 { 758 // Copying _graph_ref to graph 757 // Copy _graph_ref to graph 758 _graph.reserveNode(countNodes(_graph_ref) + 1); 759 _graph.reserveEdge(countEdges(_graph_ref) + countNodes(_graph_ref)); 759 760 copyGraph(_graph, _graph_ref) 760 761 .edgeMap(_capacity, capacity)
Note: See TracChangeset
for help on using the changeset viewer.