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

#include <bop_portfolio.h>

Public Member Functions

 OptimizerSelector (const util_intops::StrongVector< OptimizerIndex, BopOptimizerBase * > &optimizers)
 
OptimizerIndex SelectOptimizer ()
 
void UpdateScore (int64_t gain, double time_spent)
 
void TemporarilyMarkOptimizerAsUnselectable (OptimizerIndex optimizer_index)
 
void SetOptimizerRunnability (OptimizerIndex optimizer_index, bool runnable)
 
std::string PrintStats (OptimizerIndex optimizer_index) const
 Returns statistics about the given optimizer.
 
int NumCallsForOptimizer (OptimizerIndex optimizer_index) const
 
void DebugPrint () const
 Prints some debug information. Should not be used in production.
 

Detailed Description

This class is providing an adaptative selector for optimizers based on their past successes and deterministic time spent.

Definition at line 108 of file bop_portfolio.h.

Constructor & Destructor Documentation

◆ OptimizerSelector()

operations_research::bop::OptimizerSelector::OptimizerSelector ( const util_intops::StrongVector< OptimizerIndex, BopOptimizerBase * > & optimizers)
explicit
Note
the list of optimizers is only used to get the names for debug purposes, the ownership of the optimizers is not transferred.

OptimizerSelector

Definition at line 359 of file bop_portfolio.cc.

Member Function Documentation

◆ DebugPrint()

void operations_research::bop::OptimizerSelector::DebugPrint ( ) const

Prints some debug information. Should not be used in production.

Definition at line 461 of file bop_portfolio.cc.

◆ NumCallsForOptimizer()

int operations_research::bop::OptimizerSelector::NumCallsForOptimizer ( OptimizerIndex optimizer_index) const

Definition at line 455 of file bop_portfolio.cc.

◆ PrintStats()

std::string operations_research::bop::OptimizerSelector::PrintStats ( OptimizerIndex optimizer_index) const

Returns statistics about the given optimizer.

Definition at line 444 of file bop_portfolio.cc.

◆ SelectOptimizer()

OptimizerIndex operations_research::bop::OptimizerSelector::SelectOptimizer ( )

Selects the next optimizer to run based on the user defined order and history of success. Returns kInvalidOptimizerIndex if no optimizer is selectable and runnable (see the functions below).

The optimizer is selected using the following algorithm (L being the sorted list of optimizers, and l the position of the last selected optimizer): a- If a new solution has been found by optimizer l, select the first optimizer l' in L, l' >= 0, that can run. b- If optimizer l didn't find a new solution, select the first optimizer l', with l' > l, such that its deterministic time spent since last solution is smaller than the deterministic time spent by any runnable optimizer in 1..l since last solution. If no such optimizer is available, go to option a.

Select the first possible optimizer.

Select the next possible optimizer. If none, select the first one. Check that the time is smaller than all previous optimizers which are runnable.

Todo
(user): Remove this recursive call, even if in practice it's safe because the max depth is the number of optimizers.

Select the optimizer.

Definition at line 369 of file bop_portfolio.cc.

◆ SetOptimizerRunnability()

void operations_research::bop::OptimizerSelector::SetOptimizerRunnability ( OptimizerIndex optimizer_index,
bool runnable )

Sets whether or not an optimizer is "runnable". Like a non-selectable one, a non-runnable optimizer will never be returned by SelectOptimizer().

Todo
(user): Maybe we should simply have the notion of selectability here and let the client handle the logic to decide what optimizer are selectable or not.

Definition at line 439 of file bop_portfolio.cc.

◆ TemporarilyMarkOptimizerAsUnselectable()

void operations_research::bop::OptimizerSelector::TemporarilyMarkOptimizerAsUnselectable ( OptimizerIndex optimizer_index)

Marks the given optimizer as not selectable until UpdateScore() is called with a positive gain. In which case, all optimizer will become selectable again.

Definition at line 434 of file bop_portfolio.cc.

◆ UpdateScore()

void operations_research::bop::OptimizerSelector::UpdateScore ( int64_t gain,
double time_spent )

Updates the internal metrics to decide which optimizer to select. This method should be called each time the selected optimizer is run.

The gain corresponds to the reward to assign to the solver; It could for instance be the difference in cost between the last and the current solution.

The time spent corresponds to the time the optimizer spent; To make the behavior deterministic, it is recommended to use the deterministic time instead of the elapsed time.

The optimizers are sorted based on their score each time a new solution is found.

Definition at line 414 of file bop_portfolio.cc.


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