All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
set_cover_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  std::vector<int> costs = { 1, 1, 1, 1, 1 };
26  auto sets = boost::irange(0, 5);
27  std::vector<int> result;
28  auto element_index = [](int el){return el;};
29  auto cost = paal::greedy::set_cover(sets,
30  [&](int set){return costs[set];},
31  [&](int set){return set_to_elements[set];},
32  back_inserter(result),
33  element_index);
34  std::cout << "Cost: " << cost << std::endl;
35 }
auto irange(T begin, T end)
irange
Definition: irange.hpp:22
auto set_cover(SetRange &&sets, GetCostOfSet set_to_cost, GetElementsOfSet set_to_elements, OutputIterator result, GetElementIndex get_el_index)
detail
Definition: set_cover.hpp:48
int main()
[Set Cover Example]