HiGHS

class HiGHS(*args)

Linear and quadratic optimization solver.

Warning

This class is experimental and likely to be modified in future releases. To use it, import the openturns.experimental submodule.

This class exposes the linear and quadratic solvers from the HiGHS library. It solves continuous linear problems, mixed-integer linear problems and continuous convex quadratic problems. HiGHS support is optional at build time: in a build without it, run() raises an exception.

The recognized solver names are listed by GetAlgorithmNames():

Solver

Description

Supported variables

choose

Default automatic choice: dual revised simplex for LP, interior point or active set for QP, branch-and-bound MIP for discrete problems.

Continuous and discrete

simplex

Primal/dual simplex, always returns a basic solution.

Continuous LP only

qpasm

Active-set quadratic programming solver (HiGHS 1.14 or later).

Continuous QP only

ipm

Interior point (HiPO or IPX depending on the HiGHS build).

Continuous only

ipx

Serial interior point solver.

Continuous only

hipo

Parallel interior point solver, best on large problems.

Continuous only

pdlp

First-order primal-dual hybrid gradient method (cuPDLP-C), no basic solution.

Continuous only

hipdlp

HiGHS native first-order primal-dual method, no basic solution.

Continuous only

See the HiGHS documentation for solver details. Whether a name is accepted at runtime depends on the HiGHS build (e.g. hipo requires a HiGHS build with HiPO support); an unsupported name raises an error.

All solvers accept finite and infinite bounds on variables and linear constraints; mark infinite bounds with finite flags set to False in the Interval (see LinearProgrammingProblem and QuadraticProgrammingProblem).

Quadratic problems are solved by qpasm or hipo. The choose default selects the quadratic solver available in the linked HiGHS build. The active-set qpasm name requires HiGHS 1.14 or later. Earlier versions (HiGHS 1.13) already use an active-set solver for quadratic problems but do not accept the explicit qpasm name: use choose with these versions. Mixed-integer quadratic problems are not supported, and the linear-only solver names are rejected on a quadratic problem. The constant term of a quadratic objective is taken into account in the reported optimal value.

By default the interior point solvers run a crossover procedure to return a basic solution; this can be tuned with the run_crossover option below. The first-order solvers never return a basic solution. Use getSimplexIterationNumber(), getIPMIterationNumber(), getCrossoverIterationNumber(), getPDLPIterationNumber() and getQPIterationNumber() to compare per-solver work; their sum is the result iteration number.

After run(), the HiGHS model status (Optimal on success) is available as the status message of the OptimizationResult, whose status is set to SUCCESS, FAILURE, TIMEOUT, INTERRUPTION or MAXIMUMCALLS accordingly. Call setCheckStatus(False) before run() to inspect a non-success status instead of raising an exception. On continuous problems with a valid dual solution, getDualPoint() returns the constraint duals (shadow prices) and getReducedCosts() the per-variable reduced costs; getConstraintValues() returns the linear constraint activity row values. There is no dual solution on problems with discrete variables.

The linear constraint matrix is handed over to HiGHS in compressed sparse column form. When the problem provides its sparse coefficients (see LinearProgrammingProblem), they are copied directly, so a large sparse problem is neither densified nor scanned element by element.

HiGHS solver can be adapted using the parameters described here. These parameters can be modified through the ResourceMap. For every option optionName, simply add a key named HiGHS-optionName with the value to use, as shown below:

>>> import openturns as ot
>>> ot.ResourceMap.AddAsBool('HiGHS-output_flag', True)
>>> ot.ResourceMap.AddAsUnsignedInteger('HiGHS-threads', 4)
Parameters:
problemOptimizationProblem

The problem, must be linear (see LinearProgrammingProblem) or quadratic (see QuadraticProgrammingProblem).

algoNamestr, default is choose

The solver, use GetAlgorithmNames() to list the recognized names. Problems with discrete variables are solved by the MIP solver, which ignores this choice: use choose on such problems.

Methods

GetAlgorithmNames()

Accessor to the list of recognized solver names.

getAlgorithmName()

Accessor to the solver name.

getCheckStatus()

Accessor to check status flag.

getClassName()

Accessor to the object's name.

getConstraintValues()

Accessor to the linear constraint activity of the last run.

getCrossoverIterationNumber()

Accessor to the crossover iteration count of the last run.

getDualPoint()

Accessor to the constraint duals of the last run.

getIPMIterationNumber()

Accessor to the interior point iteration count of the last run.

getMaximumAbsoluteError()

Accessor to maximum allowed absolute error.

