carl  24.04
Computer ARithmetic Library
select_essential.cpp
Go to the documentation of this file.
1 #include "select_essential.h"
2 
4 
6 
8  Bitset selected;
9  bool has_selected = true;
10  while (has_selected) {
11  has_selected = false;
12  for (std::size_t e = 0; e < sc.element_count(); ++e) {
13  std::size_t num = 0;
14  std::size_t set = 0;
15  for (std::size_t s = 0; (s < sc.set_count()) && (num <= 1); ++s) {
16  if (sc.get_set(s).test(e)) {
17  ++num;
18  set = s;
19  }
20  }
21  if (num == 1) {
22  sc.select_set(set);
23  selected.set(set);
24  has_selected = true;
25  }
26  }
27  }
28  return selected;
29 }
30 
31 }
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.
Definition: Bitset.h:20
Bitset & set(std::size_t n, bool value=true)
Sets the given bit to a value, true by default.
Definition: Bitset.h:140
Represents a set cover problem.
Definition: SetCover.h:15
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
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