![]() |
Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
|
#include <synchronization.h>
Classes | |
struct | Solution |
The solution format used by this class. More... | |
Public Member Functions | |
SharedSolutionRepository (int num_solutions_to_keep, absl::string_view name="") | |
int | NumSolutions () const |
std::shared_ptr< const Solution > | GetSolution (int index) const |
Returns the solution i where i must be smaller than NumSolutions(). | |
int64_t | GetBestRank () const |
std::vector< std::shared_ptr< const Solution > > | GetBestNSolutions (int n) const |
ValueType | GetVariableValueInSolution (int var_index, int solution_index) const |
std::shared_ptr< const Solution > | GetRandomBiasedSolution (absl::BitGenRef random) const |
Returns a random solution biased towards good solutions. | |
std::shared_ptr< const Solution > | Add (Solution solution) |
void | Synchronize () |
std::vector< std::string > | TableLineStats () const |
Protected Member Functions | |
int64_t num_added_ | ABSL_GUARDED_BY (mutex_)=0 |
int64_t num_queried_ | ABSL_GUARDED_BY (mutex_)=0 |
int64_t num_synchronization_ | ABSL_GUARDED_BY (mutex_)=0 |
std::vector< int > tmp_indices_ | ABSL_GUARDED_BY (mutex_) |
std::vector< std::shared_ptr< Solution > > solutions_ | ABSL_GUARDED_BY (mutex_) |
std::vector< std::shared_ptr< Solution > > new_solutions_ | ABSL_GUARDED_BY (mutex_) |
Protected Attributes | |
const std::string | name_ |
const int | num_solutions_to_keep_ |
absl::Mutex | mutex_ |
Thread-safe. Keeps a set of n unique best solution found so far.
Definition at line 61 of file synchronization.h.
|
inlineexplicit |
Definition at line 63 of file synchronization.h.
|
mutableprotected |
Our two solutions pools, the current one and the new one that will be merged into the current one on each Synchronize() calls.
|
protected |
|
protected |
|
protectedpure virtual |
|
mutableprotectedpure virtual |
|
protectedpure virtual |
std::shared_ptr< const typename SharedSolutionRepository< ValueType >::Solution > operations_research::sat::SharedSolutionRepository< ValueType >::Add | ( | Solution | solution | ) |
Add a new solution. Note that it will not be added to the pool of solution right away. One must call Synchronize for this to happen. In order to be deterministic, this will keep all solutions until Synchronize() is called, so we need to be careful not to generate too many solutions at once.
Returns a shared pointer to the solution that was stored in the repository.
Definition at line 911 of file synchronization.h.
std::vector< std::shared_ptr< const typename SharedSolutionRepository< ValueType >::Solution > > operations_research::sat::SharedSolutionRepository< ValueType >::GetBestNSolutions | ( | int | n | ) | const |
Sorted and unique.
Definition at line 843 of file synchronization.h.
int64_t operations_research::sat::SharedSolutionRepository< ValueType >::GetBestRank | ( | ) | const |
Returns the rank of the best known solution. You shouldn't call this if NumSolutions() is zero.
Definition at line 834 of file synchronization.h.
std::shared_ptr< const typename SharedSolutionRepository< ValueType >::Solution > operations_research::sat::SharedSolutionRepository< ValueType >::GetRandomBiasedSolution | ( | absl::BitGenRef | random | ) | const |
Returns a random solution biased towards good solutions.
As long as we have solution with the best objective that haven't been explored too much, we select one uniformly. Otherwise, we select a solution from the pool uniformly.
Note(user): Because of the increase of num_selected, this is dependent on the order of call. It should be fine for "determinism" because we do generate the task of a batch always in the same order.
Select all the best solution with a low enough selection count.
Definition at line 874 of file synchronization.h.
std::shared_ptr< const typename SharedSolutionRepository< ValueType >::Solution > operations_research::sat::SharedSolutionRepository< ValueType >::GetSolution | ( | int | index | ) | const |
Returns the solution i where i must be smaller than NumSolutions().
Definition at line 827 of file synchronization.h.
ValueType operations_research::sat::SharedSolutionRepository< ValueType >::GetVariableValueInSolution | ( | int | var_index, |
int | solution_index ) const |
Returns the variable value of variable 'var_index' from solution 'solution_index' where solution_index must be smaller than NumSolutions() and 'var_index' must be smaller than number of variables.
Definition at line 865 of file synchronization.h.
int operations_research::sat::SharedSolutionRepository< ValueType >::NumSolutions | ( | ) | const |
Returns the number of current solution in the pool. This will never decrease.
Definition at line 820 of file synchronization.h.
void operations_research::sat::SharedSolutionRepository< ValueType >::Synchronize | ( | ) |
Updates the current pool of solution with the one recently added. Note that we use a stable ordering of solutions, so the final pool will be independent on the order of the calls to AddSolution() provided that the set of added solutions is the same.
Works in O(num_solutions_to_keep_).
We use a stable sort to keep the num_selected count for the already existing solutions.
Definition at line 924 of file synchronization.h.
|
inline |
Definition at line 136 of file synchronization.h.
|
mutableprotected |
Definition at line 146 of file synchronization.h.
|
protected |
Definition at line 143 of file synchronization.h.
|
protected |
Definition at line 144 of file synchronization.h.