greedySetCover: Greedy Set Cover

Description Usage Arguments Value Examples

Description

Fast greedy set cover algorithm.

Usage

1
greedySetCover(X, data.table = TRUE)

Arguments

X

Two-column data.frame in long format: Column 1 identifies the sets, column 2 the elements.

data.table

If TRUE returns a data.table with keys given by sets and elements. If FALSE returns a data.frame, sorted by sets and elements.

Value

If data.table == TRUE a data.table, keyed by sets and elements. Else a data.frame, sorted by sets and elements. Column names are derived from input.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Create some data.
set.seed(333)
X <- data.table::rbindlist(
  lapply(
    seq_len(1e4L),
    function(x) list(element=sample.int(n=1e3L,size=sample.int(50L,1L)))
  ),
  idcol="set"
)
# Elements are integers 1,2,...,1000.

# Run set cover
res <- greedySetCover(X,FALSE)
head(res)

# Check if all elements are covered.
identical(sort(unique(res$element)),sort(unique(X$element)))

Example output

100% covered by 46 sets.
  set element
1  71       7
2  71      28
3  71      40
4  71      42
5  71      55
6  71     111
[1] TRUE

RcppGreedySetCover documentation built on May 1, 2019, 9:13 p.m.