carl  24.04
Computer ARithmetic Library
SetCover.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 
6 #include <ostream>
7 #include <vector>
8 
9 namespace carl::covering {
10 
11 /**
12  * Represents a set cover problem.
13  * Allows to state which sets cover which elements and offers some helper methods to work with this set cover for the heuristics.
14  */
15 class SetCover {
16 public:
17  friend std::ostream& operator<<(std::ostream& os, const SetCover& sc);
18 private:
19  /// The actual sets.
20  std::vector<Bitset> mSets;
21 public:
22  /// States that s covers the given element.
23  void set(std::size_t set, std::size_t element);
24  /// States that s covers the given elements.
25  void set(std::size_t set, const Bitset& elements);
26  /// Returns the given set.
27  const auto& get_set(std::size_t set) const {
28  return mSets[set];
29  }
30  /// Returns the number of elements.
31  std::size_t element_count() const;
32  /// Removes empty sets.
33  void prune_sets();
34  /// Returns the number of sets.
35  std::size_t set_count() const;
36  /// Returns the number of active sets (that still cover uncovered elements).
37  std::size_t active_set_count() const;
38  /// Returns the id of the largest set.
39  std::size_t largest_set() const;
40  /// Returns the id of the largest set with respect to given weights.
41  std::size_t largest_set(const std::vector<double>& weights) const;
42  /// Returns the uncovered elements.
43  Bitset get_uncovered() const;
44  /// Selects the given set and purges the covered elements from all other sets.
45  void select_set(std::size_t s);
46 };
47 
48 /// Print the set cover to os.
49 std::ostream& operator<<(std::ostream& os, const SetCover& sc);
50 
51 }
std::ostream & operator<<(std::ostream &os, const SetCover &sc)
Print the set cover to os.
Definition: SetCover.cpp:94
This class is a simple wrapper around boost::dynamic_bitset.
Definition: Bitset.h:20
Represents a set cover problem.
Definition: SetCover.h:15
std::size_t active_set_count() const
Returns the number of active sets (that still cover uncovered elements).
Definition: SetCover.cpp:44
const auto & get_set(std::size_t set) const
Returns the given set.
Definition: SetCover.h:27
void select_set(std::size_t s)
Selects the given set and purges the covered elements from all other sets.
Definition: SetCover.cpp:86
void prune_sets()
Removes empty sets.
Definition: SetCover.cpp:32
std::vector< Bitset > mSets
The actual sets.
Definition: SetCover.h:20
Bitset get_uncovered() const
Returns the uncovered elements.
Definition: SetCover.cpp:78
std::size_t set_count() const
Returns the number of sets.
Definition: SetCover.cpp:40
std::size_t element_count() const
Returns the number of elements.
Definition: SetCover.cpp:24
void set(std::size_t set, std::size_t element)
States that s covers the given element.
Definition: SetCover.cpp:10
friend std::ostream & operator<<(std::ostream &os, const SetCover &sc)
Print the set cover to os.
Definition: SetCover.cpp:94
std::size_t largest_set() const
Returns the id of the largest set.
Definition: SetCover.cpp:50