Google OR-Tools v9.9
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 |
Solution | GetSolution (int index) const |
Returns the solution i where i must be smaller than NumSolutions(). | |
ValueType | GetVariableValueInSolution (int var_index, int solution_index) const |
Solution | GetRandomBiasedSolution (absl::BitGenRef random) const |
Returns a random solution biased towards good solutions. | |
void | Add (const Solution &solution) |
void | Synchronize () |
std::vector< std::string > | TableLineStats () const |
Protected Member Functions | |
void | AddInternal (const Solution &solution) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) |
Helper method for adding the solutions once the mutex is acquired. | |
int64_t num_added_ | ABSL_GUARDED_BY (mutex_)=0 |
int64_t num_ignored_ | 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< Solution > solutions_ | ABSL_GUARDED_BY (mutex_) |
std::vector< 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 56 of file synchronization.h.
|
inlineexplicit |
Definition at line 58 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 |
|
protectedpure virtual |
|
mutableprotectedpure virtual |
|
protectedpure virtual |
void operations_research::sat::SharedSolutionRepository< ValueType >::Add | ( | const 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.
Works in O(num_solutions_to_keep_).
Definition at line 683 of file synchronization.h.
|
protected |
Helper method for adding the solutions once the mutex is acquired.
Do not add identical solution.
Definition at line 690 of file synchronization.h.
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 647 of file synchronization.h.
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 631 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 638 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 624 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 712 of file synchronization.h.
|
inline |
Definition at line 122 of file synchronization.h.
|
mutableprotected |
Definition at line 137 of file synchronization.h.
|
protected |
Definition at line 134 of file synchronization.h.
|
protected |
Definition at line 135 of file synchronization.h.