# LSBlackBoxContext Class¶

class localsolver.LSBlackBoxContext

Context of an black-box function. Black-box contexts can be used to query and set properties of the associated black-box function.

If you know the bounds of your black-box 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 LSExpression.get_blackbox_context()

## Summary¶

 lower_bound Lower bound of the black-box function. upper_bound Upper bound of the black-box function. nanable True if the function can return a NaN value, false otherwise. evaluation_limit Maximum number of black-box evaluations.
 get_lower_bound Gets the lower bound of the exernal function. get_upper_bound Gets the upper bound of the black-box function. is_nanable Returns true if the function can return a NaN value. get_evaluation_limit Returns the maximum number of black-box evaluations. set_lower_bound Sets the lower bound of the black-box function. set_upper_bound Sets the upper bound of the black-box function. set_nanable Sets whether or not the function can return a NaN value. set_evaluation_limit Sets the maximum number of black-box evalutions. create_evaluation_point Creates an evaluation point for the black-box function. get_nb_evaluation_points Returns the number of black-box evaluation points. get_evaluation_point Returns the black-box evaluation point at the given position.

## Instance methods¶

LSBlackBoxContext.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 black-box function. int or double
LSBlackBoxContext.get_upper_bound()

Gets the upper bound of the black-box function. By default, this property is set to a large integer number or math.inf.

Returns: Upper bound of the black-box function. int or double
LSBlackBoxContext.is_nanable()

Returns true if the function can return a NaN value. Only allowed if the black-box function is a double function. By default, this property is set to true.

Returns: True if the function can return a NaN value.
LSBlackBoxContext.get_evaluation_limit()

Returns the maximum number of black-box evaluations. By default, the maximum number of evaluations is set to the largest positive integer on 32 bits, that is 2^32-1 = 2,147,483,647 > 10^9.

Returns: Maximum number of black-box evaluations.
LSBlackBoxContext.set_lower_bound(lower_bound)

Sets the lower bound of the black-box function. Only allowed in state LSState.MODELING.

Parameters: lower_bound – Lower bound of the function.
LSBlackBoxContext.set_upper_bound(upper_bound)

Sets the upper bound of the black-box function. Only allowed in state LSState.MODELING.

Parameters: upper_bound – Upper bound of the function.
LSBlackBoxContext.set_nanable(nanable)

Sets whether or not the function can return a NaN value. Only allowed if the black-box function is a double function. Only allowed in state LSState.MODELING.

Parameters: nanable – True if the function can return a NaN value, false otherwise.
LSBlackBoxContext.set_evaluation_limit(evaluation_limit)

Sets the maximum number of black-box evalutions. By default, the maximum number of evaluations is set to the largest positive integer on 32 bits, that is 2^32-1 = 2,147,483,647 > 10^9. Only allowed in state STOPPED.

Parameters: evaluationLimit – Maximum number of black-box evaluations.
LSBlackBoxContext.create_evaluation_point()

Creates an evaluation point for the black-box function. It consists of a list of values corresponding to the function’s arguments and return value. Evaluation points are used to specify known points for a function in advance. It can be useful to warm-start the solver when the function is particularly expensive to evaluate, or if you already have a good estimate of the optimal point. Only allowed in state STOPPED.

Returns: Black-box evaluation point. LSBlackBoxEvaluationPoint
LSBlackBoxContext.get_nb_evaluation_points()

Returns the number of black-box evaluation points. Only allowed in state STOPPED.

Returns: Number of black-box evaluation points. int
LSBlackBoxContext.get_evaluation_point(pos)

Returns the black-box evaluation point at the given position. Only allowed in state STOPPED.

Parameters: pos – Position of the black-box evaluation point. Black-box evaluation point at the given position. LSBlackBoxEvaluationPoint

## 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.

LSBlackBoxContext.lower_bound

Lower bound of the black-box function. It is a shortcut for get_lower_bound() and set_lower_bound().

LSBlackBoxContext.upper_bound

Upper bound of the black-box function. It is a shortcut for get_upper_bound() and set_upper_bound().

LSBlackBoxContext.nanable

True if the function can return a NaN value, false otherwise. It is a shortcut for is_nanable() and set_nanable().

LSBlackBoxContext.evaluation_limit

Maximum number of black-box evaluations. It is a shortcut for get_evaluation_limit() and set_evaluation_limit()