diff --git a/R/discover.r b/R/discover.r index 545ccd0..32c19b6 100644 --- a/R/discover.r +++ b/R/discover.r @@ -403,7 +403,7 @@ find_LHSs_dfd <- function( ) while (length(seeds) != 0) { - node <- sample(seeds, 1) + node <- seeds[sample.int(length(seeds), 1)] while (!is.na(node)) { if (nodes$visited[node]) { if (nodes$category[node] == 3) { # dependency @@ -660,11 +660,17 @@ generate_next_seeds <- function(max_non_deps, min_deps, lhs_attr_nodes, nodes, d seeds <- attrs_not_in_min_deps[candidate_categories >= 0] }else{ seeds <- integer() - for (nfd in max_non_deps) { + for (n in seq_along(max_non_deps)) { + nfd <- max_non_deps[[n]] max_non_dep_c <- remove_pruned_subsets(lhs_attr_nodes, nfd, nodes$bits) - if (length(seeds) == 0) + # paper condition is "seeds is empty", trimming cross-intersections + # by detset_limit means seeds can be empty before the end, + # which would cause the remaining nfds to start from scratch. + # we therefore just initiate the seeds on the first nfd, as + # intended anyway. + if (n == 1) { seeds <- max_non_dep_c - else { + }else{ seeds <- cross_intersection(seeds, max_non_dep_c, nodes, detset_limit) } } diff --git a/tests/testthat/test-discover.r b/tests/testthat/test-discover.r index 7e148f6..08947ef 100644 --- a/tests/testthat/test-discover.r +++ b/tests/testthat/test-discover.r @@ -693,3 +693,24 @@ describe("discover", { # ) # }) }) + +describe("generate_next_seeds", { + it("generates correctly under a detset limit", { + # example: three attributes, min. dep is whole set {1, 2, 3}, + # max. non-deps are the two-element subsets + # generated seed set is empty, regardless of limit + nodes <- nonempty_powerset(3, use_visited = TRUE) + nodes$category <- as.integer(c(0, -1, -2, 0, -2, -2, 2)) + nodes$visited <- c(FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE) + expect_identical( + generate_next_seeds( + max_non_deps = c(3L, 5L, 6L), + min_deps = 7L, + lhs_attr_nodes = c(1L, 2L, 4L), + nodes = nodes, + detset_limit = 1 + ), + integer() + ) + }) +})