diff --git a/DESCRIPTION b/DESCRIPTION index cd45aa5..0cc0c5a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mwcsr Title: Solvers for Maximum Weight Connected Subgraph Problem and Its Variants -Version: 0.1.11 +Version: 0.1.12 Authors@R: c(person("Alexander", "Loboda", email = "aleks.loboda@gmail.com", role = c("aut", "cre")), person("Nikolay", "Poperechnyi", email = "n.poperechnyi@gmail.com", role = "aut"), person("Eduardo", "Alvarez-Miranda", email = "ealvarez@utalca.cl", role = "aut"), diff --git a/R/rnc_sgmwcs.R b/R/rnc_sgmwcs.R index c9afdaf..9b2786f 100644 --- a/R/rnc_sgmwcs.R +++ b/R/rnc_sgmwcs.R @@ -56,6 +56,7 @@ solve_mwcsp.rnc_solver <- function(solver, instance, ...) { if (length(res$edges) == 0) { g <- igraph::induced_subgraph(instance, vids = res$vertices) + g <- igraph::delete_edges(g, igraph::E(g)) } else { g <- igraph::subgraph_from_edges(instance, eids = res$edges) } diff --git a/tests/testthat/test_rnc.R b/tests/testthat/test_rnc.R index ad4be84..70fda27 100644 --- a/tests/testthat/test_rnc.R +++ b/tests/testthat/test_rnc.R @@ -37,6 +37,16 @@ test_that("rnc solver handles non-integer signal weights in single-vertex soluti expect_equal(solution$weight, 2.193558) }) +test_that("rnc solver handles self-loops with negative signal weights (#13)", { + solver <- rnc_solver(max_iterations=50) + g <- igraph::make_graph(c(1, 1), directed=FALSE) # loop + V(g)$signal <- "s1" + E(g)$signal <- "s2" + g$signals <- c(s1=0, s2=-1) + solution <- solve_mwcsp(solver, g) + expect_equal(solution$weight, 0) +}) + test_that("sgmwcs rnc solver gives good solution for a GAM instance", { rnc <- rnc_solver(max_iterations = 100) solution <- solve_mwcsp(rnc, gmwcs_example)