carl  24.04
Computer ARithmetic Library
greedy.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../SetCover.h"
4 #include "../TypedSetCover.h"
5 
7 
8 /**
9  * Simple greedy heuristic:
10  * Selects the largest remaining set until all elements are covered.
11  */
12 Bitset greedy(SetCover& sc);
13 
14 /**
15  * Bounded greedy heuristic:
16  * Selects the largest remaining set until at most bound constraints remain.
17  */
18 Bitset greedy_bounded(SetCover& sc, std::size_t bound = 12);
19 
20 /**
21  * Weighted greedy heuristic:
22  * Selects the largest remaining set according to the given weight function until at most bound constraints remain.
23  */
24 Bitset greedy_weighted(SetCover& sc, const std::vector<double>& weights, std::size_t bound = 0);
25 
26 /**
27  * Weighted greedy heuristic:
28  * Selects the largest remaining set according to the given weight function until at most bound constraints remain.
29  */
30 template<typename T, typename F>
31 auto greedy_weighted(TypedSetCover<T>& tsc, F&& weight, std::size_t bound = 0) {
32  std::vector<double> weights;
33  for (std::size_t sid = 0; sid < tsc.set_cover().set_count(); ++sid) {
34  weights.emplace_back(weight(tsc.get_set(sid)));
35  }
36  return greedy_weighted(tsc.set_cover(), weights, bound);
37 }
38 
39 }
Bitset greedy(SetCover &sc)
Simple greedy heuristic: Selects the largest remaining set until all elements are covered.
Definition: greedy.cpp:7
Bitset greedy_weighted(SetCover &sc, const std::vector< double > &weights, std::size_t bound)
Weighted greedy heuristic: Selects the largest remaining set according to the given weight function u...
Definition: greedy.cpp:31
Bitset greedy_bounded(SetCover &sc, std::size_t bound)
Bounded greedy heuristic: Selects the largest remaining set until at most bound constraints remain.
Definition: greedy.cpp:19
Represents a set cover problem where a set is represented by some type.
Definition: TypedSetCover.h:16
const Set & get_set(std::size_t sid) const
Definition: TypedSetCover.h:47
const auto & set_cover() const
Returns the underlying set cover.
Definition: TypedSetCover.h:57