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

feat: rework is_bipartite to do an actual bipartivity check #1729

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,31 @@ is_weighted <- function(graph) {
is_bipartite <- function(graph) {
ensure_igraph(graph)

"type" %in% vertex_attr_names(graph)
has_type_attr <- "type" %in% vertex_attr_names(graph)

bipartite_result <- bipartite_mapping(graph)

if (has_type_attr) {
if (!bipartite_result$res) {
cli::cli_warn("{.arg graph} has a type attribute but is not actually bipartite.")
FALSE
} else {
if (!all(bipartite_result$type == vertex_attr(graph, "type")) & !all(bipartite_result$type == !vertex_attr(graph, "type"))) {
cli::cli_warn("{.arg graph} is bipartite but has a wrong 'type' vertex attribute. You can correct it using:\n {.code V(graph)$type <- bipartite_mapping(graph)$type}")
}
TRUE
}
} else {
if (bipartite_result$res) {
cli::cli_warn("{.arg graph} is bipartite but has no 'type' vertex attribute. You can add it using:\n {.code V(graph)$type <- bipartite_mapping(graph)$type}")
TRUE
} else {
FALSE
}
}
}


#############

igraph.i.attribute.combination <- function(comb) {
Expand Down
Loading