LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.

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

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, std::string, LSPMap, LSPFunction…) or manipulated through 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.

Since:10.0

Summary

Functions
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.
getExpression Returns the LSExpression with the given name.
getString Returns the string with the given name.
getFunction Returns the LSPFunction with the given name.
getMap Returns the LSPMap with the given name.
getModule Returns the LSPModule with the given name.
setValue Sets the value associated with the variable with the given name.
setMap Sets the map associated with the variable with the given name.
setModule Sets the module associated with the variable with the given name.
setFunction Sets the function associated with the variable with the given name.
setExpression Sets the LSExpression associated with the variable with the given name.
setString Sets the string associated with the variable with the given name.
setDouble Sets the double value associated with the variable with the given name.
setInt Sets the integer value associated with the variable with the given name.
setBool Sets the boolean value associated with the variable with the given name.
setNil Unsets the variable with the given name.
unset Unsets the variable with the given name.
isMap Returns true if the variable with the given name exists and holds an LSPMap.
isModule Returns true if the variable with the given name exists and holds an LSPModule.
isFunction Returns true if the variable with the given name exists and holds an LSPFunction.
isExpression Returns true if the variable with the given name exists and holds an LSExpression.
isString Returns true if the variable with the given name exists and holds a string value.
isDouble Returns true if the variable with the given name exists and holds a double value.
isInt Returns true if the variable with the given name exists and holds an integer value.
isBool Returns true if the variable with the given name exists and holds a boolean value.
isNil Returns true if no variable with this name exists in the module or if the variable holds a nil value.
asValue Returns the module as an LSPValue.

Functions

void localsolver::modeler::LSPModule::parseArguments(const std::vector<std::string> &args)

Parses the list of arguments and imports them in the module.

Each argument must be of the form argName=argValue.

Parameters:args - List of arguments.

void localsolver::modeler::LSPModule::parseArguments(int argc, const char *const *argv)

Parses the list of arguments and imports them in the module.

Each argument must be of the form argName=argValue.

Parameters:
  • argc - Number of arguments.
  • argv - Pointer to the first argument in the list.

void localsolver::modeler::LSPModule::run()

Entry point to the execution of a module.

Such 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 localsolver.LSModel is then closed.
  • The param function is executed if it exists in the module.
  • The function localsolver.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.

void localsolver::modeler::LSPModule::run(const std::vector<std::string> &arguments)

Entry point to the execution of a module.

This is a shortcut to parsing arguments with LSPModule#parseArguments before calling LSPModule#run.

See:LSPModule.parseArguments
See:LSPModule.run
Parameters:arguments - List of arguments

void localsolver::modeler::LSPModule::run(int argc, const char *const *argv)

Entry point to the execution of a module.

This is a shortcut to parsing arguments with LSPModule#parseArguments before calling LSPModule#run.

See:

LSPModule.parseArguments

See:

LSPModule.run

Parameters:
  • argc - Number of arguments.
  • argv - Point to the first arguments in the list.

LSPType localsolver::modeler::LSPModule::getType(const std::string &varName)
const

Returns the type of the variable with the given name.

If the variable does not exist in the module, LSP_Nil is returned.

Return:Type of the variable.
See:LSPType
Parameters:varName - Name of the variable.

LSPValue localsolver::modeler::LSPModule::getValue(const std::string &varName)
const

Returns the LSPValue with the given name.

If the variable does not exist in the module, an LSPValue representing a nil value is returned.

Return:LSPValue associated with the given name.
See:LSPValue.
Parameters:varName - Name of the variable.

lsint localsolver::modeler::LSPModule::getInt(const std::string &varName)
const

Returns the integer variable with the given name.

The variable must exist and must hold an integer value.

Return:Integer value associated with the given name.
Parameters:varName - Name of the variable.

lsdouble localsolver::modeler::LSPModule::getDouble(const std::string &varName)
const

Returns the double variable with the given name.

The variable must exist and must hold a double value.

Return:Double value associated with the given name.
Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::getBool(const std::string &varName)
const

