HexalyModeler Class

class Hexaly.Modeler.HexalyModeler

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

See:

Hexaly.Optimizer.HexalyOptimizer

See:

HxmModule

Since:

10.0

Summary

Methods

Dispose

Deletes this modeler environment.

CreateOptimizer

Returns a new Hexaly Optimizer instance that can be used to launch a module with the method HxmModule.Run.

GetModule

Returns the module with the given name.

AddModuleLookupPath

Adds a new lookup path for modules.

ClearModuleLookupPaths

Deletes all paths used to search for modules.

LoadModule

Loads the module written in the Hexaly modeling language at the indicated location.

CreateModule

Creates an empty module with the given name.

CreateFunction

Creates an external HxmFunction.

CreateMap

Creates a HxmMap.

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.

GetStdOut

Returns the writer used by the modeler for its standard output methods like Write or WriteLine.

SetStdOut

Sets the writer used by the modeler for its standard output methods like Write or WriteLine.

GetStdErr

Returns the writer used by the modeler for its standard error output.

SetStdErr

Sets the writer used by the modeler for its standard error output.

Instance methods

HexalyModeler()

Constructs a complete modeler environment.

See:

Hexaly.Optimizer.HexalyOptimizer

void Dispose()

Deletes this modeler environment. All references bound to this modeler will be automatically freed. This also includes optimizers created using the HexalyModeler.CreateOptimizer method.

Hexaly.Optimizer.HexalyOptimizer CreateOptimizer()

Returns a new Hexaly Optimizer instance that can be used to launch a module with the method HxmModule.Run. The returned optimizer will be automatically disposed when the modeler is destroyed or when the current reference scope is released.

Returns:

Optimizer.

See:

Hexaly.Optimizer.HexalyOptimizer

HxmModule GetModule(string moduleName)

Returns the module with the given name. User modules can be accessed as well as builtin modules like the JSON module or the CSV module. If the module is not loaded, this method attempts to load it from the paths specified by AddModuleLookupPath.

The variables of the module can then be manipulated through the associated HxmModule object.

Arguments:

moduleName (string) – Module name.

Returns:

Module created.

Return type:

HxmModule

void AddModuleLookupPath(string path)

Adds a new lookup path for modules. The paths specified when calling this method are taken into account when the modeling virtual machine loads a module, either by a direct call to the GetModule method, or indirectly when loading a dependency to another module. By default, the lookup path contains at least the current runtime folder.

Arguments:

path (string) – New path to consider for modules.

void ClearModuleLookupPaths()

Deletes all paths used to search for modules. This method deletes all the paths previously added by AddModuleLookupPath method, as well as the default location(s) (including the current execution folder).

__Important note:__ after calling this method, you must at least add a path with AddModuleLookupPath. Without a path, you won’t be able to load any modules other than the native ones supplied by the virtual machine.

HxmModule LoadModule(string moduleName, string filePath)

Loads the module written in the Hexaly modeling language at the indicated location. The loaded module will take the name specified in parameter. Unlike GetModule, this method ignores all paths indicated by AddModuleLookupPath, and if a module with a similar name is already loaded, an exception will be thrown.

Once loaded, the variables of the module can be manipulated through the associated HxmModule` object.

Arguments:
  • moduleName (string) – Name taken by the module once loaded.

  • filePath (string) – Path to the module file.

Returns:

Module created.

Return type:

HxmModule

HxmModule CreateModule(string moduleName)

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

Arguments:

moduleName (string) – Name of the module.

Returns:

Module created.

Return type:

HxmModule

HxmFunction CreateFunction(HxmFunctor functor)
HxmFunction CreateFunction(string name, HxmFunctor functor)

Creates an external HxmFunction. The argument must implement HxmFunctor. 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 a 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 HxExternalFunction 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:

HxmFunctor

HxmMap CreateMap()

Creates a HxmMap. 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 HxmModule.SetMap() or can be part of another map with HxmMap.SetMap().

Returns:

Map created.

See:

HxmMap

HxmMap CreateMap(IList<long> values)
HxmMap CreateMap(IList<double> values)
HxmMap CreateMap(IList<bool> values)
HxmMap CreateMap(IList<string> values)
HxmMap CreateMap(IList<HxmFunction> values)
HxmMap CreateMap(IList<HxmMap> values)
HxmMap CreateMap(IList<HxmModule> values)
HxmMap CreateMap(IList<HxmValue> values)

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

Returns:

Map created.

See:

HxmMap

HxmValue CreateNil()

Creates a nil value.

Returns:

Nil value created.

See:

HxmValue

HxmValue CreateInt(long value)

Creates an integer value. The value can be assigned to any variable in a module with HxmModule.SetValue() or can be part of a map as key or value.

Returns:

Integer value created.

See:

HxmValue

HxmValue CreateDouble(double value)

Creates a double value. The value can be assigned to any variable in a module with HxmModule.SetValue() or can be part of a map as key or value.

Returns:

Double value created.

See:

HxmValue

HxmValue CreateBool(bool value)

Creates a boolean value. The value can be assigned to any variable in a module with HxmModule.SetValue() or can be part of a map as key or value.

Returns:

Boolean value created.

See:

HxmValue

HxmValue CreateString(string value)

Creates a string value. The value can be assigned to any variable in a module with HxmModule.SetValue() or can be part of a map as key or value.

Returns:

String value created.

See:

HxmValue

System.IO.TextWriter GetStdOut()

Returns the writer used by the modeler for its standard output methods like Write or WriteLine. The default writer used by the modeler corresponds to the C# standard output, retrieved with Console.Out.

Returns:

The writer used by the modeler for its standard output or null if the standard output is disabled.

void SetStdOut(System.IO.TextWriter writer)

Sets the writer used by the modeler for its standard output methods like Write or WriteLine. The default is to redirect all the modeler’s outputs to the C# standard output. If the given writer is null, the standard output of the modeler will be disabled and all calls to the Write/WriteLine related functions will do nothing.

Arguments:

writer – writer to use for the standard output or null to disable standard output.

System.IO.TextWriter GetStdErr()

Returns the writer used by the modeler for its standard error output. The default writer used by the modeler corresponds to the C# standard error output, retrieved with Console.Error.

Returns:

The writer used by the modeler for its standard error output or null if the standard error output is disabled.

void SetStdErr(System.IO.TextWriter writer)

Sets the writer used by the modeler for its standard error output. The default is to redirect the standard error output stream to the C# standard error output writer. If the given writer is null, the standard error output of the modeler will be disabled.

Arguments:

writer – writer to use for the standard error output or null to disable standard error output.