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

Since:

10.0

Summary

Functions

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.

getExpression

Returns the HxExpression with the given name.

getString

Returns the string with the given name.

getMap

Returns the HxmMap with the given name.

getFunction

Returns the HxmFunction with the given name.

getModule

Returns the HxmModule with the given name.

setValue

Sets the value associated with the variable with the given name.

setNil

Unsets the variable with the given name.

setInt

Sets the integer value associated with the variable with the given name.

setDouble

Sets the double value associated with the variable with the given name.

setBool

Sets the boolean value associated with the variable with the given name.

setExpression

Sets the HxExpression associated with the variable with the given name.

setString

Sets the string associated with the variable with the given name.

setMap

Sets the map associated with the variable with the given name.

setFunction

Sets the function associated with the variable with the given name.

setModule

Sets the module associated with 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.

isExpression

Returns true if the variable with the given name exists and holds an HxExpression.

isString

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

isMap

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

isFunction

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

isModule

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

asValue

Returns the module as an HxmValue.

Overloaded operators

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

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:

Main mode

See:

Hexaly module

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:

HxmType

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:

HxmValue

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 type Hxm_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.

bool HxmModule::isModule(const std::string &varName) const

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

Parameters:

varName – Name of the variable.

HxmValue HxmModule::asValue() const

Returns the module as an HxmValue.

Overloaded operators

explicit operator HxmModule::HxmValue() const

Returns the module as an HxmValue.

See:

HxmValue