https://github.com/euxhenh/multiset-multicover
Multiset multicover using the extended greedy cover algorithm implemented in C++ and exposed to Python.
https://github.com/euxhenh/multiset-multicover
cover cpp multiset python set set-cover set-cover-problem
Last synced: about 4 hours ago
JSON representation
Multiset multicover using the extended greedy cover algorithm implemented in C++ and exposed to Python.
- Host: GitHub
- URL: https://github.com/euxhenh/multiset-multicover
- Owner: euxhenh
- License: mit
- Created: 2021-12-22T11:49:04.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-07T19:57:12.000Z (over 3 years ago)
- Last Synced: 2025-02-16T09:39:06.462Z (about 1 year ago)
- Topics: cover, cpp, multiset, python, set, set-cover, set-cover-problem
- Language: C++
- Homepage:
- Size: 67.4 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. role:: python(code)
:language: python
This package implements the Greedy Cover algorithm for multisets
in `C++` and exposes it to Python.
Given a universe of elements U, and a family of subsets F = {S1, ..., Sn}
of U, the set cover problem asks to find the smallest number of sets in F
such that every element of U appears in at least one such set.
This can be extended to a multicover problem, where we ask that
every element be included at least k sets. This in turn, can be extended
to accomodate multisets, where each element in Si also has a given
multiplicity.
The set cover problem is NP hard. The best known algorithm
is a greedy approach that iteratively selects the set with the largest
number of elements that have not been covered yet. This algorithm
has a log(n)-approximation guarantee where n is the size of the largest set.
The same guarantee also applies to the multicover problem, as well as the
multiset multicover problem (n here corresponds to the size of the largest
set, counting multiplicities).
Basic Example
________
To run the greedy cover algorithm, one needs to create a GreedyCoverInstance
object and add multisets to it. The coverage factor can be a single integer
or a specific integer for each element in U.
The solution is a list of integers corresponding to the index of the sets
included (in order of selection).
NOTE: Make sure any numpy arrays are converted to lists by calling :python:`arr.tolist()`.
>>> import multiset_multicover as mm
>>> gci = mm.GreedyCoverInstance(4)
>>> gci.add_multiset([1, 2, 3]) # if no multiplicity provided, it defaults to 1
>>> gci.add_multiset([0, 1, 2], multiplicity=[2, 3, 1])
>>> gci.add_multiset([0, 1, 2, 3])
>>> gci.cover(1)
Output: [2]
>>> gci.cover([2, 1, 1, 1])
Output: [1, 0]
For more detailed explanation see `doc `__.
Installation
____________
To install this package, run
.. code:: bash
$ pip install multiset-multicover