HxmModule Class¶
-
class 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, std::string,
HxmMap
,HxmFunction
…) or manipulated throughHxmValue
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.- Since:
10.0
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 HxExpression with the given name. |
|
Returns the string with the given name. |
|
Returns the HxmMap with the given name. |
|
Returns the HxmFunction with the given name. |
|
Returns the HxmModule with the given name. |
|
Sets the value associated with the variable with the given name. |
|
Unsets the variable with the given name. |
|
Sets the integer value associated with the variable with the given name. |
|
Sets the double value associated with the variable with the given name. |
|
Sets the boolean value associated with the variable with the given name. |
|
Sets the HxExpression associated with the variable with the given name. |
|
Sets the string associated with the variable with the given name. |
|
Sets the map associated with the variable with the given name. |
|
Sets the function associated with the variable with the given name. |
|
Sets the module associated with 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 an HxExpression. |
|
Returns true if the variable with the given name exists and holds a string value. |
|
Returns true if the variable with the given name exists and holds an HxmMap. |
|
Returns true if the variable with the given name exists and holds an HxmFunction. |
|
Returns true if the variable with the given name exists and holds an HxmModule. |
|
Returns the module as an HxmValue. |
Returns the module as an HxmValue. |
Functions¶
-
void HxmModule::run(HexalyOptimizer &optimizer)¶
-
void HxmModule::run(HexalyOptimizer &optimizer, const std::vector<std::string> &arguments)¶
-
void HxmModule::run(HexalyOptimizer &optimizer, int argc, const char *const *argv)¶
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
HexalyOptimizer::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.- Parameters:
optimizer – Instance on which modeling and optimization is performed.
arguments – List of arguments to parse and expose as global variables.
argc – Number of arguments.
argv – Pointer to the first argument in the list.
-
void HxmModule::runMain(const std::vector<std::string> &arguments)¶
-
void HxmModule::runMain(int argc, const char *const *argv)¶
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 parameters
arguments
,argc
,argv
are simply ignored.For more details on the differences between the optimization and the main mode, read Main mode.
- Parameters:
arguments – List of arguments to copy into a map and pass to the main function.
argc – Number of arguments.
argv – Pointer to the first argument in the list.
- See:
- See:
-
HxmType HxmModule::getType(const std::string &varName) const¶
Returns the type of the variable with the given name. If the variable does not exist in the module,
Hxm_Nil
is returned.- Parameters:
varName – Name of the variable.
- Returns:
Type of the variable.
- See:
-
HxmValue HxmModule::getValue(const std::string &varName) const¶
Returns the
HxmValue
with the given name. If the variable does not exist in the module, an HxmValue representing a nil value is returned.- Parameters:
varName – Name of the variable.
- Returns:
HxmValue associated with the given name.
- See:
-
hxint HxmModule::getInt(const std::string &varName) const¶
Returns the integer variable with the given name. The variable must exist and must hold an integer value.
- Parameters:
varName – Name of the variable.
- Returns:
Integer value associated with the given name.
-
hxdouble HxmModule::getDouble(const std::string &varName) const¶
Returns the double variable with the given name. The variable must exist and must hold a double value.
- Parameters:
varName – Name of the variable.
- Returns:
Double value associated with the given name.
-
bool HxmModule::getBool(const std::string &varName) const¶
Returns the boolean variable with the given name. The variable must exist and must hold a boolean value.
- Parameters:
varName – Name of the variable.
- Returns:
Boolean value associated with the given name.
-
HxExpression HxmModule::getExpression(const std::string &varName) const¶
Returns the
HxExpression
with the given name. The variable must exist and must hold a value of typeHxm_Expression
.- Parameters:
varName – Name of the variable.
- Returns:
HxExpression associated with the given name.
-
std::string HxmModule::getString(const std::string &varName) const¶
Returns the string with the given name. The variable must exist and must hold a string value.
- Parameters:
varName – Name of the variable.
- Returns:
String associated with the given name.
-
HxmMap HxmModule::getMap(const std::string &varName) const¶
Returns the
HxmMap
with the given name. The variable must exist and must hold a map.- Parameters:
varName – Name of the variable.
- Returns:
HxmMap associated with the given name.
-
HxmFunction HxmModule::getFunction(const std::string &varName) const¶
Returns the
HxmFunction
with the given name. The variable must exist and must hold a function.- Parameters:
varName – Name of the variable.
- Returns:
HxmFunction associated with the given name.
-
HxmModule HxmModule::getModule(const std::string &varName) const¶
Returns the
HxmModule
with the given name. The variable must exist and must hold a module.- Parameters:
varName – Name of the variable.
- Returns:
HxmModule associated with the given name.
-
void HxmModule::setValue(const std::string &varName, const HxmValue &value)¶
Sets the value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
value – Value of the variable.
-
void HxmModule::setNil(const std::string &varName)¶
Unsets the variable with the given name. Do nothing it the variable does not exist.
- Parameters:
varName – Name of the variable.
-
void HxmModule::setInt(const std::string &varName, hxint value)¶
Sets the integer value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
value – Value of the variable.
-
void HxmModule::setDouble(const std::string &varName, hxdouble value)¶
Sets the double value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
value – Value of the variable.
-
void HxmModule::setBool(const std::string &varName, bool value)¶
Sets the boolean value associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
value – Value of the variable.
-
void HxmModule::setExpression(const std::string &varName, const HxExpression &expr)¶
Sets the HxExpression associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
expr – Value of the variable.
-
void HxmModule::setString(const std::string &varName, const std::string &value)¶
Sets the string associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
value – Value of the variable.
-
void HxmModule::setMap(const std::string &varName, const HxmMap &map)¶
Sets the map associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
map – Value of the variable.
-
void HxmModule::setFunction(const std::string &varName, const HxmFunction &function)¶
Sets the function associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
function – Value of the variable.
-
void HxmModule::setModule(const std::string &varName, const HxmModule &module)¶
Sets the module associated with the variable with the given name. The variable is automatically created if it doesn’t exist in the module.
- Parameters:
varName – Name of the variable.
module – Value of the variable.
-
void HxmModule::unset(const std::string &varName)¶
Unsets the variable with the given name. Do nothing it the variable does not exist.
- Parameters:
varName – Name of the variable.
-
bool HxmModule::isNil(const std::string &varName) const¶
Returns true if no variable with this name exists in the module or if the variable holds a nil value.
- Parameters:
varName – Name of the variable.
-
bool HxmModule::isInt(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds an integer value.
- Parameters:
varName – Name of the variable.
-
bool HxmModule::isDouble(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds a double value.
- Parameters:
varName – Name of the variable.
-
bool HxmModule::isBool(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds a boolean value.
- Parameters:
varName – Name of the variable.
-
bool HxmModule::isExpression(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds an
HxExpression
.- Parameters:
varName – Name of the variable.
-
bool HxmModule::isString(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds a string value.
- Parameters:
varName – Name of the variable.
-
bool HxmModule::isMap(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds an
HxmMap
.- Parameters:
varName – Name of the variable.
-
bool HxmModule::isFunction(const std::string &varName) const¶
Returns true if the variable with the given name exists and holds an
HxmFunction
.- Parameters:
varName – Name of the variable.