Go to the source code of this file.
Namespaces | |
paal | |
global namespace of project. | |
paal::greedy | |
Greedy namespace. | |
Functions | |
template<typename SetRange , class GetElementsOfSet , class OutputIterator , class GetElementIndex , class GetWeightOfElement = paal::utils::return_one_functor> | |
auto | paal::greedy::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:
#include <iostream>
#include <vector>
#include <iterator>
#include <boost/range/irange.hpp>
#include "paal/greedy/set_cover/set_cover.hpp"
int main() {
std::vector<std::vector<int>> set_to_elements = {
{ 1, 2 },
{ 3, 4, 5, 6 },
{ 7, 8, 9, 10, 11, 12, 13, 0 },
{ 1, 3, 5, 7, 9, 11, 13 },
{ 2, 4, 6, 8, 10, 12, 0 }
};
std::vector<int> costs = { 1, 1, 1, 1, 1 };
auto sets = boost::irange(0, 5);
std::vector<int> result;
auto element_index = [](int el){return el;};
auto cost = paal::greedy::set_cover(sets,
[&](int set){return costs[set];},
[&](int set){return set_to_elements[set];},
back_inserter(result),
element_index);
std::cout << "Cost: " << cost << std::endl;
}
| |