14 std::vector<bool> selection(id_map.size() - size,
false);
15 selection.resize(id_map.size(),
true);
19 for (std::size_t
id = 0;
id < selection.size(); ++id) {
21 covered |= sc.
get_set(id_map[
id]);
26 for (std::size_t
id = 0;
id < selection.size(); ++id) {
27 result.
set(id_map[
id], selection[
id]);
31 }
while (std::next_permutation(selection.begin(), selection.end()));
38 CARL_LOG_DEBUG(
"carl.covering",
"Removed duplicates: " << pre << std::endl << sc);
40 CARL_LOG_DEBUG(
"carl.covering",
"Selected essential: " << pre << std::endl << sc);
43 if (uncovered.none()) {
44 CARL_LOG_DEBUG(
"carl.covering",
"trivially solved by preprocessing");
50 std::vector<std::size_t> id_map;
51 for (std::size_t sid = 0; sid < sc.
set_count(); ++sid) {
52 if (sc.
get_set(sid).any()) id_map.emplace_back(sid);
58 for (
auto bit: *res) {
61 CARL_LOG_DEBUG(
"carl.covering",
"Got exact covering of size " << size <<
" -> " << *res);
66 CARL_LOG_ERROR(
"carl.covering",
"Did not find an exact set cover.")
A small wrapper that configures logging for carl.
#define CARL_LOG_ERROR(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
Bitset exact(SetCover &sc)
Exact "heuristic": Computes a minimum set cover.
std::optional< Bitset > exact_of_size(const SetCover &sc, const Bitset &uncovered, const std::vector< std::size_t > &id_map, std::size_t size)
Bitset remove_duplicates(SetCover &sc)
Preprocessing heuristic: Compresses the matrix by removing duplicate columns.
Bitset select_essential(SetCover &sc)
Preprocessing heuristic: Selects essential sets which are the only once covering some element.
This class is a simple wrapper around boost::dynamic_bitset.
auto is_subset_of(const Bitset &rhs) const
Checks wether the bits set is a subset of the bits set in rhs.
Bitset & set(std::size_t n, bool value=true)
Sets the given bit to a value, true by default.
Represents a set cover problem.
std::size_t active_set_count() const
Returns the number of active sets (that still cover uncovered elements).
const auto & get_set(std::size_t set) const
Returns the given set.
void select_set(std::size_t s)
Selects the given set and purges the covered elements from all other sets.
Bitset get_uncovered() const
Returns the uncovered elements.
std::size_t set_count() const
Returns the number of sets.