LSPModeler Class¶
- class
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.
The creation of an LSPModeler environment results in the creation of a dedicated LocalSolver environment as well. For more information on how to use the solver’s API, see the LocalSolver class.
See: LocalSolver See: LSPModule Since: 10.0
Summary¶
LSPModeler |
Constructs a complete modeler environment. |
~LSPModeler |
Deletes this modeler environment and all associated objects. |
loadModule |
Loads a program written in LSP format into an LSPModule whose name corresponds to the provided filename (without path and . |
createModule |
Creates an empty module with the given name. |
getSolver |
Returns a pointer to the LocalSolver environment associated with this modeler instance. |
createFunction |
Creates an external LSPFunction. |
createMap |
Creates an LSPMap. |
createNil |
Creates a nil value. |
createInt |
Creates an integer value. |
createDouble |
Creates a double value. |
createBool |
Creates a boolean value. |
createString |
Creates a string value. |
Functions¶
-
localsolver::modeler::LSPModeler
::
LSPModeler
()¶ Constructs a complete modeler environment.
This has the effect of also creating a dedicated LocalSolver environment (see LocalSolver#LocalSolver). A pointer to the solver environment can be obtained via getSolver.
See: LocalSolver
-
localsolver::modeler::LSPModeler
::
~LSPModeler
()¶ Deletes this modeler environment and all associated objects.
This also deletes the solver environment, see LocalSolver#~LocalSolver.
-
LSPModule
localsolver::modeler::LSPModeler
::
loadModule
(const std::string &file)¶ Loads a program written in LSP format into an LSPModule whose name corresponds to the provided filename (without path and .lsp extension).
The variables of the module can be manipulated through the associated LSPModule object.
Return: Module created. See: LSPModule Parameters: file - Path to the file.
-
LSPModule
localsolver::modeler::LSPModeler
::
createModule
(const std::string &moduleName)¶ Creates an empty module with the given name.
The variables of the module can then be manipulated through the associated LSPModule object.
Return: Module created. See: LSPModule Parameters: moduleName - Module name.
-
LocalSolver *
localsolver::modeler::LSPModeler
::
getSolver
()¶ Returns a pointer to the LocalSolver environment associated with this modeler instance.
Return: Solver. See: LocalSolver
-
LSPFunction
localsolver::modeler::LSPModeler
::
createFunction
(LSPFunctor *functor)¶ Creates an external LSPFunction.
The argument must be derived from LSPFunctor. When the function is called, the modeler instance will be made accessible to the function, as well as the 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”.
class MyCustomFunction : public LSPFunctor { LSPValue call(LSPModeler& modeler, const LSPValue* args, int nbArgs) override { return modeler.createDouble(arguments[0].asDouble() + arguments[1].asDouble()); } }; MyCustomFunction customFunctor; module.setFunction("myCustomFunction", modeler.createFunction(&customFunctor));
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 a blackbox or external function. In this case, you should instead use the solver API directly (see LSExternalFunction or LSBlackBoxFunction)
Return: Function created. See: LSPFunctor See: LSPFunction Parameters: functor - Implementation of the external function.
-
LSPFunction
localsolver::modeler::LSPModeler
::
createFunction
(const std::string &name, LSPFunctor *functor)¶ Creates an external LSPFunction.
The argument must be derived from LSPFunctor. When the function is called, the modeler instance will be made accessible to the function, as well as the 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”.
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 a blackbox or external function. In this case, you should instead use the solver API directly (see LSExternalFunction or LSBlackBoxFunction).
Return: Function created.
See: See: Parameters: - name - Name of the function. 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.
- functor - Implementation of the external function.
-
LSPMap
localsolver::modeler::LSPModeler
::
createMap
()¶ Creates an LSPMap.
A map is a data structure mapping keys to values that can also be used as an array-like structure. Keys and values can be of any type except nil. The map can be assigned to any variable in a module with LSPModule#setMap or can be part of another map with LSPMap#setMap.
Return: Map created. See: LSPMap
-
LSPValue
localsolver::modeler::LSPModeler
::
createNil
()¶ Creates a nil value.
Return: Created nil value. See: LSPValue
-
LSPValue
localsolver::modeler::LSPModeler
::
createInt
(lsint value)¶ Creates an integer value.
The value can be assigned to any variable in a module with LSPModule#setValue or can be part of a map as key or value.
Return: Created integer value. See: LSPValue
-
LSPValue
localsolver::modeler::LSPModeler
::
createDouble
(lsdouble value)¶ Creates a double value.
The value can be assigned to any variable in a module with LSPModule#setValue or can be part of a map as key or value.
Return: Created double value. See: LSPValue
-
LSPValue
localsolver::modeler::LSPModeler
::
createBool
(bool value)¶ Creates a boolean value.
Please note that there is no dedicated type for booleans in the modeler. They are simulated with integers: 1 denotes true and 0 denotes false. The created value can be assigned to any variable in a module with LSPModule#setValue or can be part of a map as key or value.
Return: Created boolean value. See: LSPValue
-
LSPValue
localsolver::modeler::LSPModeler
::
createString
(const std::string &value)¶ Creates a string value.
The value can be assigned to any variable in a module with LSPModule#setValue or can be part of a map as key or value.
Return: Created string value. See: LSPValue