Repository navigation
DOC: Add example of floating point handling for maximum_flow capacity - #8761
Merged
dschult merged 3 commits intoJul 17, 2026
Merged
Conversation
amcandio
approved these changes
Jul 15, 2026
rossbar
approved these changes
Jul 16, 2026
Comment on lines
+181
to
+184
| >>> flow_value, _ = nx.maximum_flow( | ||
| ... G, 0, 1, capacity=lambda u, v, d: int(1e6 * d["capacity"]) | ||
| ... ) | ||
| >>> flow_value / 1e6 == 0.9 |
Contributor
There was a problem hiding this comment.
Minor suggestion to bind the precision level to a variable to make it (very slightly) more obvious how it is used both on the flow func and in the rescaling of the result!
Suggested change
| >>> flow_value, _ = nx.maximum_flow( | |
| ... G, 0, 1, capacity=lambda u, v, d: int(1e6 * d["capacity"]) | |
| ... ) | |
| >>> flow_value / 1e6 == 0.9 | |
| >>> prec = 1e6 | |
| >>> flow_value, _ = nx.maximum_flow( | |
| ... G, 0, 1, capacity=lambda u, v, d: int(prec * d["capacity"]) | |
| ... ) | |
| >>> flow_value / prec == 0.9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an example to the doc_string for
maximum_flow. The example shows how one can use thecapacitykwarg as a function to adjust the weights to integers and eliminate round-off errors.This is possible because of #8406 which enabled functions in the
capacitykwarg.There are many other functions where this sort of thing could be done. Perhaps long term we want to discuss floating point errors in one place of the docs and point to it from others. That one place could also point to doc_strings for each suite of functions where one example is housed for that suite. For example, this would be the canonical example for flow and cut functions. Those functions would point to the main page which would explain the trouble and solution as well as house a list of pointers to examples, the "flow and cut" example could be this one.
An example like this first appeared in #8402.