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.experimentalsubmodule.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
chooseDefault automatic choice: dual revised simplex for LP, interior point or active set for QP, branch-and-bound MIP for discrete problems.
Continuous and discrete
simplexPrimal/dual simplex, always returns a basic solution.
Continuous LP only
qpasmActive-set quadratic programming solver (HiGHS 1.14 or later).
Continuous QP only
ipmInterior point (HiPO or IPX depending on the HiGHS build).
Continuous only
ipxSerial interior point solver.
Continuous only
hipoParallel interior point solver, best on large problems.
Continuous only
pdlpFirst-order primal-dual hybrid gradient method (cuPDLP-C), no basic solution.
Continuous only
hipdlpHiGHS 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.
hiporequires 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
Falsein theInterval(seeLinearProgrammingProblemandQuadraticProgrammingProblem).Quadratic problems are solved by
qpasmorhipo. Thechoosedefault selects the quadratic solver available in the linked HiGHS build. The active-setqpasmname 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 explicitqpasmname: usechoosewith 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_crossoveroption below. The first-order solvers never return a basic solution. UsegetSimplexIterationNumber(),getIPMIterationNumber(),getCrossoverIterationNumber(),getPDLPIterationNumber()andgetQPIterationNumber()to compare per-solver work; their sum is the result iteration number.After
run(), the HiGHS model status (Optimalon success) is available as the status message of theOptimizationResult, whose status is set toSUCCESS,FAILURE,TIMEOUT,INTERRUPTIONorMAXIMUMCALLSaccordingly. CallsetCheckStatus(False)beforerun()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) andgetReducedCosts()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 optionoptionName, simply add a key namedHiGHS-optionNamewith 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:
- problem
OptimizationProblem The problem, must be linear (see
LinearProgrammingProblem) or quadratic (seeQuadraticProgrammingProblem).- 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: usechooseon such problems.
- problem
Methods
Accessor to the list of recognized solver names.
Accessor to the solver name.
Accessor to check status flag.
Accessor to the object's name.
Accessor to the linear constraint activity of the last run.
Accessor to the crossover iteration count of the last run.
Accessor to the constraint duals of the last run.
Accessor to the interior point iteration count of the last run.
Accessor to maximum allowed absolute error.
Accessor to maximum allowed number of calls.
Accessor to maximum allowed constraint error.
Accessor to maximum allowed number of iterations.
Accessor to maximum allowed relative error.
Accessor to maximum allowed residual error.
Accessor to the maximum duration.
getName()Accessor to the object's name.
Accessor to the PDLP iteration count of the last run.
Accessor to optimization problem.
Accessor to the QP iteration count of the last run.
Accessor to the reduced costs of the last run.
Accessor to optimization result.
Accessor to the simplex iteration count of the last run.
Accessor to starting point.
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.
See also
Examples
Solve a mixed integer linear optimization problem with objective:
with inequality constraints:
and bound constraints:
>>> 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:
- names
Description List of recognized solver names. Whether a name is accepted at runtime depends on the HiGHS build.
- names
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:
- values
Point The linear constraint row values.
- 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_crossoveroption.
- getDualPoint()¶
Accessor to the constraint duals of the last run.
- Returns:
- duals
Point The linear constraint duals (shadow prices).
- duals
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
where
and
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
where
is the current approximation of the optimum and
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
if
, else
.
- getMaximumResidualError()¶
Accessor to maximum allowed residual error.
- Returns:
- maximumResidualErrorfloat
Maximum allowed residual error, where the residual error is defined by
if
, else
.
- 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:
- problem
OptimizationProblem Optimization problem.
- 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:
- costs
Point The per-variable reduced costs.
- costs
Notes
Only available on continuous problems with a valid dual solution.
- getResult()¶
Accessor to optimization result.
- Returns:
- result
OptimizationResult Result class.
- result
- 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.
- 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 requirechoose. Quadratic problems requirechoose,qpasmorhipo;qpasmrequires 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
where
and
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
where
is the current approximation of the optimum and
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
if
, else
.
- setMaximumResidualError(maximumResidualError)¶
Accessor to maximum allowed residual error.
- Parameters:
- maximumResidualErrorfloat
Maximum allowed residual error, where the residual error is defined by
if
, else
.
- 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:
- problem
OptimizationProblem Optimization problem.
- 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:
- result
OptimizationResult Result class.
- result
- setStartingPoint(startingPoint)¶
Accessor to starting point.
- Parameters:
- startingPoint
Point Starting point.
- startingPoint
- setStartingSample(startingSample)¶
Accessor to starting sample.
- Parameters:
- startingSample
Sample Starting sample.
- startingSample
- 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()
OpenTURNS