LSParam Class¶
-
class
localsolver.LSParam¶ Solving parameters. This class contains some methods allowing you to parameterize the resolution of the model. For the sake of simplicity, only a few parameters are actually offered to tune the search.
Summary¶
seed |
Seed of the pseudo-random number generator used by the solver. |
nb_threads |
Number of threads used to parallelize the search. |
time_limit |
Time limit in seconds. |
iteration_limit |
Iteration limit. |
annealing_level |
Deprecated since version 8.0: The annealing level doesn’t have a significant influence on the search anymore. |
verbosity |
Verbosity level of the solver. |
time_between_displays |
Time in seconds between two consecutive displays. |
time_between_ticks |
Time in seconds between two consecutive ticks. |
iteration_between_ticks |
Number of iterations between two consecutive ticks. |
log_file |
Path of the LocalSolver log file. |
advanced_params |
Reserved for maintenance purpose. |
set_seed |
Sets the seed of the pseudo-random number generator used by the solver. |
get_seed |
Gets the seed of the pseudo-random number generator used by the solver. |
set_nb_threads |
Sets the number of threads used to parallelize the search. |
get_nb_threads |
Gets the number of threads requested by the user. |
set_time_limit |
Sets the time limit in seconds. |
get_time_limit |
Gets the time limit in seconds. |
set_iteration_limit |
Sets a limit on the number of iterations. |
get_iteration_limit |
Gets the limit on the number of iterations. |
set_annealing_level |
Sets the simulated annealing level. |
get_annealing_level |
Gets the simulated annealing level. |
set_verbosity |
Sets the verbosity level of the solver. |
get_verbosity |
Gets the verbosity level of the solver. |
set_objective_threshold |
Sets the threshold of the objective with the given index. |
get_objective_threshold |
Gets the threshold of the objective with the given index. |
set_time_between_displays |
Sets the time in seconds between two consecutive displays in console while the solver is running. |
get_time_between_displays |
Gets the time in seconds between two consecutive displays in console while the solver is running. |
set_time_between_ticks |
Sets the time in seconds between two events of type LSCallbackType.TIME_TICKED. |
get_time_between_ticks |
Gets the time in seconds between two events of type LSCallbackType.TIME_TICKED. |
set_iteration_between_ticks |
Sets the number of iterations between two events of type LSCallbackType.ITERATION_TICKED. |
get_iteration_between_ticks |
Gets the number of iterations between two events of type LSCallbackType.ITERATION_TICKED. |
set_log_file |
Sets the path of the LocalSolver log file. |
get_log_file |
Returns the path of the LocalSolver log file. |
set_advanced_param |
Reserved for maintenance purpose. |
get_advanced_param |
Reserved for maintenance purpose. |
__str__ |
Returns a string representation of these parameters. |
Instance methods¶
-
LSParam.set_seed(seed)¶ Sets the seed of the pseudo-random number generator used by the solver. The seed must be a positive integer. The default seed is set to 0. Only allowed in state
LSState.STOPPED.The search for solutions is highly randomized. Fixing the seed and the number of iterations of the solver allows you to reproduce exactly its results over several runs.
You can also use the shortcut member
seedParameters: seed ( int) – Seed of the pseudo-random number generator.
-
LSParam.get_seed()¶ Gets the seed of the pseudo-random number generator used by the solver. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.You can also use the shortcut member
seedReturns: Seed of the pseudo-random number generator. Return type: int
-
LSParam.set_nb_threads(nb_threads)¶ Sets the number of threads used to parallelize the search. The number of threads must be a strictly positive integer. The default number of threads is set to 2. Only allowed in state
LSState.STOPPED.This parameter is indicative, if needed LocalSolver may use more threads. The actual number of threads can also vary during the search.
You can also use the shortcut member
nb_threadsParameters: nb_threads ( int) – Number of threads.
-
LSParam.get_nb_threads()¶ Gets the number of threads requested by the user. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.You can also use the shortcut member
nb_threadsReturns: Number of threads. Return type: int
-
LSParam.set_time_limit(time_limit)¶ Sets the time limit in seconds. Only allowed in state
LSState.STOPPED.This is not allowed if you have defined multiple phases. Use
LSPhase.set_time_limit()to set the limit for each phase instead.You can also use the shortcut member
time_limitParameters: time_limit ( int) – Time limit in seconds.
-
LSParam.get_time_limit()¶ Gets the time limit in seconds. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.This is not allowed if you have defined multiple phases. Use
LSPhase.get_time_limit()instead.You can also use the shortcut member
time_limitReturns: Time limit in seconds. Return type: int
-
LSParam.set_iteration_limit(iteration_limit)¶ Sets a limit on the number of iterations. Fixing the seed and the number of iterations ensures the reproducibility of results over several runs. Only allowed in state
LSState.STOPPED.This is not allowed if you have defined multiple phases. Use
LSPhase.set_iteration_limit()to set the limit for each phase instead.You can also use the shortcut member
iteration_limitParameters: iteration_limit ( int) – Iteration limit.
-
LSParam.get_iteration_limit()¶ Gets the limit on the number of iterations. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.This is not allowed if you have defined multiple phases. Use
LSPhase.get_iteration_limit()instead.You can also use the shortcut member
iteration_limitReturns: Iteration limit. Return type: int
-
LSParam.set_annealing_level(level)¶ Sets the simulated annealing level.
Deprecated since version 8.0: The annealing level doesn’t have a significant influence on the search anymore. The tuning of this parameter won’t be allowed in a future version.
The level must be an integer between 0 and 9. The default simulated annealing level is set to 1. Only allowed in state
LSState.STOPPED.Parameters: level ( int) – Simulated annealing level.
-
LSParam.get_annealing_level()¶ Gets the simulated annealing level.
Deprecated since version 8.0: The annealing level doesn’t have a significant influence on the search anymore. The tuning of this parameter won’t be allowed in a future version.
Only allowed in states
LSState.PAUSEDorLSState.STOPPED.Returns: Simulated annealing level. Return type: int
-
LSParam.set_verbosity(verbosity)¶ Sets the verbosity level of the solver. The default verbosity is set to 1. There are 3 defined verbosity levels :
- 0: All the traces are disabled.
- 1: Normal verbosity. This is the default level.
- 2: Detailed verbosity. Displays statistics during the search.
You can also use the shortcut member
verbosityParameters: verbosity ( int) – Verbosity level: 0, 1, 2.
-
LSParam.get_verbosity()¶ Gets the verbosity level of the solver.
You can also use the shortcut member
verbosityReturns: verbosity Verbosity level: 0, 1 or 2. Return type: int
-
LSParam.set_objective_threshold(obj_index, threshold)¶ Sets the threshold of the objective with the given index. If the objective is minimized (respectively maximized), then the optimization of this objective is stopped as soon as this lower (respectively upper) threshold is reached. It can be useful for goal programming. Only allowed in states
LSState.STOPPED.Parameters: - obj_index (
int) – Index of the objective - threshold – Objective threshold. The threshold can be a double or an integer.
Since: 8.0
- obj_index (
-
LSParam.get_objective_threshold(obj_index)¶ Gets the threshold of the objective with the given index. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.Parameters: obj_index ( int) – Index of the objectiveReturns: The threshold of the objective Return type: intordoubleSince: 8.0
-
LSParam.set_time_between_displays(time_between_displays)¶ Sets the time in seconds between two consecutive displays in console while the solver is running. The default time between displays is set to 1 second. Only allowed in state
LSState.STOPPED.You can also use the shortcut member
time_between_displaysParameters: time_between_displays ( int) – Time in seconds between displays.
-
LSParam.get_time_between_displays()¶ Gets the time in seconds between two consecutive displays in console while the solver is running. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.You can also use the shortcut member
time_between_displaysReturns: Time in seconds between displays. Return type: int
-
LSParam.set_time_between_ticks(time_between_ticks)¶ Sets the time in seconds between two events of type
LSCallbackType.TIME_TICKED. The default time between ticks is set to 1 second. Only allowed in stateLSState.STOPPED.You can also use the shortcut member
time_between_ticksParameters: time_between_ticks ( int) – Time in seconds between ticks.Since: 6.0
-
LSParam.get_time_between_ticks()¶ Gets the time in seconds between two events of type
LSCallbackType.TIME_TICKED. Only allowed in statesLSState.PAUSEDorLSState.STOPPED.You can also use the shortcut member
time_between_ticksReturns: Time in seconds between ticks. Return type: intSince: 6.0
-
LSParam.set_iteration_between_ticks(iteration_between_ticks)¶ Sets the number of iterations between two events of type
LSCallbackType.ITERATION_TICKED. The default number of iterations is 10,000. Only allowed in stateLSState.STOPPED.You can also use the shortcut member
iteration_between_ticksParameters: iteration_between_ticks ( long) – Number of iterations between ticks.Since: 6.0
-
LSParam.get_iteration_between_ticks()¶ Gets the number of iterations between two events of type
LSCallbackType.ITERATION_TICKED. Only allowed in statesLSState.PAUSEDorLSState.STOPPED.You can also use the shortcut member
iteration_between_ticksReturns: Number of iterations between ticks. Return type: longSince: 6.0
-
LSParam.set_log_file(path)¶ Sets the path of the LocalSolver log file. If the path is empty, no log will be saved. To tune the logging verbosity, see
set_verbosity(). Only allowed in statesLSState.STOPPEDorLSState.MODELING.You can also use the shortcut member
log_fileParameters: path ( str) – Path of the log file. Leave empty to disable the file logging mechanism.
-
LSParam.get_log_file()¶ Returns the path of the LocalSolver log file. If no log file was specified, an empty string is returned.
You can also use the shortcut member
log_fileReturns: The path of the log file or an empty string. Return type: str
-
LSParam.set_advanced_param(key, value)¶ Reserved for maintenance purpose.
Sets the value of an advanced parameter. Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. Only allowed in states
LSState.STOPPEDorLSState.MODELING.Advanced parameters can have string, double or integer values. You can also use the shortcut collection member
advanced_params.Parameters: - key (
str) – Name of the parameter to change - value – Value of the parameter. The value can be an integer, a double or a string.
- key (
-
LSParam.get_advanced_param(key)¶ Reserved for maintenance purpose.
Returns the value of an advanced parameter. Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. Throws an exception if the parameter does not exist. Only allowed in states
LSState.PAUSEDorLSState.STOPPED.Advanced parameters can have string, integer or double values. You can also use the shortcut collection member
advanced_params.Parameters: key ( str) – Name of the parameterReturn type: int,doubleorstr
Instance attributes¶
All get/set methods have their attribute counterpart. You can use them as
shortcuts to improve the readability or your models and codes.
-
LSParam.seed¶ Seed of the pseudo-random number generator used by the solver. It is a shortcut for
get_seed()andset_seed().
-
LSParam.nb_threads¶ Number of threads used to parallelize the search. It is a shortcut for
get_nb_threads()andset_nb_threads().
-
LSParam.time_limit¶ Time limit in seconds. It is a shortcut for
get_time_limit()andset_time_limit().
-
LSParam.iteration_limit¶ Iteration limit. It is a shortcut for
get_iteration_limit()andset_iteration_limit().
-
LSParam.annealing_level¶ Deprecated since version 8.0: The annealing level doesn’t have a significant influence on the search anymore. The tuning of this parameter won’t be allowed in a future version.
Simulated annealing level.
-
LSParam.verbosity¶ Verbosity level of the solver. It is a shortcut for
get_verbosity()andset_verbosity().
-
LSParam.time_between_displays¶ Time in seconds between two consecutive displays. It is a shortcut for
get_time_between_displays()andset_time_between_displays().
-
LSParam.time_between_ticks¶ Time in seconds between two consecutive ticks. It is a shortcut for
get_time_between_ticks()andset_time_between_ticks().Since: 6.0
-
LSParam.iteration_between_ticks¶ Number of iterations between two consecutive ticks. It is a shortcut for
get_iteration_between_ticks()andset_iteration_between_ticks().Since: 6.0
-
LSParam.log_file¶ Path of the LocalSolver log file. It is a shortcut for
get_log_file()andset_log_file().
-
LSParam.advanced_params¶ Reserved for maintenance purpose.
Advanced parameters. Advanced parameters are reserved for fine tuning or debugging and should not be used by end-users. It is a shortcut for
get_advanced_param()andset_advanced_param(). The returned object can be indexed with strings. Please note that the returned object is not iterable and you cannot apply the functionlenon it.