Returns the boolean variable with the given name.

The variable must exist and must hold a boolean value.

Return:Boolean value associated with the given name.
Parameters:varName - Name of the variable.

LSExpression localsolver::modeler::LSPModule::getExpression(const std::string &varName)
const

Returns the LSExpression with the given name.

The variable must exist and must hold a value of type LSP_Expression.

Return:LSExpression associated with the given name.
Parameters:varName - Name of the variable.

std::string localsolver::modeler::LSPModule::getString(const std::string &varName)
const

Returns the string with the given name.

The variable must exist and must hold a string value.

Return:String associated with the given name.
Parameters:varName - Name of the variable.

LSPFunction localsolver::modeler::LSPModule::getFunction(const std::string &varName)
const

Returns the LSPFunction with the given name.

The variable must exist and must hold a function.

Return:LSPFunction associated with the given name.
Parameters:varName - Name of the variable.

LSPMap localsolver::modeler::LSPModule::getMap(const std::string &varName)
const

Returns the LSPMap with the given name.

The variable must exist and must hold a map.

Return:LSPMap associated with the given name.
Parameters:varName - Name of the variable.

LSPModule localsolver::modeler::LSPModule::getModule(const std::string &varName)
const

Returns the LSPModule with the given name.

The variable must exist and must hold a module.

Return:LSPModule associated with the given name.
Parameters:varName - Name of the variable.

void localsolver::modeler::LSPModule::setValue(const std::string &varName, const LSPValue &value)

Sets the value associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • value - Value of the variable.

void localsolver::modeler::LSPModule::setMap(const std::string &varName, const LSPMap &map)

Sets the map associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • map - Value of the variable.

void localsolver::modeler::LSPModule::setModule(const std::string &varName, const LSPModule &module)

Sets the module associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • module - Value of the variable.

void localsolver::modeler::LSPModule::setFunction(const std::string &varName, const LSPFunction &function)

Sets the function associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • function - Value of the variable.

void localsolver::modeler::LSPModule::setExpression(const std::string &varName, const LSExpression &expr)

Sets the LSExpression associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • expr - Value of the variable.

void localsolver::modeler::LSPModule::setString(const std::string &varName, const std::string &value)

Sets the string associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • value - Value of the variable.

void localsolver::modeler::LSPModule::setDouble(const std::string &varName, lsdouble value)

Sets the double value associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • value - Value of the variable.

void localsolver::modeler::LSPModule::setInt(const std::string &varName, lsint value)

Sets the integer value associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • value - Value of the variable.

void localsolver::modeler::LSPModule::setBool(const std::string &varName, bool value)

Sets the boolean value associated with the variable with the given name.

The variable is automatically created if it doesn’t exist in the module.

Parameters:
  • varName - Name of the variable.
  • value - Value of the variable.

void localsolver::modeler::LSPModule::setNil(const std::string &varName)

Unsets the variable with the given name.

Do nothing it the variable does not exist.

Parameters:varName - Name of the variable.

void localsolver::modeler::LSPModule::unset(const std::string &varName)

Unsets the variable with the given name.

Do nothing it the variable does not exist.

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isMap(const std::string &varName)
const

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

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isModule(const std::string &varName)
const

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

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isFunction(const std::string &varName)
const

Returns true if the variable with the given name exists and holds an LSPFunction.

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isExpression(const std::string &varName)
const

Returns true if the variable with the given name exists and holds an LSExpression.

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isString(const std::string &varName)
const

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

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isDouble(const std::string &varName)
const

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

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isInt(const std::string &varName)
const

Returns true if the variable with the given name exists and holds an integer value.

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isBool(const std::string &varName)
const

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

Parameters:varName - Name of the variable.

bool localsolver::modeler::LSPModule::isNil(const std::string &varName)
const

Returns true if no variable with this name exists in the module or if the variable holds a nil value.

Parameters:varName - Name of the variable.

LSPValue localsolver::modeler::LSPModule::asValue()
const

Returns the module as an LSPValue.