LSBBModel Class

class localsolverblackbox.LSBBModel

A model is composed of a native function (the blackbox), a number of decisions and a function call that associates the decisions and the function. Once your optimization model is created and closed, the solver can be launched to resolve it. Note that you cannot modify a model which has been closed.

Summary

Methods
call Creates a call expression.
create_native_function Creates a native function.
bool Creates a boolean decision.
int Creates an integer decision.
float Creates a float decision.
add_objective Setss the given expression to be the list of objectives to optimize.
close Closes the model.
is_closed Returns true if the model is closed, false otherwise.

Instance methods

LSBBModel.call()

Creates a call expression. First operand must be an LSBBExpression of type LSBBOperator.NATIVE_FUNCTION. The other operands must be booleans, integers or doubles decisions.

Returns:Expression of type LSBBOperator.CALL
Return type:LSBBExpression
LSBBModel.create_native_function(function)

Creates a native function. The provided function must take the native context (LSBBNativeContext) associated to the function as single argument and must return a number (int or double value).

Once you instanciated it, you have to pass arguments to your function and call it. For that, you have to create expressions of type LSBBOperator.CALL. The first operand must be your native function. The other operands must be LSBBExpressions. Their value will be made accessible to your function through the native context.

Note 1: Most of the time your native function will be called when the solver is in state LSBBState.RUNNING. Do not attempt to call any method of the solver (to retrieve statistics, values of LSBBExpressions or whatever) in that state or an exception will be thrown. The only accessible function is LocalSolverBlackBox.stop().

Parameters:function – A python function that accepts LSBBNativeContext as first argument and returns a number (int or double value).
Returns:Expression of type LSBBOperator.NATIVE_FUNCTION.
Return type:LSBBExpression
LSBBModel.bool()

Creates a boolean decision. Binary decision variable with domain [0.1].

Returns:Expression of type LSBBOperator.BOOL
Return type:LSBBExpression
LSBBModel.int(min, max)

Creates an integer decision. Decision variable with domain [min,max]. Bounds of the variable must be booleans or integers.

Returns:Expression of type LSBBOperator.INT
Return type:LSBBExpression
LSBBModel.float(min, max)

Creates a float decision. Decision variable with domain [min,max]. Bounds of the variable must be booleans, integers or doubles.

Returns:Expression of type LSBBOperator.FLOAT
Return type:LSBBExpression
LSBBModel.add_objective(expr, direction)

Setss the given expression to be the list of objectives to optimize. A same expression can be added more than once. Only allowed in state LSState.MODELING.

Parameters:
LSBBModel.close()

Closes the model. Only allowed in state LSBBState.MODELING. Once the model is closed, no expression, constraints or objectives can be added. The model must be closed before starting its resolution. When the model is closed, the state of the LocalSolver changed from LSBBState.MODELING to LSBBState.STOPPED.

LSBBModel.is_closed()

Returns true if the model is closed, false otherwise.

Returns:True if the model is closed.
Return type:bool