getMaximumCallsNumber()

Accessor to maximum allowed number of calls.

getMaximumConstraintError()

Accessor to maximum allowed constraint error.

getMaximumIterationNumber()

Accessor to maximum allowed number of iterations.

getMaximumRelativeError()

Accessor to maximum allowed relative error.

getMaximumResidualError()

Accessor to maximum allowed residual error.

getMaximumTimeDuration()

Accessor to the maximum duration.

getName()

Accessor to the object's name.

getPDLPIterationNumber()

Accessor to the PDLP iteration count of the last run.

getProblem()

Accessor to optimization problem.

getQPIterationNumber()

Accessor to the QP iteration count of the last run.

getReducedCosts()

Accessor to the reduced costs of the last run.

getResult()

Accessor to optimization result.

getSimplexIterationNumber()

Accessor to the simplex iteration count of the last run.

getStartingPoint()

Accessor to starting point.

getStartingSample()

Accessor to starting sample.

hasName()

Test if the object is named.

run()

Launch the optimization.

setAlgorithmName(algoName)

Accessor to the solver name.

setCheckStatus(checkStatus)

Accessor to check status flag.

setMaximumAbsoluteError(maximumAbsoluteError)

Accessor to maximum allowed absolute error.

setMaximumCallsNumber(maximumCallsNumber)

Accessor to maximum allowed number of calls

setMaximumConstraintError(maximumConstraintError)

Accessor to maximum allowed constraint error.

setMaximumIterationNumber(maximumIterationNumber)

Accessor to maximum allowed number of iterations.

setMaximumRelativeError(maximumRelativeError)

Accessor to maximum allowed relative error.

setMaximumResidualError(maximumResidualError)

Accessor to maximum allowed residual error.

setMaximumTimeDuration(maximumTime)

Accessor to the maximum duration.

setName(name)

Accessor to the object's name.

setProblem(problem)

Accessor to optimization problem.

setProgressCallback(*args)

Set up a progress callback.

setResult(result)

Accessor to optimization result.

setStartingPoint(startingPoint)

Accessor to starting point.

setStartingSample(startingSample)

Accessor to starting sample.

setStopCallback(*args)

Set up a stop callback.

Examples

Solve a mixed integer linear optimization problem with objective:

f = 1.1 x_0 + x_1

with inequality constraints:

\begin{eqnarray*}
    & x_1 & \leq 7\\
    5 & \leq x_0 + 2x_1 & \leq 15\\
    6 & \leq 3x_0 + 2x_1 & \\
\end{eqnarray*}

and bound constraints:

\begin{eqnarray*}
    0 & \leq x_0 & \leq 4\\
    1 & \leq x_1 &
\end{eqnarray*}

>>> import openturns as ot
>>> import openturns.experimental as otexp
>>> cost = [1.1, 1.0]
>>> bounds = ot.Interval([0.0, 1.0], [4.0, 1e30], [True, True], [True, False])
>>> A = ot.Matrix([[0.0, 1.0], [1.0, 2.0], [3.0, 2.0]])
>>> cb = ot.Interval([-1e9, 5.0, 6.0], [7.0, 15.0, 1e9], [False, True, True], [True, True, False])
>>> problem = otexp.LinearProgrammingProblem(cost, bounds, A, cb)
>>> problem.setVariablesType([ot.OptimizationProblemImplementation.INTEGER] * 2)
>>> algo = otexp.HiGHS(problem)
>>> algo.run()
>>> result = algo.getResult()
>>> x_star = result.getOptimalPoint()
>>> y_star = result.getOptimalValue()
__init__(*args)
static GetAlgorithmNames()

Accessor to the list of recognized solver names.

Returns:
namesDescription

List of recognized solver names. Whether a name is accepted at runtime depends on the HiGHS build.

Examples

>>> import openturns.experimental as otexp
>>> print(otexp.HiGHS.GetAlgorithmNames())
[choose,simplex,qpasm,ipm,ipx,hipo,pdlp,hipdlp]
getAlgorithmName()

Accessor to the solver name.

Returns:
algoNamestr

The solver name.

getCheckStatus()

Accessor to check status flag.

Returns:
checkStatusbool

Whether to check the termination status. If set to False, run() will not throw an exception if the algorithm does not fully converge and will allow one to still find a feasible candidate.

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

The object class name (object.__class__.__name__).

getConstraintValues()

Accessor to the linear constraint activity of the last run.

Returns:
valuesPoint

The linear constraint row values.

Notes

Only available after a run with linear constraints and a valid primal solution.

