Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::GreedySolutionGenerator Class Reference

The consistency level is maintained up to kFreeAndUncovered. More...

Detailed Description

The consistency level is maintained up to kFreeAndUncovered.

The first solution is obtained using the Chvatal heuristic, that guarantees that the solution is at most 1 + log(n) times the optimal value. Vasek Chvatal, 1979. A greedy heuristic for the set-covering problem. Mathematics of Operations Research, 4(3):233-235, 1979. http://www.jstor.org/stable/3689577

Chvatal's heuristic works as follows: Choose the subset that covers as many remaining uncovered elements as possible for the least possible cost per element and iterate.

The following papers dive into the details of this class of algorithms.

Young, Neal E. 2008. “Greedy Set-Cover Algorithms.” In Encyclopedia of Algorithms, 379–81. Boston, MA: Springer US. Draft at: http://www.cs.ucr.edu/~neal/non_arxiv/Young08SetCover.pdf

Cormode, Graham, Howard Karloff, and Anthony Wirth. 2010. “Set Cover Algorithms for Very Large Datasets.” In CIKM ’10. ACM Press. https://doi.org/10.1145/1871437.1871501.

Definition at line 301 of file set_cover_heuristics.h.

#include <set_cover_heuristics.h>

Inheritance diagram for operations_research::GreedySolutionGenerator:
operations_research::SubsetListBasedSolutionGenerator operations_research::SetCoverSolutionGenerator

Public Member Functions

 GreedySolutionGenerator (SetCoverInvariant *inv)
 GreedySolutionGenerator (SetCoverInvariant *inv, absl::string_view name)
bool NextSolution (absl::Span< const SubsetIndex > focus) final
 GreedySolutionGenerator.
bool NextSolution () final
 Virtual methods that must be implemented by derived classes.
bool NextSolution (const SubsetBoolVector &in_focus) final
 Same as above, but with a vector of Booleans as focus.
Public Member Functions inherited from operations_research::SubsetListBasedSolutionGenerator
 SubsetListBasedSolutionGenerator (SetCoverInvariant *inv, SetCoverInvariant::ConsistencyLevel consistency_level, absl::string_view class_name, absl::string_view name)
bool NextSolution (absl::Span< const SubsetIndex > _) override
bool NextSolution () final
 Virtual methods that must be implemented by derived classes.
bool NextSolution (const SubsetBoolVector &in_focus) final
 Same as above, but with a vector of Booleans as focus.
Public Member Functions inherited from operations_research::SetCoverSolutionGenerator
 SetCoverSolutionGenerator (SetCoverInvariant *inv, SetCoverInvariant::ConsistencyLevel consistency_level, absl::string_view class_name, absl::string_view name)
virtual ~SetCoverSolutionGenerator ()=default
void SetName (const absl::string_view name)
SetCoverInvariantinv () const
virtual SetCoverSolutionGeneratorResetLimits ()
 Resets the limits to their default values.
SetCoverSolutionGeneratorSetMaxIterations (int64_t max_iterations)
 Sets the maximum number of iterations.
int64_t max_iterations () const
 Returns the maximum number of iterations.
SetCoverSolutionGeneratorSetTimeLimitInSeconds (double seconds)
 Sets the time limit in seconds.
absl::Duration run_time () const
double run_time_in_seconds () const
 Returns the total elapsed runtime in seconds.
double run_time_in_microseconds () const
 Returns the total elapsed runtime in microseconds.
std::string name () const
 Returns the name of the heuristic.
std::string class_name () const
 Returns the name of the class.
Cost cost () const
 Returns the current cost of the solution in the invariant.
bool CheckInvariantConsistency () const

Additional Inherited Members

Protected Member Functions inherited from operations_research::SetCoverSolutionGenerator
SetCoverModelmodel () const
 Accessors.
BaseInt num_subsets () const
double time_limit_in_seconds () const
 The time limit in seconds.
Protected Attributes inherited from operations_research::SetCoverSolutionGenerator
absl::Duration run_time_
 run_time_ is an abstract duration for the time spent in NextSolution().
SetCoverInvariant::ConsistencyLevel consistency_level_
 The consistency needed by the solution generator.

Constructor & Destructor Documentation

◆ GreedySolutionGenerator() [1/2]

operations_research::GreedySolutionGenerator::GreedySolutionGenerator ( SetCoverInvariant * inv)
inlineexplicit

Definition at line 303 of file set_cover_heuristics.h.

◆ GreedySolutionGenerator() [2/2]

operations_research::GreedySolutionGenerator::GreedySolutionGenerator ( SetCoverInvariant * inv,
absl::string_view name )
inline

Definition at line 306 of file set_cover_heuristics.h.

Member Function Documentation

◆ NextSolution() [1/3]

bool operations_research::SubsetListBasedSolutionGenerator::NextSolution ( )
inlinefinalvirtual

Virtual methods that must be implemented by derived classes.

Computes the next full solution taking into account all the subsets.

Implements operations_research::SetCoverSolutionGenerator.

Definition at line 181 of file set_cover_heuristics.h.

◆ NextSolution() [2/3]

bool operations_research::GreedySolutionGenerator::NextSolution ( absl::Span< const SubsetIndex > focus)
finalvirtual

GreedySolutionGenerator.

NOMUTANTS – reason, for C++

The priority queue maintains the maximum number of elements covered by unit of cost. We chose 16 as the arity of the heap after some testing.

Todo
(user): research more about the best value for Arity.

NOMUTANTS – reason, for C++

Don't expect pq to be empty, because of the break in the while loop.

Implements operations_research::SetCoverSolutionGenerator.

Definition at line 85 of file set_cover_heuristics.cc.

◆ NextSolution() [3/3]

bool operations_research::SubsetListBasedSolutionGenerator::NextSolution ( const SubsetBoolVector & in_focus)
inlinefinalvirtual

Same as above, but with a vector of Booleans as focus.

Implements operations_research::SetCoverSolutionGenerator.

Definition at line 183 of file set_cover_heuristics.h.


The documentation for this class was generated from the following files: