HxmModule Class¶
- class hexaly.modeler.HxmModule¶
A module is a collection of global variables. As the Hexaly modeling language is dynamically typed, global variables 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.
Summary¶
Starts the execution of the module using the optimizer passed in parameter. |
|
Runs the module in main mode. |
Returns the value of the variable with the given name. |
|
Sets the value of the variable with the given name. |
|
Resets the value of the variable with the given name to nil if the variable exists in the module. |
|
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¶
- HxmModule.run(optimizer, *args)¶
Starts the execution of the module using the optimizer passed in parameter. Such execution is defined by the following steps:
The
inputfunction is executed if it exists in the module.The
modelfunction is executed. It must be declared in the module.The
HxModelis then closed.The
paramfunction is executed if it exists in the module.The function
solve()is called on the corresponding optimizer instance. If thedisplayfunction is defined, it will be called during the resolution process.The
outputfunction is executed if it exists in the module.
Note that the optimizer used as a parameter must have been created by the
HexalyModeler.create_optimizer()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 withargNameas the name of the variable andargValueas 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.- Parameters:
optimizer (HexalyOptimizer) – Instance on which modeling and optimization is performed.
args (
stror list ofstr) – List of arguments to parse and expose as global variables.
- HxmModule.run_main(*args)¶
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
mainmethod which will be the only one invoked by the modeler.Unlike the optimization mode, the
mainmode 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
argsis simply ignored.For more details on the differences between the optimization and the main mode, read Main mode.
- Parameters:
args (
stror list ofstr) – List of arguments to copy into a map and pass to the main function.- See:
- See:
Special operators and methods¶
- HxmModule.__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:
NoneType(nil in Hexaly Modeler)boolintfloatstr
This method is automatically called by python when using special constructs like
value = myModule[var_name].- Parameters:
var_name (
str) – Name of the variable.
- HxmModule.__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:
NoneType(nil in Hexaly Modeler)boolintfloatstr
Setting a variable to
Nonehas 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.
- HxmModule.__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 myModulereturns false andmyModule[var_name]returnsNone.
- HxmModule.__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.