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
Change G(n,p) to accept exact 0 or 1 probabilities #174
Merged
mtreinish
merged 1 commit into
Qiskit:master
from
MoAllabbad:gnp-zero-one-probabilities
Oct 18, 2020
Merged
Change G(n,p) to accept exact 0 or 1 probabilities #174
mtreinish
merged 1 commit into
Qiskit:master
from
MoAllabbad:gnp-zero-one-probabilities
Oct 18, 2020
Conversation
This file contains 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
MoAllabbad
force-pushed
the
gnp-zero-one-probabilities
branch
from
October 18, 2020 09:06
4811965
to
829c0ff
Compare
When p=0, we'll have an empty graph with n nodes and zero edges. When p=1, we'll have a complete graph with n n(n-1) edges for directed graphs and n(n-1)/2 edges for undirected graphs. The time complexity stays the same. Let m be the max number of edges, then run time is O(n+p*m), which reduces to O(n) when p=0 and, when p=1 becomes O(n+n(n-1)) = O(n^2).
Pull Request Test Coverage Report for Build 313529560
💛 - Coveralls |
mtreinish
approved these changes
Oct 18, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, thanks for pushing this up!
mtreinish
added a commit
to mtreinish/retworkx
that referenced
this pull request
Oct 18, 2020
In Qiskit#174 the gnp random functions were extended to support values of 0 and 1 for the probability representing either empty of full graphs. In that change comparisons between the value of probability and 1 were used to check if it's a full graph and we should just fast path adding an edge between every node. However, when running 'cargo clippy' on this it rightfully points out that we should probably check for equality to 1 within an error margin (given that floating point is never exact). Clippy suggested replacing using std::f64::EPSILON as the error value, which is ~2.2e-16 [1] and replacing the comparison with: (probability - 1.0).abs() < error This commit just makes that change. While this is unlikely to cause any issues in practice, because probability is a parameter and if someone is going to want a full graph they'll likely call the function with probability=1 in python. It's better to be safe just in case someone is computing the probability value and could have some error on the value. [1] https://doc.rust-lang.org/std/f64/constant.EPSILON.html
Merged
mtreinish
added a commit
that referenced
this pull request
Oct 18, 2020
In #174 the gnp random functions were extended to support values of 0 and 1 for the probability representing either empty of full graphs. In that change comparisons between the value of probability and 1 were used to check if it's a full graph and we should just fast path adding an edge between every node. However, when running 'cargo clippy' on this it rightfully points out that we should probably check for equality to 1 within an error margin (given that floating point is never exact). Clippy suggested replacing using std::f64::EPSILON as the error value, which is ~2.2e-16 [1] and replacing the comparison with: (probability - 1.0).abs() < error This commit just makes that change. While this is unlikely to cause any issues in practice, because probability is a parameter and if someone is going to want a full graph they'll likely call the function with probability=1 in python. It's better to be safe just in case someone is computing the probability value and could have some error on the value. [1] https://doc.rust-lang.org/std/f64/constant.EPSILON.html
Awesome! Thanks as well. |
MoAllabbad
added a commit
to MoAllabbad/retworkx
that referenced
this pull request
Oct 19, 2020
This adds two G(n,m) graph generators, one directed and one undirected. The generated graph will be a random graph out of all the possible graphs that are n nodes and m edges with max n*(n-1) edges for directed graphs and n*(n-1)/2 for undirected graphs, avoiding self-loops and multigraphs. The run time is O(n+m) Fixes Qiskit#174
mtreinish
pushed a commit
that referenced
this pull request
Oct 19, 2020
* Add G(n,m) random graph generator This adds two G(n,m) graph generators, one directed and one undirected. The generated graph will be a random graph out of all the possible graphs that are n nodes and m edges with max n*(n-1) edges for directed graphs and n*(n-1)/2 for undirected graphs, avoiding self-loops and multigraphs. The run time is O(n+m) Fixes #174 * Change !.is_some() to is_none() Apply suggestions from code review
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.
When p=0, we'll have an empty graph with n nodes and zero edges.
When p=1, we'll have a complete graph with n(n-1) edges
for directed graphs and n(n-1)/2 edges for undirected graphs.
The time complexity stays the same. Let m be the max number of edges,
then run time is O(n+p*m), which reduces to O(n) when p=0 and, when
p=1 becomes O(n+n(n-1)) = O(n^2).
Fixes #172