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.

LSPModeler Class

class localsolver.modeler.LSPModeler

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 (see the language reference).

The creation of a modeler 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

Methods

Dispose

Deletes this modeler environment.

LoadModule

Loads a program written in LSP format into a LSPModule whose name corresponds to the provided filename.

CreateModule

Creates an empty module with the given name.

GetSolver

Returns the LocalSolver environment associated with this modeler instance.

CreateFunction

Creates an external LSPFunction.

CreateMap

Creates a 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.

Instance methods

LSPModeler()

Constructs a complete modeler environment. This has the effect of also creating a dedicated LocalSolver environment. A reference to the solver can be obtained via GetSolver().

See

LocalSolver

void Dispose()

Deletes this modeler environment. This includes the solver environment as well.

LSPModule LoadModule(string filepath)

Loads a program written in LSP format into a LSPModule whose name corresponds to the provided filename. The variables of the module can be manipulated through the associated LSPModule object.

Arguments

filepath (string) – Path to the file.

Returns

Module loaded.

Return type

LSPModule

LSPModule CreateModule(string moduleName)

Creates an empty module with the given name. The variables of the module can then be manipulated through the associated LSPModule object.

Arguments

moduleName (string) – Name of the module.

Returns

Module created.

Return type

LSPModule

LocalSolver GetSolver()

Returns the LocalSolver environment associated with this modeler instance.

Returns

Solver associated with this modeler.

Return type

LocalSolver

LSPFunction CreateFunction(LSPFunctor functor)
LSPFunction CreateFunction(string name, LSPFunctor functor)

Creates an external LSPFunction. The argument must implement LSPFunctor. When the function is called, the modeler instance will be made accessible to the function, as well as the arguments in a list.

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”:

module.SetFunction("myCustomFunction", (modeler, arguments) => {
    return modeler.CreateDouble(arguments[0].AsDouble() + arguments[1].AsDouble());
});

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 an external function. In this case, you should instead use the solver API directly (see LSExternalFunction Delegate).

Arguments
  • functor – External function to call, passed as a delegate.

  • name (string) – Name of the function (optional). 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.

Returns

Function created.

See

LSPFunctor

LSPMap CreateMap()

Creates a LSPMap. A map is a data structure mapping keys to values that can also be used as an array-like structure. The map can be assigned to any variable in a module thanks to LSPModule.SetMap() or can be part of another map with LSPMap.SetMap().

Returns

Map created.

See

LSPMap

LSPMap CreateMap(IList<long> values)
LSPMap CreateMap(IList<double> values)
LSPMap CreateMap(IList<bool> values)
LSPMap CreateMap(IList<string> values)
LSPMap CreateMap(IList<LSPFunction> values)
LPSMap CreateMap(IList<LSPMap> values)
LSPMap CreateMap(IList<LSPModule> values)
LSPMap CreateMap(IList<LSPValue> values)

Creates a LSPMap and fills it with the provided values. The map can be assigned to any variable in a module with LSPModule.SetMap() or can be part of another map with LSPMap.SetMap().

Returns

Map created.

See

LSPMap

LSPValue CreateNil()

Creates a nil value.

Returns

Nil value created.

See

LSPValue

LSPValue CreateInt(long 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.

Returns

Integer value created.

See

LSPValue

LSPValue CreateDouble(double 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.

Returns

Double value created.

See

LSPValue

LSPValue CreateBool(bool value)

Creates a boolean 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.

Returns

Boolean value created.

See

LSPValue

LSPValue CreateString(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.

Returns

String value created.

See

LSPValue