Hexaly Optimizer Class

class HexalyOptimizer

Hexaly Optimizer environment. Main type of Hexaly Optimizer library.

Summary

Methods

createPhase

Creates and adds a new phase to this Hexaly Optimizer environment.

solve

Solves the model.

stop

Aborts the resolution previously launched using solve().

computeInconsistency

Compute an inconsistency core for this model.

loadEnvironment

Import a complete environment from a file.

saveEnvironment

Export a complete environment or a model to a file.

addCallback

Add a new callback for a specific event type.

removeCallback

Remove the callback for the given event type and previously added with addCallback().

Overloaded operators

enter

These operators are automatically called when a solver instance is used in a with statement.

Fields

HexalyOptimizer.state

State of this Hexaly Optimizer environment. The returned value can be one of the following strings:

  • MODELING: Model is being built. This status is returned when the optimization model is not yet closed (or if it has been reopened).

  • RUNNING: The solve() method has been called. This value can only appear in the modeler when the solver calls an external function.

  • PAUSED: The solver and all its optimization algorithms are paused. This is the status of the solver when a callback is invoked.

  • STOPPED: State of the solver when the model is closed but not yet run or when the optimization is finished.

HexalyOptimizer.model

Model associated to this Hexaly Optimizer environment. Once the model is created and closed, the solver can be launched with solve().

Return type:

HxModel

HexalyOptimizer.solution

Best solution found by the solver. If the solver has not been started at least once, all the decision variables of the solution are set to 0, or to their closest bound if 0 is not part of their domain (such a solution may be infeasible).

Only allowed in states PAUSED or STOPPED.

Return type:

HxSolution

HexalyOptimizer.statistics

Statistics of this Hexaly Optimizer environment. Statistics are reset to zero before each resolution. Only allowed in states PAUSED or STOPPED.

Return type:

HxStatistics

HexalyOptimizer.param

Parameters of this Hexaly Optimizer environment.

Return type:

HxParam

HexalyOptimizer.nbPhases

Number of phases. Only allowed in states PAUSED or STOPPED.

HexalyOptimizer.phases

Phases. This field returns a readonly map-like structure containing HxPhase with the following features:

  • A count field to get the number of phases, e.g. phases.count().

  • An overloaded index [] operator to get a phase, e.g. phases[0]. The index must be between 0 and phases.count() - 1. Accessing a value outside these bounds throws an exception.

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

Return type:

map-like structure containing objects of type HxPhase.

Methods

HexalyOptimizer.createPhase()

Creates and adds a new phase to this Hexaly Optimizer environment. Only allowed in state STOPPED.

Returns:

New phase.

Return type:

HxPhase

HexalyOptimizer.solve()

Solves the model. This method returns only when the time limit, the iteration limit, the objective bounds are reached or when the method stop() is called. The model must be closed to launch the resolution.

HexalyOptimizer.stop()

Aborts the resolution previously launched using solve(). If no resolution was launched, this method does nothing. Solution and statistics remain valid. This method can be called in any state, notably in state RUNNING. Note that the effect of this method is not immediate. In particular when called within a callback, the resolution will not be stopped before the end of the callback.

See:

stop()

See:

addCallback()

HexalyOptimizer.computeInconsistency()

Compute an inconsistency core for this model. Only allowed in state STOPPED.

Returns:

The inconsistency core

Return type:

HxInconsistency

HexalyOptimizer.loadEnvironment(filename)

Import a complete environment from a file. Only allowed in state MODELING. The current model must be empty.

The only format supported is HXB.

The chosen file format is determined by the file suffix. An exception is thrown if the provided file suffix is not supported. The suffix may optionally be followed by .gz. In that case, this function uncompress the stream before reading.

Parameters:

filename – Name of the file.

See:

saveEnvironment()

HexalyOptimizer.saveEnvironment(filename)

Export a complete environment or a model to a file.

Currently, this function supports 2 file formats:

  • HXB : with this format, the complete environment (model, parameters, solution, …) is exported. This format is useful to debug or replay a model in the same conditions. Since the produced file is binary, it offers good performance and space efficiency.

  • HXM : with this format, only the model is exported in the Hexaly Modeling Language. This format is useful to have a quick view of the optimization model or to perform some modifications. However, the file may be heavy for big models and the exact reproductibility is not guaranteed since the parameters from one execution to another may differ.

The chosen file format is determined by the file suffix. An exception is thrown if the provided file suffix is not supported. The suffix may optionally be followed by .gz. In that case, this function produces a compressed result (using deflate algorithm).

Parameters:

filename – Name of the file.

See:

loadEnvironment()

HexalyOptimizer.addCallback(type, callback)

Add a new callback for a specific event type. The callback will be called each time the given event occurs. When a callback is called, the solver is paused. You can stop the resolution from a callback, retrieve the current solution, retrieve the statistics of the solver and, in general, call all the methods marked as “allowed in state PAUSED”.

The same callback can be used for different events.

The callback must be a function accepting 0, 1 or 2 parameters that are respectively the Hexaly Optimizer environment and the type of the event. The type of the event must be a string among:

  • PHASE_STARTED: Event that occurs when a phase is started.

  • PHASE_ENDED: Event that occurs when a phase ends.

  • DISPLAY: Event that occurs regularly before, after and during the search to display useful information about the model and the resolution. The time between two such events can be tuned with the timeBetweenDisplays parameter.

  • TIME_TICKED: Event that occurs regularly during the resolution. The time between two such events can be tuned with the timeBetweenTicks parameter.

  • ITERATION_TICKED: Event that occurs regularly during the resolution. The number of iterations between two such events can be tuned with the iterationBetweenTicks parameter.

HexalyOptimizer.removeCallback(type, callback)

Remove the callback for the given event type and previously added with addCallback().

Parameters:
  • type – Type of the callback to remove. Must be a string among “PHASE_STARTED”, “PHASE_ENDED”, “DISPLAY”, “TIME_TICKED” or “ITERATION_TICKED”.

  • callback – Callback to remove. Must be exactly the same instance as the one provided for addCallback().

Returns:

True if the callback was removed, false otherwise.

Return type:

bool

Operators

HexalyOptimizer.enter()
HexalyOptimizer.exit()

These operators are automatically called when a solver instance is used in a with statement.

enter is called at the beginning of the with statement. It sets the solver as the current solver, the one that will be used when calling the mathematical operators and the keywords minimize, maximize and constraint.

exit restores the previous solver as the current solver (or none).