LSPhase Class¶

class
localsolver.
LSPhase
¶ Optimization phase. Since LocalSolver allows lexicographic multiobjective optimization, we allow you to parameterize the time or the number of iterations to spend in optimizing each objective. When multiple objectives are declared, these objectives are optimized in lexicographic order (in the order of their declaration in the model). Thus, if
k
objectives0, ..., k1
are declared, each objectivei
can be optimized while maintaining the values of objectives0, ..., i1
previously obtained and ignoring the values of objectivesi+1, ..., k1
. During such an optimization phase, objectivei
is called the optimized objective.At least one phase must be created to launch the solver. If you have only one objective to optimize, then create a phase, set the time or the number of iterations, and run the solver. By default, the optimized objective of a phase corresponds to the last objective declared in the model (in this case, all objectives of the model are optimized together).
Summary¶
time_limit 
Time limit of this phase in seconds. 
iteration_limit 
Iteration limit of this phase. 
optimized_objective 
Index of the optimized objective of this phase. 
enabled 
Enabled status of this phase. 
set_time_limit 
Sets the time limit of this phase in seconds. 
get_time_limit 
Gets the time limit of this phase in seconds. 
set_iteration_limit 
Sets the number of iterations of this phase. 
get_iteration_limit 
Gets the number of iterations of this phase. 
set_optimized_objective 
Sets the optimized objective of this phase. 
get_optimized_objective 
Gets the index of the optimized objective. 
set_enabled 
Sets the enabled status of this phase. 
is_enabled 
Returns true if the phase is enabled, False otherwise. 
__str__ 
Returns a string representation of this phase. 
Instance methods¶

LSPhase.
set_time_limit
(limit)¶ Sets the time limit of this phase in seconds. Note that the “real” time (that is, total time) spent to resolve the model is considered here (and not only the CPU time). The default time limit is set to the largest positive integer on 32 bits, that is
2^311 = 2,147,483,647 > 10^9
. Only allowed in statesLSState.MODELING
orLSState.STOPPED
.Note that if the optimal value of an objective is found before the end of the corresponding phase, the remaining time will be transferred to the next phase.
You can also use the shortcut member
time_limit
Parameters: limit ( int
) – Time limit in seconds.

LSPhase.
get_time_limit
()¶ Gets the time limit of this phase in seconds.
You can also use the shortcut member
time_limit
Returns: Time limit in seconds. Return type: int

LSPhase.
set_iteration_limit
(limit)¶ Sets the number of iterations of this phase. Fixing the seed and the number of iterations of all phases ensures the reproducibility of results over several runs. The default number of iterations is set to the largest positive integer on 64 bits, that is
2^631 = 9,223,372,036,854,775,807 > 10^18
. Only allowed in statesLSState.MODELING
orLSState.STOPPED
.Note that if the optimal value of an objective is found before the end of the corresponding phase, the remaining iterations will be transferred to the next phase.
You can also use the shortcut member
iteration_limit
Parameters: limit ( int
) – Iteration limit

LSPhase.
get_iteration_limit
()¶ Gets the number of iterations of this phase. Only allowed in states
LSState.PAUSED
orLSState.STOPPED
.You can also use the shortcut member
iteration_limit
Returns: Iteration limit Return type: int

LSPhase.
set_optimized_objective
(obj_index)¶ Sets the optimized objective of this phase. When multiple objectives are declared, these objectives are optimized in lexicographic order (in the order of their declaration in the model). Thus, if
k
objectives0, ..., k1
are declared, each objectivei
can be optimized while maintaining the values of objectives0, ..., i1
previously obtained and ignoring the values of objectivesi+1, ..., k1
. By default, the optimized objective corresponds to the last objective declared in the model. Only allowed in statesLSState.MODELING
orLSState.STOPPED
.You can also use the shortcut member
optimized_objective
Parameters: obj_index ( int
) – Index of the optimized objective

LSPhase.
get_optimized_objective
(obj_index)¶ Gets the index of the optimized objective.
You can also use the shortcut member
optimized_objective
Returns: Index of the optimized objective. Return type: int

LSPhase.
set_enabled
(enabled)¶ Sets the enabled status of this phase. The solver only optimize enabled phases. Disabling a phase can be useful when an objective has been removed from the model by
LSModel.remove_objective()
. By default, a phase is enabled. Only allowed in statesLSState.MODELING
orLSState.STOPPED
.You can also use the shortcut member
enabled
Parameters: enabled ( bool
) – True to enable the phase, False to disable itSince: 5.0
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.

LSPhase.
time_limit
¶ Time limit of this phase in seconds. It is a shortcut for
get_time_limit()
andset_time_limit()
.

LSPhase.
iteration_limit
¶ Iteration limit of this phase. It is a shortcut for
get_iteration_limit()
andset_iteration_limit()
.

LSPhase.
optimized_objective
¶ Index of the optimized objective of this phase. It is a shortcut for
get_optimized_objective()
andset_optimized_objective()
.

LSPhase.
enabled
¶ Enabled status of this phase. It is a shortcut for
is_enabled()
andset_enabled()
.