Google OR-Tools v9.11
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(). | |
int64_t | GetBestRank () const |
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 | |
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< 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 58 of file synchronization.h.
|
inlineexplicit |
Definition at line 60 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 |
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. 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.
Definition at line 837 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 785 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 801 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 778 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 792 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 771 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 845 of file synchronization.h.
|
inline |
Definition at line 128 of file synchronization.h.
|
mutableprotected |
Definition at line 138 of file synchronization.h.
|
protected |
Definition at line 135 of file synchronization.h.
|
protected |
Definition at line 136 of file synchronization.h.