This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

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 an LSPValue 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

Methods
ParseArguments Parses the list of arguments and imports them in the module.
Run Entry point to the execution of a module.
GetType Returns the type of the variable with the given name.
GetValue Returns the LSPValue with the given name.
GetInt Returns the integer variable with the given name.
GetDouble Returns the double variable with the given name.
GetBool Returns the boolean variable with the given name.
GetString Returns the string variable with the given name.
GetExpression Returns the LSExpression variable with the given name.
GetFunction Returns the LSPFunction variable with the given name.
GetModule Returns the LSPModule variable with the given name.
GetMap Returns the LSPMap variable with the given name.
SetValue Sets the value associated with the given name.
SetInt Sets the integer value associated with the given name.
SetDouble Sets the double value associated with the given name.
SetBool Sets the boolean value associated with the given name.
SetString Sets the string value associated with the given name.
SetExpression Sets the LSExpression associated with the given name.
SetFunction Sets the function associated with the given name.
SetModule Sets the module associated with the given name.
SetMap Sets the map associated with the given name.
SetNil Unsets the variable with the given name.
Unset Unsets the variable with the given name.
IsNil Returns true if no variable with this name exists in the module or if the variable holds a nil value.
IsInt Returns true if the variable with the given name exists and holds an integer value.
IsDouble Returns true if the variable with the given name exists and holds a double value.
IsBool Returns true if the variable with the given name exists and holds a boolean value.
IsString Returns true if the variable with the given name exists and holds a boolean value.
IsExpression Returns true if the variable with the given name exists and holds a LSExpression.
IsFunction Returns true if the variable with the given name exists and holds a LSPFunction.
IsModule Returns true if the variable with the given name exists and holds a LSPModule.
IsMap 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 the display 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:LSPType
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:LSPValue
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:LSExpression
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:LSPFunction
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:LSPModule
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:LSPMap
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.
bool IsModule(string varName)

Returns true if the variable with the given name exists and holds a LSPModule.

Arguments:varName (string) – Name of the variable.
bool IsMap(string varName)

Returns true if the variable with the given name exists and holds a LSPMap.

Arguments:varName (string) – Name of the variable.