getCrossoverIterationNumber()

Accessor to the crossover iteration count of the last run.

Returns:
countint

Number of crossover iterations reported by HiGHS.

Notes

Only available after a run. Crossover runs after the interior point solvers to return a basic solution, depending on the run_crossover option.

getDualPoint()

Accessor to the constraint duals of the last run.

Returns:
dualsPoint

The linear constraint duals (shadow prices).

Notes

Only available on continuous problems with a valid dual solution.

getIPMIterationNumber()

Accessor to the interior point iteration count of the last run.

Returns:
countint

Number of interior point iterations reported by HiGHS.

Notes

Only available after a run. A value of 0 means HiGHS reported 0 interior point iterations, not untraced work.

getMaximumAbsoluteError()

Accessor to maximum allowed absolute error.

Returns:
maximumAbsoluteErrorfloat

Maximum allowed absolute error, where the absolute error is defined by \epsilon^a_n=\|\vect{x}_{n+1}-\vect{x}_n\|_{\infty} where \vect{x}_{n+1} and \vect{x}_n are two consecutive approximations of the optimum.

getMaximumCallsNumber()

Accessor to maximum allowed number of calls.

Returns:
maximumCallsNumberint

Maximum allowed number of function evaluations, including direct calls through the () operator and indirect calls through finite difference gradients.

getMaximumConstraintError()

Accessor to maximum allowed constraint error.

Returns:
maximumConstraintErrorfloat

Maximum allowed constraint error, where the constraint error is defined by \gamma_n=\|g(\vect{x}_n)\|_{\infty} where \vect{x}_n is the current approximation of the optimum and g is the function that gathers all the equality and inequality constraints (violated values only)

getMaximumIterationNumber()

Accessor to maximum allowed number of iterations.

Returns:
maximumIterationNumberint

Maximum allowed number of iterations.

getMaximumRelativeError()

Accessor to maximum allowed relative error.

Returns:
maximumRelativeErrorfloat

Maximum allowed relative error, where the relative error is defined by \epsilon^r_n=\epsilon^a_n/\|\vect{x}_{n+1}\|_{\infty} if \|\vect{x}_{n+1}\|_{\infty}\neq 0, else \epsilon^r_n=-1.

getMaximumResidualError()

Accessor to maximum allowed residual error.

Returns:
maximumResidualErrorfloat

Maximum allowed residual error, where the residual error is defined by \epsilon^r_n=\frac{\|f(\vect{x}_{n+1})-f(\vect{x}_{n})\|}{\|f(\vect{x}_{n+1})\|} if \|f(\vect{x}_{n+1})\|\neq 0, else \epsilon^r_n=-1.

getMaximumTimeDuration()

Accessor to the maximum duration.

Returns:
maximumTimefloat

Maximum optimization duration in seconds.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getPDLPIterationNumber()

Accessor to the PDLP iteration count of the last run.

Returns:
countint

Number of PDLP iterations reported by HiGHS.

Notes

Only available after a run. Non-zero only for the first-order solvers.

getProblem()

Accessor to optimization problem.

Returns:
problemOptimizationProblem

Optimization problem.

getQPIterationNumber()

Accessor to the QP iteration count of the last run.

Returns:
countint

Number of QP iterations reported by HiGHS.

Notes

Only available after a run.

getReducedCosts()

Accessor to the reduced costs of the last run.

Returns:
costsPoint

The per-variable reduced costs.

Notes

Only available on continuous problems with a valid dual solution.

getResult()

Accessor to optimization result.

Returns:
resultOptimizationResult

Result class.

getSimplexIterationNumber()

Accessor to the simplex iteration count of the last run.

Returns:
countint

Number of simplex iterations reported by HiGHS.

Notes

Only available after a run. A value of 0 means HiGHS reported 0 simplex iterations (e.g. presolve or another solver did the work), not untraced work.

getStartingPoint()

Accessor to starting point.

Returns:
startingPointPoint

Starting point.

getStartingSample()

Accessor to starting sample.

Returns:
startingSampleSample

Starting sample.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

run()

Launch the optimization.

setAlgorithmName(algoName)

Accessor to the solver name.

Parameters:
algoNamestr

The solver name, see GetAlgorithmNames(). Problems with discrete variables require choose. Quadratic problems require choose, qpasm or hipo; qpasm requires HiGHS 1.14 or later.

setCheckStatus(checkStatus)

Accessor to check status flag.

Parameters:
checkStatusbool

