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 variables 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.

Summary

Methods

parse_arguments

Parses the arguments and imports them in the module.

run

Entry point to the execution of a module.

Special methods

__getitem__

Returns the value of the variable with the given name.

__setitem__

Sets the value of the variable with the given name.

__delitem__

Resets the value of the variable with the given name to nil if the variable exists in the module.

__contains__

Returns true if the variable with the given name exists in the module and if its value is not nil (None in python).

Instance methods

LSPModule.parse_arguments(\*args)

Parses the arguments and imports them in the module. Each argument must be strings of the form argName=argValue.

Parameters

args (str or list of str) – List of arguments.

LSPModule.run(\*args)

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.

If arguments are passed to this method, they are imported into the module via parse_arguments().

Parameters

args (str or list of str) – Optional list of arguments.

Special operators and methods

LSPModule.__getitem__(var_name)

Returns the value of the variable with the given name. If the variable doesn’t exist in the module, None is returned. This method can return values of the following types:

This method is automatically called by python when using special constructs like value = myModule[var_name].

Parameters

var_name (str) – Name of the variable.

LSPModule.__setitem__(var_name, value)

Sets the value of the variable with the given name. The variable is automatically created if it doesn’t exist in the module. This method accepts the following types as input value:

Setting a variable to None has the same effect as calling __delitem__() on the variable.

This method is automatically called by python when using special constructs like myModule[var_name] = value.

Parameters
  • var_name (str) – Name of the variable.

  • value – Value to set.

LSPModule.__delitem__(var_name, value)

Resets the value of the variable with the given name to nil if the variable exists in the module. Do nothing if the variable was not declared or if the variable is already nil. This method is automatically called by python when using special constructs like del myModule[var_name].

After calling this method, var_name in myModule returns false and myModule[var_name] returns None.

LSPModule.__contains__(var_name)

Returns true if the variable with the given name exists in the module and if its value is not nil (None in python). Returns false otherwise. This method is automatically called by python when using special constructs like var_name in myModule.