LSPModeler Class¶
- class LSPModeler¶
Modeler environment. Main class of the Modeler library which enables the creation and manipulation of a virtual machine that can load and execute programs written in the LSP language (see the language reference for more information).
- Since
10.0
Summary¶
Stream used by the modeler for its standard output methods. |
|
Stream used by the modeler for its standard error output methods. |
Returns a new LocalSolver instance that can be used to launch a module with the method LSPModule.run(). |
|
Loads a program written in LSP format into a LSPModule whose name corresponds to the filename. |
|
Creates an empty module with the given name. |
|
Creates a LSPMap. |
|
Creates an external LSPFunction. |
|
Deletes this modeler environment and all associated resources. |
|
Returns the stream used by the modeler for its standard output methods like print. |
|
Sets the stream used by the modeler for its standard output methods like print. |
|
Returns the stream used by the modeler for its standard error output. |
|
Sets the stream used by the modeler for its standard error output. |
Instance attributes¶
- LSPModeler.stdout¶
Stream used by the modeler for its standard output methods. This is a shortcut for
LSPModeler.get_stdout()
.
- LSPModeler.stderr¶
Stream used by the modeler for its standard error output methods. This is a shortcut for
LSPModeler.get_stderr()
.
Instance methods¶
- LSPModeler.create_solver()¶
Returns a new LocalSolver instance that can be used to launch a module with the method
LSPModule.run()
. The returned solver will be automatically disposed when the modeler is destroyed or when the current reference scope is released.- Returns
Solver.
- Return type
- See
- LSPModeler.load_module(filepath)¶
Loads a program written in LSP format into a
LSPModule
whose name corresponds to the filename. The variables of the module can be manipulated through the returned module object.- Parameters
filepath (
str
) – Path to the file.- Returns
Module loaded.
- Return type
- LSPModeler.create_module(module_name)¶
Creates an empty module with the given name. The variables of the module can be manipulated through the return module object.
- Parameters
module_name (
str
) – Name of the module.- Returns
Module created.
- Return type
- LSPModeler.create_map()¶
Creates a
LSPMap
. A map is a data structure mapping keys to values that can also be used as an array-like structure. The map can be assigned to any variable in a module withLSPModule.__setitem__()
or can be part of another map withLSPMap.__setitem__()
.- Returns
Map created.
- Return type
- LSPModeler.create_function(name, function)¶
- LSPModeler.create_function(function)
Creates an external
LSPFunction
. The provided function must take a modeler instance as first argument and the LSP function arguments as subsequent arguments. For instance, the following example creates a simple function that accepts two arguments and returns the sum of both values. The generated function is then exposed in an LSP module under the name “myCustomFunction”:def my_custom_function(modeler, arg1, arg2): return arg1 + arg2 module["myCustomFunction"] = modeler.create_function(my_custom_function)
Note: This method should only be used to expose functions used during the modeling process. You should not use this method to create a function that will be used during the resolution as an external function. In this case, you should instead use the solver API directly (see
LSModel.create_int_external_function()
orLSModel.create_double_external_function()
for example).- Parameters
function – A python function that accepts a modeler instance as first argument and the LSP function arguments as subsequent arguments. The function must returns a value whose type is supported by the modeler (None, int, float, str, LSPMap, LSPFunction, LSPModule, LSExpression)
name (
str
) – Name of the function (optional). The name is only used to identify the function in the generated stack trace when an exception occurs. Once created, the function can be associated with any variable in any module, regardless of its name.
- Returns
Function created.
- Return type
- LSPModeler.delete()¶
Deletes this modeler environment and all associated resources. This also deletes the solvers created using
LSPModeler.create_solver()
. This method is automatically called when you use the LSPModeler in awith
statement.
- LSPModeler.get_stdout()¶
Returns the stream used by the modeler for its standard output methods like print. The default stream used by the modeler corresponds to the Python standard output, retrieved with sys.stdout.
You can also use the shortcut member
stdout
- Returns
The stream used by the modeler for its standard output or null if the standard output is disabled.
- LSPModeler.set_stdout(stream)¶
Sets the stream used by the modeler for its standard output methods like print. The default is to redirect all the modeler’s outputs to the Python standard output. If the given stream is null, the standard output of the modeler will be disabled and all calls to the print related functions will do nothing.
- Parameters
stream – stream to use for the standard output or null to disable standard output.
- LSPModeler.get_stderr()¶
Returns the stream used by the modeler for its standard error output. The default stream used by the modeler corresponds to the Python standard error output, retrieved with sys.stderr.
You can also use the shortcut member
stderr
- Returns
The stream used by the modeler for its standard error output or null if the standard error output is disabled.
- LSPModeler.set_stderr(stream)¶
Sets the stream used by the modeler for its standard error output. The default is to redirect the standard error output stream to the Python standard error output stream. If the given stream is null, the standard error output of the modeler will be disabled.
- Parameters
stream – stream to use for the standard error output or null to disable standard error output.