HxModel Class¶
- class HxModel¶
Mathematical optimization model. A model is composed of expressions (some of which are decisions), organized as a tree. Then, some expressions of the model can be constrained or optimized. Once your optimization model is created and closed, the solver can be launched to resolve it. Note that you cannot modify a model which has been closed: you must reopen it (with
open()
) or instantiate another Hexaly Optimizer environment to optimize another model.- See:
Summary¶
Returns true if the model is closed, false otherwise. |
|
Closes the model. |
|
Reopens the model. |
|
Removes the given expression from the list of constraints. |
|
Removes the objective at the given position in the list of objectives. |
Fields¶
- HxModel.expressions¶
This field returns a readonly map-like structure containing all expressions added to this model. The returned structure has the following features:
A count field to get the number of expressions, e.g.
expressions.count()
.An overloaded index
[]
operator to get a specific expression, e.g.expressions[0]
. The index must be between0
andexpressions.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the expressions with afor
statement.
- Return type:
map-like structure containing objects of type
HxExpression
.
- HxModel.decisions¶
This field returns a readonly map-like structure containing all decisions added to this model. The returned structure has the following features:
A count field to get the number of decisions, e.g.
decisions.count()
.An overloaded index
[]
operator to get a specific decision, e.g.decisions[0]
. The index must be between0
anddecisions.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the decisions with afor
statement.
- Return type:
map-like structure containing objects of type
HxExpression
.
- HxModel.constraints¶
This field returns a readonly map-like structure containing all constraints added to this model. The returned structure has the following features:
A count field to get the number of constraints, e.g.
constraints.count()
.An overloaded index
[]
operator to get a specific constraint, e.g.constraints[0]
. The index must be between0
andconstraints.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the constraints with afor
statement.
- Return type:
map-like structure containing objects of type
HxExpression
.
- HxModel.objectives¶
This field returns a readonly map-like structure containing all objectives added to this model. The returned structure has the following features:
A count field to get the number of objectives, e.g.
objectives.count()
.An overloaded index
[]
operator to get a specific objective, e.g.objectives[0]
. The index must be between0
andobjectives.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the objectives with afor
statement.
- Return type:
map-like structure containing objects of type
HxExpression
.
- HxModel.objectiveDirections¶
This field returns a readonly map-like structure containing the directions of the objectives expressed as strings (
MINIMIZE
orMAXIMIZE
). The returned structure has the following features:A count field to get the number of objectives, e.g.
objectiveDirections.count()
.An overloaded index
[]
operator to get a specific objective direction, e.g.objectiveDirections[0]
. The index must be between0
andobjectiveDirections.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the objective directions with afor
statement.
- Return type:
map-like structure containing strings
MINIMIZE
orMAXIMIZE
.
- HxModel.nbExpressions¶
Number of expressions added to this model so far.
- HxModel.nbDecisions¶
Number of decisions added to this model so far.
- HxModel.nbConstraints¶
Number of constraints added to this model so far.
- HxModel.nbObjectives¶
Number of objectives added to this model so far.
- HxModel.nbOperands¶
Number of operands added to this model so far. This corresponds to the number of operands for all expressions declared in the model. It is an analog of the number of non zeros in matrix model encountered in mathematical programming: it gives an hint about the size and the density of your model.
Methods¶
- HxModel.isClosed()¶
Returns true if the model is closed, false otherwise.
- Return type:
bool
- HxModel.close()¶
Closes the model. Only allowed in state
MODELING
. When this method is called, the solver is placed in stateSTOPPED
.Once the model is closed, no expressions, constraints or objectives can be added or removed unless the model is reopened. The model must be closed before starting its resolution.
- See:
- HxModel.open()¶
Reopens the model. Only allowed in state
STOPPED
. When this method is called, the solver is placed in stateMODELING
.In this state, the model can be modified: it is possible to add new expressions, constraints or objectives, modify expression operands, and remove existing constraints and objectives. However, existing expressions cannot be deleted.
- See:
- HxModel.removeConstraint(expr)¶
- HxModel.removeConstraint(constraintIndex)
Removes the given expression from the list of constraints. If the expression was not constrained, this method does nothing and returns immediately. Only allowed in state
MODELING
.- Since:
13.0
- Parameters:
expr (HxExpression) – Expression.
constraintIndex – Index of the constraint to remove.
- HxModel.removeObjective(objectiveIndex)¶
Removes the objective at the given position in the list of objectives. Note that the objectives created after the removed one have their index decreased by 1. Phases are not modified when an objective is removed. It is the user’s responsibility to change the objective index of each phase to keep it coherent (with
HxPhase.optimizedObjective
), or to disable it (withHxPhase.enabled
). Only allowed in stateMODELING
.- Since:
13.0
- Parameters:
objectiveIndex – position of the objective to remove, must be an integer.