-
Notifications
You must be signed in to change notification settings - Fork 47
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
Added DigraphNrStronglyConnectedComponents attribute #180
Added DigraphNrStronglyConnectedComponents attribute #180
Conversation
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.
Doesn’t this technically return a non-negative integer?
I’ll double check this in a bit, but I think I ran it on Digraph([[]]) and it returned 1, so I took it that there must always be at least 1 strongly connected component of a graph. I think that there must always be at least one strongly connected component is consistent with the strongly connected components being partitions of the set of vertices, too? |
Oh, unless I’m overlooking the digraph with no edges or vertices, if that is a thing? If so, I will fix in a moment. |
Yeah I think |
Thanks, I’ll change it in a moment. |
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.
@MTWhyte Thanks for you work 🙂 I've suggested a few small changes
tst/standard/attr.tst
Outdated
@@ -316,6 +316,23 @@ gap> DigraphStronglyConnectedComponents(gr2); | |||
rec( comps := [ [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ], [ 8 ], | |||
[ 9 ], [ 10 ] ], id := [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ) | |||
|
|||
# DigraphNrStronglyConnectedComponents | |||
gap> D := CycleDigraph(10);; | |||
gap> for i in [1 .. 1000] do |
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.
Can you please decrease this number to something much smaller, like 50
or something. For me this code takes almost half a second, and ideally we'd like each standard test file to take only about a second or two in total.
doc/attr.xml
Outdated
<Description> | ||
This function returns the number of strongly connected components of | ||
<A>digraph</A>. Note that this is no more efficient than calling <Ref | ||
Attr="DigraphStronglyConnectedComponents"/>. |
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.
If you intend for this to be the end of a paragraph, you need a <P/>
tag at the end here.
gap/attr.gi
Outdated
InstallMethod(DigraphNrStronglyConnectedComponents, "for a digraph", | ||
[IsDigraph], | ||
function(digraph) | ||
return Length(DigraphStronglyConnectedComponents(digraph).comps); |
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 works fine, but when you have a one line function like this, instead of using three lines as you have, you can write it shorter (and I think it's what we tend to do in the digraphs package):
InstallMethod(DigraphNrStronglyConnectedComponents, "for a digraph",
[IsDigraph],
digraph -> Length(DigraphStronglyConnectedComponents(digraph).comps));
3 | ||
gap> D := Digraph([[]]);; | ||
gap> DigraphNrStronglyConnectedComponents(D); | ||
1 |
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.
Please also add a test for DigraphNrStronglyConnectedComponents(EmptyDigraph(0));
🙂
Thanks for your comments, I've implemented and pushed them :) |
This pull requests adds an attribute DigraphNrStronglyConnectedComponents, which takes a digraph as its argument and returns the number of strongly connected components of the digraph.
The feature was suggested in this issue.