Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve method _ford fulkerson chronicle in src/sage/combinat/posets/posets.py #37571

Merged
merged 2 commits into from
Mar 31, 2024

Conversation

dcoudert
Copy link
Contributor

@dcoudert dcoudert commented Mar 9, 2024

We relabel the internal digraph to integers in range 0..n-1 and associate each edge an index in range 0..m-1 to use less dictionaries.

We also do some minor changes in posets.py.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

@dcoudert
Copy link
Contributor Author

dcoudert commented Mar 9, 2024

An intriguing question is that posets are sometimes created using an immutable digraph and sometimes not. Should we unify that ?

Copy link

github-actions bot commented Mar 9, 2024

Documentation preview for this PR (built with commit 58b8506; changes) is ready! 🎉

Copy link
Contributor

@fchapoton fchapoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ca m'a l'air correct. C'est plus rapide ?

@dcoudert
Copy link
Contributor Author

ca m'a l'air correct. C'est plus rapide ?

Dans mes petits tests c'est mieux mais pas une révolution. Il faudrait voir avec des exemples plus gros.

With the example of the doctest:

sage: from sage.combinat.posets.posets import _ford_fulkerson_chronicle
sage: G = DiGraph({1: [3, 6, 7], 2: [4], 3: [7], 4: [], 6: [7, 8],
....:              7: [9], 8: [9, 12], 9: [], 10: [], 12: []})
sage: s = 1
sage: t = 9
sage: (1, 6, None) in G.edges(sort=False)
True
sage: (1, 6) in G.edges(sort=False)
False
sage: a = {(1, 6): 4, (2, 4): 0, (1, 3): 4, (1, 7): 1, (3, 7): 6,
....:      (7, 9): 1, (6, 7): 3, (6, 8): 1, (8, 9): 0, (8, 12): 2}
sage: def B(G, s, t, a, n):
....:     ffc = _ford_fulkerson_chronicle(G, s, t, a)
....:     for _ in range(n):
....:         _ = next(ffc)

Before:

sage: %time B(G, s, t, a, 10)
CPU times: user 560 µs, sys: 86 µs, total: 646 µs
Wall time: 649 µs
sage: %time B(G, s, t, a, 100)
CPU times: user 3.54 ms, sys: 0 ns, total: 3.54 ms
Wall time: 3.54 ms
sage: %time B(G, s, t, a, 1000)
CPU times: user 20.9 ms, sys: 765 µs, total: 21.7 ms
Wall time: 21 ms

After

sage: %time B(G, s, t, a, 10)
CPU times: user 310 µs, sys: 131 µs, total: 441 µs
Wall time: 443 µs
sage: %time B(G, s, t, a, 100)
CPU times: user 1.77 ms, sys: 22 µs, total: 1.79 ms
Wall time: 1.79 ms
sage: %time B(G, s, t, a, 1000)
CPU times: user 12.7 ms, sys: 459 µs, total: 13.1 ms
Wall time: 12.7 ms

@vbraun vbraun merged commit 4e69608 into sagemath:develop Mar 31, 2024
19 checks passed
@mkoeppe mkoeppe added this to the sage-10.4 milestone Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants