#16471: The Push-Relabel method for Maximum Flow
-------------------------------------+-------------------------------------
Reporter: foosterhof | Owner:
Type: enhancement | Status: needs_review
Priority: minor | Milestone: sage-6.3
Component: graph theory | Resolution:
Keywords: maximum flow push | Merged in:
relabel | Reviewers:
Authors: | Work issues:
Report Upstream: N/A | Commit:
Branch: | 900e255397b5d5ae977605ced7a4d4f733fe9a22
u/foosterhof/ticket/16471 | Stopgaps:
Dependencies: #16467, #16470 |
-------------------------------------+-------------------------------------
Comment (by foosterhof):
Profiling Code:
{{{
def test_small_graphs(rangeList = xrange(2, 5)):
use_labels = False
value = True
total = 0
set_random_seed(5)
def test_graph(A):
count = 0
for s in xrange(0, n-1):
for t in xrange(0, n-1):
count += 1
if s != t and A.shortest_path(s, t) != []:
f1 = A._ford_fulkerson(s, t, value_only=value,
use_edge_labels= use_labels)
f2 = A._push_relabel(s, t, value_only=value,
use_edge_labels = use_labels)
if abs(f1-f2) > 10**(-14)*f1:
print 'Unequal Flows in graph; Ford-Fulkerson:',
f1, ' - Push-Relabel:', f2, ' - Absolute Error:', abs(f1-f2), ' - Relative
Error:', abs(f1-f2)/f1
return False, A, s, t
return True, None, None, count
for n in rangeList:
for A in graphs(n):
if use_labels:
for e in A.edge_iterator():
A.set_edge_label(e[0],e[1], 1+random()*99)
good, A, s, t = test_graph(A)
if good:
total += t
else:
return False, A, s, t
for A in digraphs(n):
if use_labels:
for e in A.edge_iterator():
A.set_edge_label(e[0],e[1], 1+random()*99)
good, A, s, t = test_graph(A)
if good:
total += t
else:
return False, A, s, t
print 'Done with', n
print 'Done, total number of instances done:', total
return True, None, None, None
def test_random_graphs(size, probability, count):
for i in xrange(count):
G = digraphs.RandomDirectedGNP(size, probability)
if G.shortest_path(0, size-1) != []:
f1, F1 = G._ford_fulkerson(0, size-1, use_edge_labels=True,
value_only=False)
f2, F2 = G._push_relabel(0, size-1, use_edge_labels=True,
value_only=False)
if abs(f1-f2) > 10**(-14)*f1:
print 'Unequal Flows in graph; Ford-Fulkerson:', f1, ' -
Push-Relabel:', f2, ' - Absolute Error:', abs(f1-f2), ' - Relative
Error:', abs(f1-f2)/f1
def test(cmd, sort, num):
import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.run(cmd)
ps = pstats.Stats(pr).strip_dirs().sort_stats(sort).print_stats(num)
}}}
Calling Code:
{{{
test("test_small_graphs([2, 3, 4])", 'cumulative', int(100))
test("test_small_graphs([5])", 'cumulative', int(15))
for size in [10, 20, 50, 100, 200, 500, 1000, 2000]:
for probability in [0.2, 0.4, 0.6, 0.8]:
count = 10000/size
test("test_random_graphs(" + str(size) + "," + str(probability) +
"," + str(count) + ")", 'cumulative', int(8))
}}}
Profiling Data:
[[Image(http://i62.tinypic.com/19wfx5.png)]]
First column after data represents the relative difference.
The second column represents the relative speedup.
--
Ticket URL: <http://trac.sagemath.org/ticket/16471#comment:8>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.