# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1381994977 -7200
# Node ID 330264b171cf7ed09fb3117033abddc4d3ebf74d
# Parent ee9bac10f58e04dfc86f266cae4a1ad968cd8d20
Fix debug checking + simplify lower bound handling (#478)
diff --git a/lemon/capacity_scaling.h b/lemon/capacity_scaling.h
a
|
b
|
|
356 | 356 | _have_lower = true; |
357 | 357 | for (ArcIt a(_graph); a != INVALID; ++a) { |
358 | 358 | _lower[_arc_idf[a]] = map[a]; |
359 | | _lower[_arc_idb[a]] = map[a]; |
360 | 359 | } |
361 | 360 | return *this; |
362 | 361 | } |
… |
… |
|
836 | 835 | return OPTIMAL; |
837 | 836 | } |
838 | 837 | |
839 | | // Check if the upper bound is greater or equal to the lower bound |
840 | | // on each arc. |
| 838 | // Check if the upper bound is greater than or equal to the lower bound |
| 839 | // on each forward arc. |
841 | 840 | bool checkBoundMaps() { |
842 | 841 | for (int j = 0; j != _res_arc_num; ++j) { |
843 | | if (_upper[j] < _lower[j]) return false; |
| 842 | if (_forward[j] && _upper[j] < _lower[j]) return false; |
844 | 843 | } |
845 | 844 | return true; |
846 | 845 | } |
… |
… |
|
857 | 856 | if (_have_lower) { |
858 | 857 | int limit = _first_out[_root]; |
859 | 858 | for (int j = 0; j != limit; ++j) { |
860 | | if (!_forward[j]) _res_cap[j] += _lower[j]; |
| 859 | if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; |
861 | 860 | } |
862 | 861 | } |
863 | 862 | |
diff --git a/lemon/cost_scaling.h b/lemon/cost_scaling.h
a
|
b
|
|
370 | 370 | _have_lower = true; |
371 | 371 | for (ArcIt a(_graph); a != INVALID; ++a) { |
372 | 372 | _lower[_arc_idf[a]] = map[a]; |
373 | | _lower[_arc_idb[a]] = map[a]; |
374 | 373 | } |
375 | 374 | return *this; |
376 | 375 | } |
… |
… |
|
902 | 901 | return OPTIMAL; |
903 | 902 | } |
904 | 903 | |
905 | | // Check if the upper bound is greater or equal to the lower bound |
906 | | // on each arc. |
| 904 | // Check if the upper bound is greater than or equal to the lower bound |
| 905 | // on each forward arc. |
907 | 906 | bool checkBoundMaps() { |
908 | 907 | for (int j = 0; j != _res_arc_num; ++j) { |
909 | | if (_upper[j] < _lower[j]) return false; |
| 908 | if (_forward[j] && _upper[j] < _lower[j]) return false; |
910 | 909 | } |
911 | 910 | return true; |
912 | 911 | } |
… |
… |
|
989 | 988 | if (_have_lower) { |
990 | 989 | int limit = _first_out[_root]; |
991 | 990 | for (int j = 0; j != limit; ++j) { |
992 | | if (!_forward[j]) _res_cap[j] += _lower[j]; |
| 991 | if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; |
993 | 992 | } |
994 | 993 | } |
995 | 994 | } |
diff --git a/lemon/cycle_canceling.h b/lemon/cycle_canceling.h
a
|
b
|
|
281 | 281 | _have_lower = true; |
282 | 282 | for (ArcIt a(_graph); a != INVALID; ++a) { |
283 | 283 | _lower[_arc_idf[a]] = map[a]; |
284 | | _lower[_arc_idb[a]] = map[a]; |
285 | 284 | } |
286 | 285 | return *this; |
287 | 286 | } |
… |
… |
|
784 | 783 | return OPTIMAL; |
785 | 784 | } |
786 | 785 | |
787 | | // Check if the upper bound is greater or equal to the lower bound |
788 | | // on each arc. |
| 786 | // Check if the upper bound is greater than or equal to the lower bound |
| 787 | // on each forward arc. |
789 | 788 | bool checkBoundMaps() { |
790 | 789 | for (int j = 0; j != _res_arc_num; ++j) { |
791 | | if (_upper[j] < _lower[j]) return false; |
| 790 | if (_forward[j] && _upper[j] < _lower[j]) return false; |
792 | 791 | } |
793 | 792 | return true; |
794 | 793 | } |
… |
… |
|
838 | 837 | if (_have_lower) { |
839 | 838 | int limit = _first_out[_root]; |
840 | 839 | for (int j = 0; j != limit; ++j) { |
841 | | if (!_forward[j]) _res_cap[j] += _lower[j]; |
| 840 | if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; |
842 | 841 | } |
843 | 842 | } |
844 | 843 | } |
diff --git a/lemon/network_simplex.h b/lemon/network_simplex.h
a
|
b
|
|
1235 | 1235 | return true; |
1236 | 1236 | } |
1237 | 1237 | |
1238 | | // Check if the upper bound is greater or equal to the lower bound |
| 1238 | // Check if the upper bound is greater than or equal to the lower bound |
1239 | 1239 | // on each arc. |
1240 | 1240 | bool checkBoundMaps() { |
1241 | 1241 | for (int j = 0; j != _arc_num; ++j) { |
# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1381995057 -7200
# Node ID c0c2f5c87aa648bc03a301c4443797ea80b6b83d
# Parent 330264b171cf7ed09fb3117033abddc4d3ebf74d
Rename field in min cost flow codes (#478)
diff --git a/lemon/capacity_scaling.h b/lemon/capacity_scaling.h
a
|
b
|
|
160 | 160 | int _root; |
161 | 161 | |
162 | 162 | // Parameters of the problem |
163 | | bool _have_lower; |
| 163 | bool _has_lower; |
164 | 164 | Value _sum_supply; |
165 | 165 | |
166 | 166 | // Data structures for storing the digraph |
… |
… |
|
353 | 353 | /// \return <tt>(*this)</tt> |
354 | 354 | template <typename LowerMap> |
355 | 355 | CapacityScaling& lowerMap(const LowerMap& map) { |
356 | | _have_lower = true; |
| 356 | _has_lower = true; |
357 | 357 | for (ArcIt a(_graph); a != INVALID; ++a) { |
358 | 358 | _lower[_arc_idf[a]] = map[a]; |
359 | 359 | } |
… |
… |
|
539 | 539 | _upper[j] = INF; |
540 | 540 | _cost[j] = _forward[j] ? 1 : -1; |
541 | 541 | } |
542 | | _have_lower = false; |
| 542 | _has_lower = false; |
543 | 543 | return *this; |
544 | 544 | } |
545 | 545 | |
… |
… |
|
750 | 750 | // Remove non-zero lower bounds |
751 | 751 | const Value MAX = std::numeric_limits<Value>::max(); |
752 | 752 | int last_out; |
753 | | if (_have_lower) { |
| 753 | if (_has_lower) { |
754 | 754 | for (int i = 0; i != _root; ++i) { |
755 | 755 | last_out = _first_out[i+1]; |
756 | 756 | for (int j = _first_out[i]; j != last_out; ++j) { |
… |
… |
|
853 | 853 | pt = startWithoutScaling(); |
854 | 854 | |
855 | 855 | // Handle non-zero lower bounds |
856 | | if (_have_lower) { |
| 856 | if (_has_lower) { |
857 | 857 | int limit = _first_out[_root]; |
858 | 858 | for (int j = 0; j != limit; ++j) { |
859 | 859 | if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; |
diff --git a/lemon/cost_scaling.h b/lemon/cost_scaling.h
a
|
b
|
|
251 | 251 | int _root; |
252 | 252 | |
253 | 253 | // Parameters of the problem |
254 | | bool _have_lower; |
| 254 | bool _has_lower; |
255 | 255 | Value _sum_supply; |
256 | 256 | int _sup_node_num; |
257 | 257 | |
… |
… |
|
367 | 367 | /// \return <tt>(*this)</tt> |
368 | 368 | template <typename LowerMap> |
369 | 369 | CostScaling& lowerMap(const LowerMap& map) { |
370 | | _have_lower = true; |
| 370 | _has_lower = true; |
371 | 371 | for (ArcIt a(_graph); a != INVALID; ++a) { |
372 | 372 | _lower[_arc_idf[a]] = map[a]; |
373 | 373 | } |
… |
… |
|
562 | 562 | _scost[j] = 0; |
563 | 563 | _scost[_reverse[j]] = 0; |
564 | 564 | } |
565 | | _have_lower = false; |
| 565 | _has_lower = false; |
566 | 566 | return *this; |
567 | 567 | } |
568 | 568 | |
… |
… |
|
774 | 774 | // Remove infinite upper bounds and check negative arcs |
775 | 775 | const Value MAX = std::numeric_limits<Value>::max(); |
776 | 776 | int last_out; |
777 | | if (_have_lower) { |
| 777 | if (_has_lower) { |
778 | 778 | for (int i = 0; i != _root; ++i) { |
779 | 779 | last_out = _first_out[i+1]; |
780 | 780 | for (int j = _first_out[i]; j != last_out; ++j) { |
… |
… |
|
831 | 831 | for (NodeIt n(_graph); n != INVALID; ++n) { |
832 | 832 | sup[n] = _supply[_node_id[n]]; |
833 | 833 | } |
834 | | if (_have_lower) { |
| 834 | if (_has_lower) { |
835 | 835 | for (ArcIt a(_graph); a != INVALID; ++a) { |
836 | 836 | int j = _arc_idf[a]; |
837 | 837 | Value c = _lower[j]; |
… |
… |
|
985 | 985 | } |
986 | 986 | |
987 | 987 | // Handle non-zero lower bounds |
988 | | if (_have_lower) { |
| 988 | if (_has_lower) { |
989 | 989 | int limit = _first_out[_root]; |
990 | 990 | for (int j = 0; j != limit; ++j) { |
991 | 991 | if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; |
diff --git a/lemon/cycle_canceling.h b/lemon/cycle_canceling.h
a
|
b
|
|
195 | 195 | int _root; |
196 | 196 | |
197 | 197 | // Parameters of the problem |
198 | | bool _have_lower; |
| 198 | bool _has_lower; |
199 | 199 | Value _sum_supply; |
200 | 200 | |
201 | 201 | // Data structures for storing the digraph |
… |
… |
|
278 | 278 | /// \return <tt>(*this)</tt> |
279 | 279 | template <typename LowerMap> |
280 | 280 | CycleCanceling& lowerMap(const LowerMap& map) { |
281 | | _have_lower = true; |
| 281 | _has_lower = true; |
282 | 282 | for (ArcIt a(_graph); a != INVALID; ++a) { |
283 | 283 | _lower[_arc_idf[a]] = map[a]; |
284 | 284 | } |
… |
… |
|
470 | 470 | _cost[j] = 0; |
471 | 471 | _cost[_reverse[j]] = 0; |
472 | 472 | } |
473 | | _have_lower = false; |
| 473 | _has_lower = false; |
474 | 474 | return *this; |
475 | 475 | } |
476 | 476 | |
… |
… |
|
683 | 683 | // Remove infinite upper bounds and check negative arcs |
684 | 684 | const Value MAX = std::numeric_limits<Value>::max(); |
685 | 685 | int last_out; |
686 | | if (_have_lower) { |
| 686 | if (_has_lower) { |
687 | 687 | for (int i = 0; i != _root; ++i) { |
688 | 688 | last_out = _first_out[i+1]; |
689 | 689 | for (int j = _first_out[i]; j != last_out; ++j) { |
… |
… |
|
726 | 726 | for (NodeIt n(_graph); n != INVALID; ++n) { |
727 | 727 | sup[n] = _supply[_node_id[n]]; |
728 | 728 | } |
729 | | if (_have_lower) { |
| 729 | if (_has_lower) { |
730 | 730 | for (ArcIt a(_graph); a != INVALID; ++a) { |
731 | 731 | int j = _arc_idf[a]; |
732 | 732 | Value c = _lower[j]; |
… |
… |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | // Handle non-zero lower bounds |
837 | | if (_have_lower) { |
| 837 | if (_has_lower) { |
838 | 838 | int limit = _first_out[_root]; |
839 | 839 | for (int j = 0; j != limit; ++j) { |
840 | 840 | if (_forward[j]) _res_cap[_reverse[j]] += _lower[j]; |
diff --git a/lemon/network_simplex.h b/lemon/network_simplex.h
a
|
b
|
|
198 | 198 | int _search_arc_num; |
199 | 199 | |
200 | 200 | // Parameters of the problem |
201 | | bool _have_lower; |
| 201 | bool _has_lower; |
202 | 202 | SupplyType _stype; |
203 | 203 | Value _sum_supply; |
204 | 204 | |
… |
… |
|
682 | 682 | /// \return <tt>(*this)</tt> |
683 | 683 | template <typename LowerMap> |
684 | 684 | NetworkSimplex& lowerMap(const LowerMap& map) { |
685 | | _have_lower = true; |
| 685 | _has_lower = true; |
686 | 686 | for (ArcIt a(_graph); a != INVALID; ++a) { |
687 | 687 | _lower[_arc_id[a]] = map[a]; |
688 | 688 | } |
… |
… |
|
879 | 879 | _upper[i] = INF; |
880 | 880 | _cost[i] = 1; |
881 | 881 | } |
882 | | _have_lower = false; |
| 882 | _has_lower = false; |
883 | 883 | _stype = GEQ; |
884 | 884 | return *this; |
885 | 885 | } |
… |
… |
|
1072 | 1072 | "Upper bounds must be greater or equal to the lower bounds"); |
1073 | 1073 | |
1074 | 1074 | // Remove non-zero lower bounds |
1075 | | if (_have_lower) { |
| 1075 | if (_has_lower) { |
1076 | 1076 | for (int i = 0; i != _arc_num; ++i) { |
1077 | 1077 | Value c = _lower[i]; |
1078 | 1078 | if (c >= 0) { |
… |
… |
|
1612 | 1612 | } |
1613 | 1613 | |
1614 | 1614 | // Transform the solution and the supply map to the original form |
1615 | | if (_have_lower) { |
| 1615 | if (_has_lower) { |
1616 | 1616 | for (int i = 0; i != _arc_num; ++i) { |
1617 | 1617 | Value c = _lower[i]; |
1618 | 1618 | if (c != 0) { |