Title: Greedy Set Cover
Version: 0.1.0
Description: A fast implementation of the greedy algorithm for the set cover problem using 'Rcpp'.
Depends: R (≥ 3.2.5)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
SystemRequirements: C++11
Imports: data.table, Rcpp (≥ 0.12.14)
LinkingTo: BH, Rcpp (≥ 0.12.14)
URL: http://github.com/matthiaskaeding/RcppGreedySetCover
BugReports: http://github.com/matthiaskaeding/RcppGreedySetCover/issues
RoxygenNote: 6.0.1
NeedsCompilation: yes
Packaged: 2018-01-24 07:57:05 UTC; mkaeding
Author: Matthias Kaeding [aut, cre]
Maintainer: Matthias Kaeding <matthiaskaeding@posteo.de>
Repository: CRAN
Date/Publication: 2018-01-24 12:41:12 UTC

Fast Greedy Set Cover

Description

This package offers an implementation of the greedy algorithm for the set cover problem using Rcpp.

Set Cover Problem

We are given a universe of elements U and F, a collection of subsets from U, covering U; i.e. U is in the union of the sets in F. The objective is to find A, the smallest subcollection of F, covering U. An important application is hospital placement, where the number of hospitals is minimized under the constraint that all residents are provided for.

The optimal solution to the problem is available via linear programming, however this is not a feasible solution for large problems due to the computational demands involved. A quick approximate solution is given by the greedy algorithm. The algorithm iterates the following steps until all elements are covered, starting from an empty A:

This simple algorithm exhibits surprisingly good properties. For a nice introduction to the set cover problem and the greedy algorithm see Vazirani, 2001.

References

Vazirani, Vijay V. (2001), Approximation Algorithms, Springer


Greedy Set Cover

Description

Fast greedy set cover algorithm.

Usage

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

# 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)))

mirror server hosted at Truenetwork, Russian Federation.