-
Notifications
You must be signed in to change notification settings - Fork 91
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
Induced bipartite #147
base: master
Are you sure you want to change the base?
Induced bipartite #147
Conversation
Return the bipartite subgraph of `g` induced by the disjoint subsets of vertices X and Y. | ||
|
||
""" | ||
function induced_bipartite_subgraph(g::T,X::AbstractVector{U},Y::AbstractVector{U}) where T <: AbstractGraph where U <: Integer |
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.
From convention it would be better to use G
instead of T
for the graph type. Furthermore, as far as I understand, this method would not work on any kind of AbstractGraph
, only on SimpleGraph
and SimpleDiGraph
. So I would restrict it to these types of graphs.
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.
I copied the style of induced_subgraph
that also uses T
for the graph type. If this is more consistent with the convention, I can change it. Also, we could follow what's been done for induced_subgraph
which also returns a mapping from the subgraph to the whole graph. This solution would let people use this function for any AbstractGraph (for example, using the mapping to retrieve information in a metagraph)
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.
I think following induced_subgraph
is a good idea for the mapping, for the types I'd go with G
g10 = complete_graph(10) | ||
@testset "Induced bipartite Subgraphs: $g" for g in testgraphs(g10) | ||
sg = @inferred(induced_bipartite_subgraph(g, [2,3],[4,5])) | ||
@test nv(sg) == 4 | ||
@test ne(sg) == 4 | ||
@test is_bipartite(sg) | ||
end |
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.
While this is good, I think we need a few more test cases, e.g.
- For empty graphs
- For graphs with self-loops
- For graphs that are not complete graphs
- For directed graphs
- For cases, where an exception is being thrown
- For
U
of different type thanInt
It might also be good to test more than just some properties, namely if the subgraph is actually the one that we wanted.
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.
I agree that more tests would be nice
Thanks for your PR :) I added a few comments. |
Codecov Report
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
+ Coverage 97.54% 98.19% +0.64%
==========================================
Files 109 109
Lines 6314 5757 -557
==========================================
- Hits 6159 5653 -506
+ Misses 155 104 -51 |
Return the bipartite subgraph of `g` induced by the disjoint subsets of vertices X and Y. | ||
|
||
""" | ||
function induced_bipartite_subgraph(g::T,X::AbstractVector{U},Y::AbstractVector{U}) where T <: AbstractGraph where U <: Integer |
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.
I think following induced_subgraph
is a good idea for the mapping, for the types I'd go with G
""" | ||
function induced_bipartite_subgraph(g::T,X::AbstractVector{U},Y::AbstractVector{U}) where T <: AbstractGraph where U <: Integer | ||
|
||
X ∩ Y != [] && throw(ArgumentError("X and Y sould not intersect!")) |
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.
would this ever be satisfied with an untyped array? better to test the length
|
||
|
||
n = length(X) + length(Y) | ||
G = T(n) |
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.
no guarantee this constructor exists (I'm not sure how we solve that though)
@@ -308,6 +308,7 @@ | |||
@test sort(vm) == [1:5;] | |||
end | |||
|
|||
|
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.
useless diff
g10 = complete_graph(10) | ||
@testset "Induced bipartite Subgraphs: $g" for g in testgraphs(g10) | ||
sg = @inferred(induced_bipartite_subgraph(g, [2,3],[4,5])) | ||
@test nv(sg) == 4 | ||
@test ne(sg) == 4 | ||
@test is_bipartite(sg) | ||
end |
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.
I agree that more tests would be nice
Added support for induced bipartite subgraphs as discussed in this issue.