All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
max_coverage_example.cpp
Go to the documentation of this file.
1 
8 #include <iostream>
10 #include <vector>
11 #include <iterator>
12 
13 #include <boost/range/irange.hpp>
14 
16 
17 int main() {
18  std::vector<std::vector<int>> set_to_elements = {
19  { 1, 2 },
20  { 3, 4, 5, 6 },
21  { 7, 8, 9, 10, 11, 12, 13, 0 },
22  { 1, 3, 5, 7, 9, 11, 13 },
23  { 2, 4, 6, 8, 10, 12, 0 }
24  };
25  const int NUMBER_OF_SETS_TO_SELECT = 2;
26  auto sets = boost::irange(0, 5);
27  using SetIterator = decltype(sets)::iterator;
28  std::vector<int> result;
29  auto element_index = [](int el){return el;};
30  auto covered = paal::greedy::maximum_coverage(
31  sets,
32  [&](int set){return set_to_elements[set];},
33  back_inserter(result),
34  element_index,
35  NUMBER_OF_SETS_TO_SELECT);
36  std::cout << "Covered: " << covered << std::endl;
37 }
auto maximum_coverage(SetRange &&sets, GetElementsOfSet set_to_elements, OutputIterator result, GetElementIndex get_el_index, unsigned int number_of_sets_to_select, GetWeightOfElement get_weight_of_element=GetWeightOfElement{})
this is solve Set Cover problem and return set cover cost example:
auto irange(T begin, T end)
irange
Definition: irange.hpp:22
int main()
[Max Coverage Example]