LSExternalContext Class¶
- class localsolver.LSExternalContext¶
Context of an external function. External context can be used to query and set properties of the associated external function.
If you know the bounds of your external function or if you know it cannot return a NaN value, we recommend you to specify it as LocalSolver is then able to improve its search process. But beware! If the evaluation of the function returns an unexpected value (like a value outside of the bounds), an exception will be thrown during the search.
- Since
9.5
- See
Summary¶
Lower bound of the external function. |
|
Upper bound of the external function. |
|
True if the function can return a NaN value, false otherwise. |
Gets the lower bound of the exernal function. |
|
Gets the upper bound of the external function. |
|
Sets the lower bound of the external function. |
|
Sets the upper bound of the external function. |
|
Returns true if the function can return a NaN value. |
|
Sets whether or not the function can return a NaN value. |
|
Enables the surrogate modeling on the associated external function. |
Instance methods¶
- LSExternalContext.get_lower_bound()¶
Gets the lower bound of the exernal function. By default, this property is set to a large integer number or math.inf.
- Returns
Lower bound of the external function.
- Return type
int
ordouble
- LSExternalContext.get_upper_bound()¶
Gets the upper bound of the external function. By default, this property is set to a large integer number or math.inf.
- Returns
Upper bound of the external function.
- LSExternalContext.set_lower_bound(lower_bound)¶
Sets the lower bound of the external function. If it is an array function, the bound will apply to all elements of the array. Only allowed in state
LSState.MODELING
.- Parameters
lower_bound – Lower bound of the function.
- LSExternalContext.set_upper_bound(upper_bound)¶
Sets the upper bound of the external function. If it is an array function, the bound will apply to all elements of the array. Only allowed in state
LSState.MODELING
.- Parameters
upper_bound – Upper bound of the function.
- LSExternalContext.is_nanable()¶
Returns true if the function can return a NaN value. Only allowed if the external function is a double function. By default, this property is set to true.
- Returns
True if the function can return a NaN value.
- LSExternalContext.set_nanable(nanable)¶
Sets whether or not the function can return a NaN value. Only allowed if the external function is a double function. If it is an array function, this parameter will apply to all elements of the array. Only allowed in state
LSState.MODELING
.- Parameters
nanable – True if the function can return a NaN value, false otherwise.
- LSExternalContext.enable_surrogate_modeling()¶
Enables the surrogate modeling on the associated external function. This method changes the internal behavior of the solver: the solver now considers that the function is computationally expensive and therefore uses surrogate modeling. This method returns the
LSSurrogateParameters
which are used to parameterize various aspects of surrogate modeling. Note: Once the surrogate modeling is enabled, it cannot be disabled. Only allowed in stateMODELING
.For more information, please see the section dedicated to surrogate modeling among the modeling features.
- Returns
Surrogate parameters.
- Return type
Instance attributes¶
All get/set
methods have their attribute counterpart. You can use them as
shortcuts to improve the readability of your models and codes.
- LSExternalContext.lower_bound¶
Lower bound of the external function. It is a shortcut for
get_lower_bound()
andset_lower_bound()
.
- LSExternalContext.upper_bound¶
Upper bound of the external function. It is a shortcut for
get_upper_bound()
andset_upper_bound()
.
- LSExternalContext.nanable¶
True if the function can return a NaN value, false otherwise. It is a shortcut for
is_nanable()
andset_nanable()
.