Posted on Aug 18
Set cover problem: Given the universe \(\mathcal{U}\) and the set \(\mathcal{S}\) of subsets of \(\mathcal{U}\), find the collection \(\mathcal{C}\) of subsets from \(\mathcal{S}\) that covers the universe while minimizing the total cost where
and the objective is to …
The format of the problem input for the above code is:
[the cardinality of the universe] [the number of the subsets given below]
[cost of the subset 0] [the size of the subset 0] [the first element] ...
[cost of the subset 1] [the size of the subset 1] [the first element] ...
...
The following snippet shows the usage of the greedy_set_cover
class.
It takes an input from an input stream and translates the input
into its internal parameters, the universe cardinality and the subsets,
according to the input format above.
greedy_set_cover sc;
istringstream iss(src); // Input string in the above input format.
sc.input(iss); // Feed the input.
sc.solve(); // Solve the problem.
The solve
method show the selection of subsets,
each represented with an 0-based integer, and the total cost incurred
by that selection.
The implementation is roughly summarized as a pseudo code below:
2015 My gh-pages