Whether to check the termination status. If set to False, run() will not throw an exception if the algorithm does not fully converge and will allow one to still find a feasible candidate.

setMaximumAbsoluteError(maximumAbsoluteError)

Accessor to maximum allowed absolute error.

Parameters:
maximumAbsoluteErrorfloat

Maximum allowed absolute error, where the absolute error is defined by \epsilon^a_n=\|\vect{x}_{n+1}-\vect{x}_n\|_{\infty} where \vect{x}_{n+1} and \vect{x}_n are two consecutive approximations of the optimum.

setMaximumCallsNumber(maximumCallsNumber)

Accessor to maximum allowed number of calls

Parameters:
maximumCallsNumberint

Maximum allowed number of function evaluations, including direct calls through the () operator and indirect calls through finite difference gradients.

setMaximumConstraintError(maximumConstraintError)

Accessor to maximum allowed constraint error.

Parameters:
maximumConstraintErrorfloat

Maximum allowed constraint error, where the constraint error is defined by \gamma_n=\|g(\vect{x}_n)\|_{\infty} where \vect{x}_n is the current approximation of the optimum and g is the function that gathers all the equality and inequality constraints (violated values only)

setMaximumIterationNumber(maximumIterationNumber)

Accessor to maximum allowed number of iterations.

Parameters:
maximumIterationNumberint

Maximum allowed number of iterations.

setMaximumRelativeError(maximumRelativeError)

Accessor to maximum allowed relative error.

Parameters:
maximumRelativeErrorfloat

Maximum allowed relative error, where the relative error is defined by \epsilon^r_n=\epsilon^a_n/\|\vect{x}_{n+1}\|_{\infty} if \|\vect{x}_{n+1}\|_{\infty}\neq 0, else \epsilon^r_n=-1.

setMaximumResidualError(maximumResidualError)

Accessor to maximum allowed residual error.

Parameters:
maximumResidualErrorfloat

Maximum allowed residual error, where the residual error is defined by \epsilon^r_n=\frac{\|f(\vect{x}_{n+1})-f(\vect{x}_{n})\|}{\|f(\vect{x}_{n+1})\|} if \|f(\vect{x}_{n+1})\|\neq 0, else \epsilon^r_n=-1.

setMaximumTimeDuration(maximumTime)

Accessor to the maximum duration.

Parameters:
maximumTimefloat

Maximum optimization duration in seconds.

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

setProblem(problem)

Accessor to optimization problem.

Parameters:
problemOptimizationProblem

Optimization problem.

setProgressCallback(*args)

Set up a progress callback.

Can be used to programmatically report the progress of an optimization.

Parameters:
callbackcallable

Takes a float as argument as percentage of progress.

Examples

>>> import sys
>>> import openturns as ot
>>> rosenbrock = ot.SymbolicFunction(['x1', 'x2'], ['(1-x1)^2+100*(x2-x1^2)^2'])
>>> problem = ot.OptimizationProblem(rosenbrock)
>>> solver = ot.OptimizationAlgorithm(problem)
>>> solver.setStartingPoint([0, 0])
>>> solver.setMaximumResidualError(1.e-3)
>>> solver.setMaximumCallsNumber(10000)
>>> def report_progress(progress):
...     sys.stderr.write('-- progress=' + str(progress) + '%\n')
>>> solver.setProgressCallback(report_progress)
>>> solver.run()
setResult(result)

Accessor to optimization result.

Parameters:
resultOptimizationResult

Result class.

setStartingPoint(startingPoint)

Accessor to starting point.

Parameters:
startingPointPoint

Starting point.

setStartingSample(startingSample)

Accessor to starting sample.

Parameters:
startingSampleSample

Starting sample.

setStopCallback(*args)

Set up a stop callback.

Can be used to programmatically stop an optimization.

Parameters:
callbackcallable

Returns an int deciding whether to stop or continue.

Examples

>>> import openturns as ot
>>> rosenbrock = ot.SymbolicFunction(['x1', 'x2'], ['(1-x1)^2+100*(x2-x1^2)^2'])
>>> problem = ot.OptimizationProblem(rosenbrock)
>>> solver = ot.OptimizationAlgorithm(problem)
>>> solver.setStartingPoint([0, 0])
>>> solver.setMaximumResidualError(1.e-3)
>>> solver.setMaximumCallsNumber(10000)
>>> def ask_stop():
...     return True
>>> solver.setStopCallback(ask_stop)
>>> solver.run()

Examples using the class

Optimization using HiGHS solvers

Optimization using HiGHS solvers

Unit commitment

Unit commitment