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:

HxExpression

Summary

Methods

isClosed

Returns true if the model is closed, false otherwise.

close

Closes the model.

open

Reopens the model.

removeConstraint

Removes the given expression from the list of constraints.

removeObjective

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 between 0 and expressions.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the expressions with a for 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 between 0 and decisions.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the decisions with a for 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 between 0 and constraints.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the constraints with a for 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 between 0 and objectives.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the objectives with a for 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 or MAXIMIZE). 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 between 0 and objectiveDirections.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the objective directions with a for statement.

Return type:

map-like structure containing strings MINIMIZE or MAXIMIZE.

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

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:

open()

HxModel.open()

Reopens the model. Only allowed in state STOPPED. When this method is called, the solver is placed in state MODELING.

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:

close()

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 (with HxPhase.enabled). Only allowed in state MODELING.

Since:

13.0

Parameters:

objectiveIndex – position of the objective to remove, must be an integer.