14#ifndef OR_TOOLS_ALGORITHMS_SET_COVER_HEURISTICS_H_
15#define OR_TOOLS_ALGORITHMS_SET_COVER_HEURISTICS_H_
20#include "absl/base/nullability.h"
21#include "absl/types/span.h"
31 using Index = SubsetIndex::ValueType;
77 : inv_(inv), num_columns_fixed_by_singleton_row_(0) {}
90 return num_columns_fixed_by_singleton_row_;
99 BaseInt num_columns_fixed_by_singleton_row_;
137 bool NextSolution(
const std::vector<SubsetIndex>& focus);
174 bool NextSolution(
const std::vector<SubsetIndex>& focus);
177 bool NextSolution(
const std::vector<SubsetIndex>& focus,
232 bool NextSolution(absl::Span<const SubsetIndex> focus,
int num_iterations);
245 void UpdatePriorities(absl::Span<const SubsetIndex> impacted_subsets);
257 array_.resize(
size.value(), T(-1));
261 int size()
const {
return array_.size(); }
265 array_.resize(
size, T(-1));
272 const int size = array_.size();
275 if (index_ >=
size) {
285 for (
int i = 0; i < fill_; ++i) {
286 if (t == array_[i]) {
294 std::vector<T> array_;
325 lagrangian_factor_(kDefaultLagrangianFactor),
326 penalty_factor_(kDefaultPenaltyFactor),
327 epsilon_(kDefaultEpsilon),
330 tabu_list_(SubsetIndex(kDefaultTabuListSize)) {
343 bool NextSolution(absl::Span<const SubsetIndex> focus,
int num_iterations);
365 void UpdatePenalties(absl::Span<const SubsetIndex> focus);
371 static constexpr double kDefaultLagrangianFactor = 100.0;
372 double lagrangian_factor_;
375 static constexpr double kPenaltyUpdateEpsilon = 1e-1;
378 static constexpr double kDefaultPenaltyFactor = 0.3;
379 double penalty_factor_;
382 static constexpr double kDefaultEpsilon = 1e-6;
396 static constexpr int kDefaultTabuListSize = 17;
416 : inv_(inv), epsilon_(kDefaultEpsilon), alpha_(kDefaultAlpha) {
429 bool NextSolution(absl::Span<const SubsetIndex> focus,
int num_iterations);
438 void SetEpsilon(
double r) { epsilon_ = r; }
440 double GetEpsilon()
const {
return epsilon_; }
442 void SetAlpha(
double r) { alpha_ = r; }
444 double GetAlpha()
const {
return alpha_; }
448 static constexpr double kDefaultEpsilon = 1e-8;
453 static constexpr double kDefaultAlpha = 0.5;
457 double penalization_factor_;
463 Cost ComputeDelta(SubsetIndex subset)
const;
481 SetCoverInvariant* inv);
485 std::size_t num_subsets,
486 SetCoverInvariant* inv);
494 SetCoverInvariant* inv);
498 absl::Span<const SubsetIndex> focus, std::size_t num_subsets,
499 SetCoverInvariant* inv);
ElementDegreeSolutionGenerator(SetCoverInvariant *inv)
bool NextSolution()
GreedySolutionGenerator.
GreedySolutionGenerator(SetCoverInvariant *inv)
GuidedLocalSearch(SetCoverInvariant *inv)
bool NextSolution(const SubsetBoolVector &in_focus, int num_iterations)
void Initialize()
Initializes the Guided Local Search algorithm.
bool NextSolution(int num_iterations)
void SetTabuListSize(int size)
void Initialize()
Initializes the Guided Tabu Search algorithm.
void SetLagrangianFactor(double factor)
int GetTabuListSize() const
double GetLagrangianFactor() const
double GetEpsilon() const
double GetPenaltyFactor() const
void SetPenaltyFactor(double factor)
Setters and getters for the Guided Tabu Search algorithm parameters.
void SetEpsilon(double r)
GuidedTabuSearch(SetCoverInvariant *inv)
bool NextSolution(const SubsetBoolVector &in_focus, int num_iterations)
bool NextSolution(int num_iterations)
bool NextSolution()
Preprocessor.
Preprocessor(absl::Nonnull< SetCoverInvariant * > inv)
int num_columns_fixed_by_singleton_row() const
Returns the number of columns that are the only one for a given row.
bool NextSolution()
Returns true if a solution was found.
RandomSolutionGenerator(SetCoverInvariant *inv)
bool NextSolution(int num_iterations)
SteepestSearch(SetCoverInvariant *inv)
Priority aggregate for the subset priority queue.
SubsetIndexWithPriority()
SubsetIndexWithPriority(Priority priority, Index index)
SubsetIndex::ValueType Index
bool operator<(const SubsetIndexWithPriority other) const
Priority priority() const
void Init(int size)
Initializes the array of the Tabu list.
bool Contains(T t) const
Returns true if t is in the array. This is O(size), but small.
int size() const
Returns the size of the array.
void Add(T t)
Adds t to the array. When the end of the array is reached, re-start at 0.
TrivialSolutionGenerator(SetCoverInvariant *inv)
bool NextSolution()
TrivialSolutionGenerator.
In SWIG mode, we don't want anything besides these top-level includes.
std::vector< SubsetIndex > ClearMostCoveredElements(std::size_t max_num_subsets, SetCoverInvariant *inv)
util_intops::StrongVector< SubsetIndex, BaseInt, IntAllocator > SubsetToIntVector
std::vector< SubsetIndex > ClearRandomSubsets(std::size_t num_subsets, SetCoverInvariant *inv)
double Cost
Basic non-strict type for cost. The speed penalty for using double is ~2%.