HxmModule Class

class Hexaly.Modeler.HxmModule

A module is a collection of global variables. As the Hexaly modeling language is dynamically typed, global variable can contain any value (including functions and other modules). Each HXM 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, HxmMap, HxmFunction…) or manipulated with an HxmValue 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. HxmValue should only be used when you don’t know the type of the manipulated value.

Summary

Methods

Run

Starts the execution of the module using the optimizer passed in parameter.

RunMain

Runs the module in main mode.

GetType

Returns the type of the variable with the given name.

GetValue

Returns the HxmValue 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 HxExpression variable with the given name.

GetFunction

Returns the HxmFunction variable with the given name.

GetModule

Returns the HxmModule variable with the given name.

GetMap

Returns the HxmMap 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 HxExpression associated with the given name The variable is automatically created if it doesn’t exist in the module.

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

IsFunction

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

IsModule

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

IsMap

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

Dispose

Releases the reference.

Instance methods

void Run(Hexaly.Optimizer.HexalyOptimizer optimizer)
void Run(Hexaly.Optimizer.HexalyOptimizer optimizer, params string[] arguments)
void Run(Hexaly.Optimizer.HexalyOptimizer optimizer, IEnumerable<string> arguments)

Starts the execution of the module using the optimizer passed in parameter. 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 HxModel is then closed.

  • The param function is executed if it exists in the module.

  • The function Solve is called on the corresponding optimizer 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.

Note that the optimizer used as a parameter must have been created by the HexalyModeler.CreateOptimizer method.

If arguments are given, each of them must be of the form argName=argValue. Each argument is then parsed and exposed as a new global variable in the module with argName as the name of the variable and argValue as its value. The format followed by the arguments is exactly the same as in the Hexaly Optimizer command line. For more information about the format of the Hexaly Optimizer command line you can read Command line.

Arguments:
  • optimizer (Hexaly.Optimizer.HexalyOptimizer) – Instance on which modeling and optimization is performed.

  • arguments – List of arguments to parse and expose as global variables.

void RunMain(params string[] arguments)
void RunMain(IEnumerable<string> arguments)

Runs the module in main mode. In this mode, the modeler behaves like a classical programming language. Therefore, the call sequence is free: you only need to implement a main method which will be the only one invoked by the modeler.

Unlike the optimization mode, the main mode requires you to manually create the optimizer instances, close your models and launch the resolutions directly in your HXM files. For this you can rely on the builtin module hexaly. In return, you are free to run several successive resolutions or none at all if you just want to use Hexaly Modeler for its pure programming features.

The arguments specified when calling this method are copied as is (as strings, without parsing) into a map that is passed as the first argument to the main function of your HXM file. If the main function of your file does not accept any arguments, the parameter arguments is simply ignored.

For more details on the differences between the optimization and the main mode, read Main mode.

Arguments:

arguments – List of arguments to copy into a map and pass to the main function.

See:

Main mode

See:

Hexaly module

HxmType GetType(string varName)

Returns the type of the variable with the given name. If the variable does not exist in the module, HxmType.Nil is returned.

Arguments:

varName (string) – Name of the variable.

Returns:

Type of the variable.

Return type:

HxmType

HxmValue GetValue(string varName)

Returns the HxmValue with the given name. If the variable does not exist in the module, an HxmValue representing nil is returned.

Arguments:

varName (string) – Name of the variable.

Returns:

HxmValue associated with the given name.

Return type:

HxmValue

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

Hexaly.Optimizer.HxExpression GetExpression(string varName)

Returns the HxExpression 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:

Hexaly.Optimizer.HxExpression

HxmFunction GetFunction(string varName)

Returns the HxmFunction 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:

HxmFunction

HxmModule GetModule(string varName)

Returns the HxmModule 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:

HxmModule

HxmMap GetMap(string varName)

Returns the HxmMap 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:

HxmMap

void SetValue(string varName, HxmValue 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 (HxmValue) – 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, Hexaly.Optimizer.HxExpression expr)

Sets the HxExpression associated with the given name The variable is automatically created if it doesn’t exist in the module.

Arguments:
void SetFunction(string varName, HxmFunction 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 (HxmFunction) – Value of the variable.

void SetModule(string varName, HxmModule 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 (HxmModule) – Value of the variable.

void SetMap(string varName, HxmMap 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 (HxmMap) – 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 HxExpression.

Arguments:

varName (string) – Name of the variable.

bool IsFunction(string varName)

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

Arguments:

varName (string) – Name of the variable.

bool IsModule(string varName)

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

Arguments:

varName (string) – Name of the variable.

bool IsMap(string varName)

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

Arguments:

varName (string) – Name of the variable.

void Dispose()

Releases the reference. If this module was already released, returns immediately and does nothing. Invoking any method on this object after this operation will throw an exception.

Note: Releasing a reference does not necessarily imply that the underlying module object is destroyed. It is only destroyed if no more references point to it.

Since:

11.5