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 anHxmValue
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¶
Starts the execution of the module using the optimizer passed in parameter. |
|
Runs the module in main mode. |
|
Returns the type of the variable with the given name. |
|
Returns the HxmValue with the given name. |
|
Returns the integer variable with the given name. |
|
Returns the double variable with the given name. |
|
Returns the boolean variable with the given name. |
|
Returns the string variable with the given name. |
|
Returns the HxExpression variable with the given name. |
|
Returns the HxmFunction variable with the given name. |
|
Returns the HxmModule variable with the given name. |
|
Returns the HxmMap variable with the given name. |
|
Sets the value associated with the given name. |
|
Sets the integer value associated with the given name. |
|
Sets the double value associated with the given name. |
|
Sets the boolean value associated with the given name. |
|
Sets the string value associated with the given name. |
|
Sets the HxExpression associated with the given name The variable is automatically created if it doesn’t exist in the module. |
|
Sets the function associated with the given name. |
|
Sets the module associated with the given name. |
|
Sets the map associated with the given name. |
|
Unsets the variable with the given name. |
|
Unsets the variable with the given name. |
|
Returns true if no variable with this name exists in the module or if the variable holds a nil value. |
|
Returns true if the variable with the given name exists and holds an integer value. |
|
Returns true if the variable with the given name exists and holds a double value. |
|
Returns true if the variable with the given name exists and holds a boolean value. |
|
Returns true if the variable with the given name exists and holds a boolean value. |
|
Returns true if the variable with the given name exists and holds a HxExpression. |
|
Returns true if the variable with the given name exists and holds a HxmFunction. |
|
Returns true if the variable with the given name exists and holds a HxmModule. |
|
Returns true if the variable with the given name exists and holds a HxmMap. |
|
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 thedisplay
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 withargName
as the name of the variable andargValue
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:
- See:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
varName (
string
) – Name of the variable.expr (Hexaly.Optimizer.HxExpression) – Value of the variable.
- 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