LSPModule Class¶
- class localsolver.modeler.LSPModule¶
A module is a collection of global variables. As LSP is a dynamically typed language, global variable can contain any value (including functions and other modules). Each LSP file is a module.
Global variables can be modified and accessed by their name specified as a string. Most of the functions below exist in multiple versions: values of the global variables can be manipulated through their native type (like
int
,float
,String
,LSPMap
,LSPFunction
…) or manipulated with anLSPValue
which is a container that can hold any type of value. Using the native type is more convenient and results in less overhead most of the time.LSPValue
should only be used when you don’t know the type of the manipulated value.
Summary¶
Parses the list of arguments and imports them in the module. |
|
Entry point to the execution of a module. |
|
Returns the type of the variable with the given name. |
|
Returns the LSPValue with the given name. |
|
Returns the integer variable with the given name. |
|
Returns the double variable with the given name. |
|
Returns the boolean variable with the given name. |
|
Returns the string variable with the given name. |
|
Returns the LSExpression variable with the given name. |
|
Returns the LSPFunction variable with the given name. |
|
Returns the LSPModule variable with the given name. |
|
Returns the LSPMap variable with the given name. |
|
Sets the value associated with the given name. |
|
Sets the integer value associated with the given name. |
|
Sets the double value associated with the given name. |
|
Sets the boolean value associated with the given name. |
|
Sets the string value associated with the given name. |
|
Sets the LSExpression associated with the given name. |
|
Sets the function associated with the given name. |
|
Sets the module associated with the given name. |
|
Sets the map associated with the given name. |
|
Unsets the variable with the given name. |
|
Unsets the variable with the given name. |
|
Returns true if no variable with this name exists in the module or if the variable holds a nil value. |
|
Returns true if the variable with the given name exists and holds an integer value. |
|
Returns true if the variable with the given name exists and holds a double value. |
|
Returns true if the variable with the given name exists and holds a boolean value. |
|
Returns true if the variable with the given name exists and holds a boolean value. |
|
Returns true if the variable with the given name exists and holds a LSExpression. |
|
Returns true if the variable with the given name exists and holds a LSPFunction. |
|
Returns true if the variable with the given name exists and holds a LSPModule. |
|
Returns true if the variable with the given name exists and holds a LSPMap. |
Instance methods¶
- void ParseArguments(params string[] arguments)¶
- void ParseArguments(List<string> arguments)
Parses the list of arguments and imports them in the module. Each argument must be of the form
argName=argValue
.- Arguments
arguments – List of arguments.
- void Run()¶
- void Run(string commandLine)
- void Run(params string[] arguments)
- void Run(List<string> arguments)
Entry point to the execution of a module. Such an execution is defined by the following steps:
The
input
function is executed if it exists in the module.The
model
function is executed. It must be declared in the module.The corresponding
LSModel
is then closed.The
param
function is executed if it exists in the module.The function
LocalSolver.Solve()
is called on the corresponding solver instance. If thedisplay
function is defined, it will be called during the resolution process.The
output
function is executed if it exists in the module.
- Arguments
arguments – Arguments parsed before running the module.
- LSPType GetType(string varName)¶
Returns the type of the variable with the given name. If the variable does not exist in the module,
LSPType.Nil
is returned.- Arguments
varName (
string
) – Name of the variable.- Returns
Type of the variable.
- Return type
- LSPValue GetValue(string varName)¶
Returns the
LSPValue
with the given name. If the variable does not exist in the module, an LSPValue representing nil is returned.- Arguments
varName (
string
) – Name of the variable.- Returns
LSPValue associated with the given name.
- Return type
- long GetInt(string varName)¶
Returns the integer variable with the given name. The variable must exist and must hold an integer value.
- Arguments
varName (
string
) – Name of the variable.- Returns
Integer value associated with the given name.
- Return type
long
- double GetDouble(string varName)¶
Returns the double variable with the given name. The variable must exist and must hold a double value.
- Arguments
varName (
string
) – Name of the variable.- Returns
Double value associated with the given name.
- Return type
double
- bool GetBool(string varName)¶
Returns the boolean variable with the given name. The variable must exist and must hold a boolean value.
- Arguments
varName (
string
) – Name of the variable.- Returns
Boolean value associated with the given name.
- Return type
bool
- string GetString(string varName)¶
Returns the string variable with the given name. The variable must hold a string value.
- Arguments
varName (
string
) – Name of the variable.- Returns
String value associated with the given name.
- Return type
string
- LSExpression GetExpression(string varName)¶
Returns the
LSExpression
variable with the given name. The variable must exist and must hold an expression.- Arguments
varName (
string
) – Name of the variable.- Returns
Expression associated with the given name.
- Return type
- LSPFunction GetFunction(string varName)¶
Returns the
LSPFunction
variable with the given name. The variable must exist and must hold a function.- Arguments
varName (
string
) – Name of the variable.- Returns
Function associated with the given name.
- Return type
- LSPModule GetModule(string varName)¶
Returns the
LSPModule
variable with the given name. The variable must exist and must hold a module.- Arguments
varName (
string
) – Name of the variable.- Returns
Module associated with the given name.
- Return type
- LSPMap GetMap(string varName)¶
Returns the
LSPMap
variable with the given name. The variable must exist and must hold a map.- Arguments
varName (
string
) – Name of the variable.- Returns
Map associated with the given name.
- Return type
- void SetValue(string varName, LSPValue value)¶
Sets the value associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.value (LSPValue) – Value of the variable.
- void SetInt(string varName, long value)¶
Sets the integer value associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.value (long) – Integer value of the variable.
- void SetDouble(string varName, double value)¶
Sets the double value associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.value (double) – Double value of the variable.
- void SetBool(string varName, bool value)¶
Sets the boolean value associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.value (bool) – Boolean value of the variable.
- void SetString(string varName, string value)¶
Sets the string value associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.value (string) – String value of the variable.
- void SetExpression(string varName, LSExpression expr)¶
Sets the
LSExpression
associated with the given name. The variable is automatically created if it doesn’t exist in the module.- Arguments
varName (
string
) – Name of the variable.expr (LSExpression) – Value of the variable.
- void SetFunction(string varName, LSPFunction function)¶
Sets the function associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.function (LSPFunction) – Value of the variable.
- void SetModule(string varName, LSPModule module)¶
Sets the module associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.module (LSPModule) – Value of the variable.
- void SetMap(string varName, LSPMap map)¶
Sets the map associated with the given name. The variable is automatically created if it doesn’t exist in the module.
- Arguments
varName (
string
) – Name of the variable.map (LSPMap) – Value of the variable.
- void SetNil(string varName)¶
Unsets the variable with the given name. Do nothing it the variable does not exist.
- Arguments
varName (
string
) – Name of the variable.
- void Unset(string varName)¶
Unsets the variable with the given name. Do nothing it the variable does not exist.
- Arguments
varName (
string
) – Name of the variable.
- bool IsNil(string varName)¶
Returns true if no variable with this name exists in the module or if the variable holds a nil value.
- Arguments
varName (
string
) – Name of the variable.
- bool IsInt(string varName)¶
Returns true if the variable with the given name exists and holds an integer value.
- Arguments
varName (
string
) – Name of the variable.
- bool IsDouble(string varName)¶
Returns true if the variable with the given name exists and holds a double value.
- Arguments
varName (
string
) – Name of the variable.
- bool IsBool(string varName)¶
Returns true if the variable with the given name exists and holds a boolean value.
- Arguments
varName (
string
) – Name of the variable.
- bool IsString(string varName)¶
Returns true if the variable with the given name exists and holds a boolean value.
- Arguments
varName (
string
) – Name of the variable.
- bool IsExpression(string varName)¶
Returns true if the variable with the given name exists and holds a
LSExpression
.- Arguments
varName (
string
) – Name of the variable.
- bool IsFunction(string varName)¶
Returns true if the variable with the given name exists and holds a
LSPFunction
.- Arguments
varName (
string
) – Name of the variable.