Class HxmModule
- All Implemented Interfaces:
AutoCloseable
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.- Since:
- 10.0
-
Method Summary
Modifier and TypeMethodDescriptionasValue()Returns the module as anHxmValue.voidclose()Releases the reference.booleanbooleanReturns the boolean variable with the given name.Returns theHxmClasswith the given name.Gets the full qualified name of the module.doubleReturns the double variable with the given name.getExpression(String varName) Returns theHxExpressionwith the given name.getFunction(String varName) Returns theHxmFunctionwith the given name.longReturns the integer variable with the given name.Returns theHxmMapwith the given name.Returns theHxmModulewith the given name.Returns the string with the given name.Returns the type of the variable with the given name.Returns theHxmValuewith the given name.inthashCode()booleanReturns true if the variable with the given name exists and holds a boolean value.booleanReturns true if the variable with the given name exists and holds anHxmClass.booleanReturns true if the variable with the given name exists and holds a double value.booleanisExpression(String varName) Returns true if the variable with the given name exists and holds anHxExpression.booleanisFunction(String varName) Returns true if the variable with the given name exists and holds anHxmFunction.booleanReturns true if the variable with the given name exists and holds an integer value.booleanReturns true if the variable with the given name exists and holds anHxmMap.booleanReturns true if the variable with the given name exists and holds anHxmModule.booleanReturns true if no variable with this name exists in the module or if the variable holds a nil value.booleanReturns true if the variable with the given name exists and holds a string value.voidrun(HexalyOptimizer optimizer, Iterable<String> arguments) Starts the execution of the module using the optimizer passed in parameter.voidrun(HexalyOptimizer optimizer, String... arguments) Starts the execution of the module using the optimizer passed in parameter.voidRuns the module in main mode.voidRuns the module in main mode.voidSets the boolean value associated with the variable with the given name.voidSets theHxmClassassociated with the variable with the given name.voidSets the double value associated with the variable with the given name.voidsetExpression(String varName, HxExpression expr) Sets theHxExpressionassociated with the variable with the given name.voidsetFunction(String varName, HxmFunction function) Sets theHxmFunctionassociated with the variable with the given name.voidSets the integer value associated with the variable with the given name.voidSets theHxmMapassociated with the variable with the given name.voidSets theHxmModuleassociated with the variable with the given name.voidUnsets the variable with the given name.voidSets the string associated with the variable with the given name.voidSets the value associated with the variable with the given name.voidUnsets the variable with the given name.
-
Method Details
-
close
public void close()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.
- Specified by:
closein interfaceAutoCloseable- Since:
- 11.5
-
getDeclaredName
Gets the full qualified name of the module. -
run
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
HexalyOptimizer.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.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 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 the command line section in the Hexaly Modeler reference guide.- Parameters:
optimizer- Instance on which modeling and optimization is performed.arguments- List of arguments to parse and expose as global variables.
- The
-
run
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
HexalyOptimizer.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.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 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 the command line section in the Hexaly Modeler reference guide.- Parameters:
optimizer- Instance on which modeling and optimization is performed.arguments- List of arguments to parse and expose as global variables.
- The
-
runMain
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
argumentsis simply ignored.For more details on the differences between the optimization and the main mode, read the main mode section of the Hexaly Modeler reference guide.
- Parameters:
arguments- List of arguments to copy into a map and pass to the main function.
-
runMain
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
argumentsis simply ignored.For more details on the differences between the optimization and the main mode, read the main mode section of the Hexaly Modeler reference guide.
- Parameters:
arguments- List of arguments to copy into a map and pass to the main function.
-
getType
Returns the type of the variable with the given name. If the variable does not exist in the module,HxmType.Nilis returned.- Parameters:
varName- Name of the variable.- Returns:
- Type of the variable.
- See Also:
-
getValue
Returns theHxmValuewith the given name. If the variable does not exist, an HxmValue representing a nil value is returned.- Parameters:
varName- Name of the variable.- Returns:
- HxmValue associated with the given name.
- See Also:
-
getInt
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.
-
getDouble
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.
-
getBool
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.
-
getExpression
Returns theHxExpressionwith the given name. The variable must exist and must hold a value of typeHxmType.Expression.- Parameters:
varName- Name of the variable.- Returns:
- HxExpression associated with the given name.
-
getString
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.
-
getFunction
Returns theHxmFunctionwith 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.
-
getMap
Returns theHxmMapwith the given name. The variable must exist and must hold a map.- Parameters:
varName- Name of the variable.- Returns:
- HxmFunction associated with the given name.
-
getModule
Returns theHxmModulewith 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.
-
getClass
Returns theHxmClasswith the given name. The variable must exist and must hold a class.- Parameters:
varName- Name of the variable.- Returns:
- HxmClass associated with the given name.
-
setValue
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.
-
setInt
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.
-
setDouble
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.
-
setBool
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.
-
setExpression
Sets theHxExpressionassociated 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.
-
setString
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.str- Value of the variable.
-
setFunction
Sets theHxmFunctionassociated 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.
-
setMap
Sets theHxmMapassociated 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.
-
setModule
Sets theHxmModuleassociated 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.
-
setClass
Sets theHxmClassassociated 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.clazz- Value of the variable.
-
setNil
Unsets the variable with the given name. Do nothing it the variable does not exist.- Parameters:
varName- Name of the variable.
-
unset
Unsets the variable with the given name. Do nothing it the variable does not exist.- Parameters:
varName- Name of the variable.
-
isInt
Returns true if the variable with the given name exists and holds an integer value.- Parameters:
varName- Name of the variable.
-
isDouble
Returns true if the variable with the given name exists and holds a double value.- Parameters:
varName- Name of the variable.
-
isBool
Returns true if the variable with the given name exists and holds a boolean value.- Parameters:
varName- Name of the variable.
-
isExpression
Returns true if the variable with the given name exists and holds anHxExpression.- Parameters:
varName- Name of the variable.
-
isString
Returns true if the variable with the given name exists and holds a string value.- Parameters:
varName- Name of the variable.
-
isFunction
Returns true if the variable with the given name exists and holds anHxmFunction.- Parameters:
varName- Name of the variable.
-
isMap
Returns true if the variable with the given name exists and holds anHxmMap.- Parameters:
varName- Name of the variable.
-
isModule
Returns true if the variable with the given name exists and holds anHxmModule.- Parameters:
varName- Name of the variable.
-
isClass
Returns true if the variable with the given name exists and holds anHxmClass.- Parameters:
varName- Name of the variable.
-
isNil
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.
-
asValue
Returns the module as anHxmValue. -
hashCode
public int hashCode() -
equals
-