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

Induced bipartite #147

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

Codsilla
Copy link

Added support for induced bipartite subgraphs as discussed in this issue.

src/operators.jl Outdated Show resolved Hide resolved
src/operators.jl Outdated Show resolved Hide resolved
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
Copy link
Contributor

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.

Copy link
Author

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)

Copy link
Member

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

Comment on lines +322 to +328
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
Copy link
Contributor

@simonschoelly simonschoelly Jun 21, 2022

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 than Int

It might also be good to test more than just some properties, namely if the subgraph is actually the one that we wanted.

Copy link
Member

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

src/operators.jl Outdated Show resolved Hide resolved
src/operators.jl Outdated Show resolved Hide resolved
@simonschoelly
Copy link
Contributor

Thanks for your PR :) I added a few comments.

@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

Merging #147 (bf8f0f6) into master (48cb6ec) will increase coverage by 0.64%.
The diff coverage is 100.00%.

@@            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     

@gdalle gdalle added the enhancement New feature or request label Jun 16, 2023
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
Copy link
Member

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!"))
Copy link
Member

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)
Copy link
Member

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


Copy link
Member

Choose a reason for hiding this comment

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

useless diff

Comment on lines +322 to +328
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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants