Knitro / AMPL reference

A complete list of available Knitro options can always be shown by typing:

knitroampl -=

in a terminal, which produces something similar to the following output (we have removed some deprecated options or options that may not be relevant for this interface from the list below).

act_lpalg                LP algorithm used in Active or SQP subproblems
act_lpdumpmps            Dump LPs to MPS files in Active or SQP algorithm
act_lpfeastol            Feasibility tolerance for LP subproblems
act_lppenalty            Controls constraint penalization in LP subproblems
act_lppresolve           Controls LP presolve in Active or SQP subproblems
act_lpsolver             LP solver used by Active or SQP algorithm
act_parametric           Use parametric LP in Active or SQP algorithm
act_qpalg                QP subproblem alg used by Active or SQP algorithm
act_qppenalty            Controls constraint penalization in QP subproblems
alg                      Algorithm (0=auto, 1=direct, 2=cg, 3=active, 4=sqp, 5=multi)
algorithm                Synonym for alg
bar_conic_enable         Special handling of conic constraints
bar_directinterval       Frequency for trying to force direct steps
bar_feasible             Emphasize feasibility
bar_feasmodetol          Tolerance for entering stay feasible mode
bar_globalize            Barrier globalization strategy
bar_initmu               Initial value for barrier parameter
bar_initpi_mpec          Initial value for barrier MPEC penalty parameter
bar_initpt               Barrier initial point strategy for slacks/multipliers
bar_linsys               Barrier linear system form
bar_linsys_storage       Barrier linear system storage
bar_maxcorrectors        Maximum number of corrector steps
bar_maxcrossit           Maximum number of crossover iterations
bar_maxmu                Maximum value for barrier parameter
bar_maxrefactor          Maximum number of KKT refactorizations allowed
bar_mpec_heuristic       Whether to enable barrier MPEC heuristic
bar_murule               Rule for updating the barrier parameter
bar_penaltycons          Apply penalty method to constraints
bar_penaltyrule          Rule for updating the penalty parameter
bar_refinement           Whether to refine barrier solution
bar_relaxcons            Whether to relax constraints
bar_slackboundpush       Amount by which slacks are pushed inside bounds
bar_switchobj            Objective for barrier switching alg
bar_switchrule           Rule for barrier switching alg
bar_watchdog             Enable watchdog heuristic for barrier algs?
bfgs_scaling             Initial scaling for BFGS/L-BFGS Hessian
blas_numthreads          Number of parallel threads for BLAS
blasoption               Which BLAS/LAPACK library to use
blasoptionlib            Name of dynamic BLAS/LAPACK library
bndrange                 Constraint/variable bound range
cg_maxit                 Maximum number of conjugate gradient iterations
cg_pmem                  Memory for incomplete Cholesky
cg_precond               Preconditioning method
cg_stoptol               Stopping tolerance for CG subproblems
conic_numthreads         Number of parallel threads for conic operations
convex                   Declare the problem as convex
cplexlibname             Name of dynamic CPLEX library
cpuplatform              Target CPU platform/architecture
debug                    Debugging level (0=none, 1=problem, 2=execution)
delta                    Initial trust region radius
eval_cost                Specifies the relative cost of performing function/derivative evaluations
feastol                  Feasibility stopping tolerance
feastol_abs              Absolute feasibility tolerance
findiff_estnoise         Noise estimate for finite-difference gradients
findiff_relstepsize      Relative stepsize for finite-difference gradients
findiff_terminate        Termination for finite-difference gradients
fstopval                 Stop based on obj. function value
ftol                     Stop based on small change in obj. function
ftol_iters               Stop based on small change in obj. function
gradopt                  Gradient computation method
hessopt                  Hessian computation method
honorbnds                Enforce satisfaction of the bounds
infeastol                Infeasibility stopping tolerance
infeastol_iters          Stop based on small change in feasibility error
initpenalty              Initial merit function penalty value
initpt_strategy          Specifies the initial point strategy used for the continuous algorithms
leastsquares             Solve as a least-squares model
linesearch               Which linesearch method to use
linesearch_maxtrials     Maximum number of linesearch trial points
linsolver                Which linear solver to use
linsolver_maxitref       Maximum number of iterative refinement steps
linsolver_nodeamalg      Controls node amalgamation for linear solvers
linsolver_numthreads     Number of parallel threads for linear solver
linsolver_ooc            Use out-of-core option?
linsolver_ordering       Ordering method for linear solvers
linsolver_pivottol       Initial pivot tolerance
linsolver_scaling        Scaling method for linear solvers
lmsize                   Number of limited-memory pairs stored for LBFGS
ma_maxtime_cpu           Maximum CPU time when 'algorithm=multi', in seconds
ma_maxtime_real          Maximum real time when 'algorithm=multi', in seconds
ma_outsub                Enable subproblem output when 'algorithm=multi'
ma_terminate             Termination condition when option 'algorithm=multi'
maxfevals                Maximum number of function evaluations
maxit                    Maximum number of iterations
maxtime_cpu              Maximum CPU time in seconds, per start point
maxtime_real             Maximum real time in seconds, per start point
mip_branchrule           MIP branching rule
mip_clique               Add clique cuts
mip_cut_flowcover        Add flow cover cuts
mip_cut_probing          Add probing cuts
mip_cutfactor            Limit on the number of cuts allowed in node subproblem
mip_cutoff               MIP objective cutoff value
mip_cutting_plane        When to perform cutting plane procedure
mip_debug                MIP debugging level (0=none, 1=all)
mip_gomory               Add Gomory cuts (0=none, 1=root)
mip_gub_branch           Branch on GUBs (0=no, 1=yes)
mip_heuristic_diving     MIP diving heuristic
mip_heuristic_feaspump   MIP feasibility pump heuristic
mip_heuristic_lns        MIP Large Neighborhood Search (LNS) heuristic
mip_heuristic_localsearch   MIP local search heuristic
mip_heuristic_maxit      MIP heuristic iteration limit
mip_heuristic_misqp      MIP MISQP heuristic
mip_heuristic_mpec       MIP MPEC heuristic
mip_heuristic_strategy   MIP heuristic strategy
mip_heuristic_terminate  MIP heuristic termination
mip_implications         Add logical implications (0=no, 1=yes)
mip_integer_tol          Threshold for deciding integrality
mip_intvar_strategy      Treatment of integer variables
mip_knapsack             Add knapsack cuts
mip_liftproject          Add lift and project cuts
mip_lpalg                LP subproblem algorithm
mip_maxnodes             Maximum nodes explored
mip_maxsolves            Maximum subproblem solves
mip_maxtime_cpu          Maximum CPU time in seconds for MIP
mip_maxtime_real         Maximum real in seconds time for MIP
mip_method               MIP method (0=auto, 1=BB, 2=HQG, 3=MISQP)
mip_mir                  Add mixed integer rounding cuts
mip_multistart           Enable MIP multistart
mip_nodealg              Standard node relaxation algorithm
mip_numthreads           Number of threads for MIP
mip_opt_gap_abs          Absolute optimality gap stop tolerance
mip_opt_gap_rel          Relative optimality gap stop tolerance
mip_outinterval          MIP output interval
mip_outlevel             MIP output level
mip_outsub               Enable MIP subproblem output
mip_pseudoinit           Pseudo-cost initialization
mip_relaxable            Are integer variables relaxable?
mip_restart              Enable MIP restart
mip_rootalg              Root node relaxation algorithm
mip_rounding             MIP rounding rule
mip_selectdir            MIP node selection direction
mip_selectrule           MIP node selection rule
mip_strong_candlim       Strong branching candidate limit
mip_strong_level         Strong branching tree level limit
mip_strong_maxit         Strong branching iteration limit
mip_terminate            Termination condition for MIP
mip_zerohalf             Add zero half cuts
ms_enable                Enable multi-start
ms_initpt_cluster        Clustering strategy for multistart
ms_maxbndrange           Maximum unbounded variable range for multi-start
ms_maxsolves             Maximum Knitro solves for multi-start
ms_maxtime_cpu           Maximum CPU time for multi-start, in seconds
ms_maxtime_real          Maximum real time for multi-start, in seconds
ms_num_to_save           Feasible points to save from multi-start
ms_numthreads            Number of parallel threads for multi-start
ms_outsub                Enable subproblem output for parallel multi-start
ms_savetol               Tol for feasible points being equal
ms_seed                  Seed for multi-start random generator
ms_startptrange          Maximum variable range for multi-start
ms_terminate             Termination condition for multi-start
ms_terminaterule_tol     The tolerance in (0,1] for the rule-based termination of multi-start
ncvx_qcqp_init           Initialization strategy for non-convex QPs/QCQPs
newpoint                 Use newpoint feature
numthreads               Number of parallel threads
objno                    objective number: 0 = none, 1 = first (default),
                         2 = second (if _nobjs > 1), etc.
objrange                 Objective range
objrep                   Whether to replace
                           minimize obj: v;
                         with
                           minimize obj: f(x)
                         when variable v appears linearly
                         in exactly one constraint of the form
                           s.t. c: v >= f(x);
                         or
                           s.t. c: v == f(x);
                         Possible objrep values:
                         0 = no
                         1 = yes for v >= f(x) (default)
                         2 = yes for v == f(x)
                         3 = yes in both cases
optionsfile              Name/location of Knitro options file if provided
opttol                   Optimality stopping tolerance
opttol_abs               Absolute optimality tolerance
out_csvinfo              Create knitro_solve.csv info file
out_csvname              Name for csv info file
out_hints                Print hints for parameter settings
outappend                Append to output files (0=no, 1=yes)
outdir                   Directory for output files
outlev                   Control printing level
outmode                  Where to direct output (0=screen, 1=file, 2=both)
outname                  Name for output file
presolve                 Knitro presolver level
presolve_dbg             Knitro presolver debugging level
presolve_initpt          Knitro presolver initial point handling
presolve_level           Knitro presolver level
presolve_passes          Knitro presolver pass limit
presolve_tol             Knitro presolver tolerance
presolveop_redundant     Constraint redundancy detection level
presolveop_substitution       Substitution application level
presolveop_substitution_tol   Substitution application tolerance
presolveop_tighten       Knitro presolve tightening operations
presolveop_varbnd_abs_max_val     Variable bound tightening tolerance for maximal magnitude.
presolveop_varbnd_rel_min_change  Variable bound tightening tolerance for minimal improvement.
relax                    whether to ignore integrality: 0 (default) = no, 1 = yes
restarts                 Maximum number of restarts allowed
restarts_maxit           Maximum number of iterations before restarting
scale                    Automatic scaling option
scale_vars               Variable scaling strategy
soc                      Second order correction options
storequadcoefs           Store quadratic coefficients when solving QCQPs
strat_warm_start         Enable warm-start strategy?
threads                  Number of parallel threads
timing                   Whether to report problem I/O and solve times:
                           0 (default) = no
                           1 = yes, on stdout
tuner                    Enables Knitro Tuner
tuner_maxtime_cpu        Maximum CPU time when 'tuner=on', in seconds
tuner_maxtime_real       Maximum real time when 'tuner=on', in seconds
tuner_optionsfile        Name/location of Tuner options file if provided
tuner_outsub             Enable subproblem output when 'tuner=on'
tuner_terminate          Termination condition when 'tuner=on'
version                  Report software version
wantsol                  solution report without -AMPL: sum of
                           1 ==> write .sol file
                           2 ==> print primal variable values
                           4 ==> print dual variable values
                           8 ==> do not print solution message
xpresslibname            Name of dynamic Xpress library
xtol                     Stepsize stopping tolerance
xtol_iters               Stop based on small change in variables

These options are detailed below.

Knitro options in AMPL

  • act_lpalg: LP subproblem algorithm in Active Set or SQP algorithm (default 0). See act_lpalg.

Value

Description

0

default LP algorithm

1

primal simplex algorithm

2

dual simplex algorithm

3

barrier/interior-point algorithm

  • act_lpdumpmps: Used for internal debugging.

  • act_lpfeastol: feasibility tolerance for LP subproblems (default 1.0e-8). See act_lpfeastol.

  • act_lppenalty: Use penalty formulation for LP subproblems in Active Set or SQP algorithm (default 1). See act_lppenalty.

Value

Description

1

penalize all constraints

2

penalize only nonlinear constraints

3

dynamically choose which constraints to penalize

  • act_lppresolve: Control presolve for LP subproblems in Active Set or SQP algorithm (default 0). See act_lppresolve.

Value

Description

0

presolve turned off for LP subproblems

1

presolve turned on for LP subproblems

  • act_lpsolver: LP solver used in Active Set or SQP algorithm (default 1). See act_lpsolver.

  • act_parametric: Use parametric LP subproblems in Active Set or SQP algorithm (default 1). See act_parametric.

Value

Description

0

do not use a parametric solve

1

use a parametric solve sometimes

2

always try a parametric solve

  • act_qpalg: QP subproblem algorithm in Active Set or SQP algorithm (default 0). See act_qpalg.

Value

Description

0

let Knitro decide the QP algorithm

1

Interior/Direct (barrier) algorithm

2

Interior/CG (barrier) algorithm

3

Active Set algorithm

  • act_qppenalty: Use penalty formulation for QP subproblems in SQP algorithm (default -1). See act_qppenalty.

Value

Description

-1

let Knitro determine automatically

0

do not penalize constraints in QP subproblems

1

penalize all constraints in QP subproblems

  • alg or algorithm: optimization algorithm used (default 0). See algorithm.

Value

Description

0

let Knitro choose the algorithm

1

Interior/Direct (barrier) algorithm

2

Interior/CG (barrier) algorithm

3

Active Set algorithm

4

Sequential Quadratic Programming (SQP) algorithm

5

Run multiple algorithms

  • bar_conic_enable: enable special treatment for conic constraints (default -1). See bar_conic_enable.

Value

Description

-1

let Knitro determine automatically

0

do not apply any special treatment for conic constraints

1

apply special treatments for any Second Order Cone (SOC) constraints

  • bar_directinterval: frequency for trying to force direct steps (default 10). See bar_directinterval.

  • bar_feasible: whether feasibility is given special emphasis (default 0). See bar_feasible.

Value

Description

0

no special emphasis on feasibility

1

iterates must honor inequalities

2

emphasize first getting feasible before optimizing

3

implement both options 1 and 2 above

  • bar_feasmodetol: tolerance for entering stay feasible mode (default 1.0e-4). See bar_feasmodetol.

  • bar_globalize: globalization strategy used for the barrier algorithms (default 2). See bar_globalize.

Value

Description

0

do not apply any globalization strategy

1

apply a globalization strategy based on decreasing the KKT error

2

apply a globalization strategy using a filter based on the objective and constraint violation

  • bar_initmu: initial value for barrier parameter (default 1.0e-1). See bar_initmu.

  • bar_initpi_mpec: initial value for barrier MPEC penalty parameter. Knitro uses an internal formula to initialize the MPEC penalty parameter if a non-positive value is specified (default 0.0). See bar_initpi_mpec.

  • bar_initpt: initial settings of x (if not set by user), slacks and multipliers for barrier algorithms (default 0). See bar_initpt.

Value

Description

0

let Knitro choose the initial point strategy

1

initialization strategy for LP, convex QP (x unaffected if initialized by user)

2

initialization strategy staying near bounds (x unaffected if initialized by user)

3

initialization strategy more central to bounds (x unaffected if initialized by user)

  • bar_linsys: linear system form used in barrier direct algorithm (default -1). See bar_linsys.

Value

Description

-1

let Knitro choose automatically

0

use the full system

1

eliminate the slack variables

2

eliminate slacks and bounds

3

eliminate slacks, bounds, and some inequalities

  • bar_linsys_storage: linear system storage used for barrier direct algorithm (default -1). See bar_linsys_storage.

Value

Description

-1

let Knitro choose automatically

1

low memory storage (use the same memory for multiple systems)

2

normal storage (separate memory for different linear systems)

  • bar_maxcorrectors: maximum number of primal-dual corrector steps (default -1). See bar_maxcorrectors.

  • bar_maxcrossit: maximum number of allowable crossover iterations (default 0). See bar_maxcrossit.

  • bar_maxmu: maximum allowed barrier parameter value (default 1.0e16). See bar_maxmu.

  • bar_maxrefactor: maximum number of KKT refactorizations allowed (default -1). See bar_maxrefactor.

  • bar_mpec_heuristic: enable a heuristic approach when using the barrier algorithm to solve an MPEC model (default 0). See bar_mpec_heuristic.

Value

Description

0

do not enable the heuristic for MPEC models when using the barrier algorithm

1

enable the heuristic for MPEC models when using the barrier algorithm

  • bar_murule: barrier parameter update rule (default 0). See bar_murule.

Value

Description

0

let Knitro choose the barrier update rule

1

monotone decrease rule

2

adaptive rule based on complementarity gap

3

probing rule (Interior/Direct only)

4

safeguarded Mehrotra predictor-corrector type rule

5

Mehrotra predictor-corrector type rule

6

rule based on minimizing a quality function

  • bar_penaltycons: technique for penalizing constraints in the barrier algorithms (default -1). See bar_penaltycons.

Value

Description

-1

let Knitro choose the strategy

0

do not apply penalty approach to any constraints

2

apply a penalty approach to all general constraints

  • bar_penaltyrule: penalty parameter rule for step acceptance (default 0). See bar_penaltyrule.

Value

Description

0

let Knitro choose the strategy

1

use single penalty parameter approach

2

use more tolerant, flexible strategy

  • bar_refinement: specify whether to refine barrier solution for more precision (default 0). See bar_refinement.

Value

Description

0

do not apply refinement phase

1

try to refine the barrier solution

  • bar_relaxcons: specify whether to relax constraints in the barrier algorithms (default 2). See bar_relaxcons.

Value

Description

0

do not relax constraints

1

relax equality constraints only

2

relax inequality constraints only

3

relax all constraints

  • bar_slackboundpush: minimum amount by which initial slack variables are pushed inside the bounds (default 1.0e-1). See bar_slackboundpush.

  • bar_switchobj: the objective function to use when Knitro switches to feasibility phase in the barrier algorithms (default 1). See bar_switchobj.

Value

Description

0

no (or zero) objective function

1

proximal point objective scaled by a scalar value

2

proximal point objective using a diagonal scaling

  • bar_switchrule: controls technique for switching between feasibility phase and optimality phase in the barrier algorithms (default -1). See bar_switchrule.

Value

Description

-1

let Knitro determine the switching procedure

0

never switch to feasibility phase

2

allow switches to feasibility phase

3

use more aggressive switching rule

  • bar_watchdog: specify whether to enable watchdog heuristic for barrier algorithms (default 0). See bar_watchdog.

Value

Description

0

do not apply watchdog heuristic

1

enable watchdog heuristic

  • bfgs_scaling: specify the initial scaling to use for the BFGS or L-BFGS Hessian (default 0). See bfgs_scaling.

Value

Description

0

make a dynamic choice of which scaling to use (for L-BFGS this may change at each iteration)

1

use a scaling that approximates the scale of the inverse Hessian

2

use a scaling that approximates the scale of the Hessian

  • blas_numthreads: specify the number of threads to use for BLAS (default 0). See blas_numthreads.

Value

Description

0

let Knitro choose the number of threads

n

use n > 0 threads

  • blasoption: specify the BLAS/LAPACK function library to use (default -1). See blasoption.

Value

Description

-1

let Knitro automatically choose which BLAS to use

0

use Knitro built-in functions

1

use Intel Math Kernel Library functions

2

use the dynamic library specified with blasoptionlib

3

use BLIS Library functions (not available on Windows OS)

4

use Apple Accelerate (only available on Mac with M1 processor)

  • blasoptionlib: specify the BLAS/LAPACK function library if using blasoption=2. See blasoptionlib.

  • bndrange: max limit for finite bounds (default 1e20). See bndrange.

  • cg_maxit: maximum allowable conjugate gradient (CG) iterations (default -1). See cg_maxit.

Value

Description

0

let Knitro set the number based on the problem size

n

maximum of n > 0 CG iterations per minor iteration

  • cg_pmem: amount of memory n used for the incomplete Cholesky preconditioner where n enforces the maximum number of nonzero elements per column in the matrix (default 10). See cg_pmem.

  • cg_precond: whether or not to apply an incomplete Cholesky preconditioner for the CG subproblems in the barrier algorithms (default 0). See cg_precond.

Value

Description

0

no preconditioner used

1

apply incomplete Cholesky preconditioner

  • cg_stoptol: relative stopping tolerance for CG subproblems (default 1.0e-2). See cg_stoptol.

  • conic_numthreads: specify the number of threads to use for operations in the conic solver (default 0). See conic_numthreads.

Value

Description

0

let Knitro choose the number of threads

n

use n > 0 threads

  • convex: declare the problem as convex (default -1). See convex.

Value

Description

-1

Knitro will try to automatically determine convexity

0

Knitro will treat the problem as non-convex

1

Knitro will treat the problem as convex

  • cpuplatform: Target CPU platform/architecture (default -1). See cpuplatform.

Value

Description

-1

determine automatically

1

compatible SSE2-based architecture

2

SSE2

3

AVX

4

AVX2

5

AVX512

  • debug: enable debugging output (default 0). See debug.

Value

Description

0

no extra debugging

1

print info to debug solution of the problem

2

print info to debug execution of the solver

  • delta: initial trust region radius scaling (default 1.0e0). See delta.

  • eval_cost: the relative cost of performing function/derivative evaluations (default 0). See eval_cost.

Value

Description

0

evaluation cost is unspecified

1

evaluation cost is relatively inexpensive

2

evaluation cost is relatively expensive

  • feastol: feasibility termination tolerance (relative) (default 1.0e-6). See feastol.

  • feastol_abs: feasibility termination tolerance (absolute) (default 1.0e-3). See feastol_abs.

  • findiff_estnoise: enable noise estimate when using finite-difference gradients (default 0). See findiff_estnoise.

Value

Description

0

do not enable any noise estimation procedure for finite-difference gradients

1

enable noise estimation procedure for finite-difference gradients

2

enable noise estimation and curvature factor for finite-difference gradients

  • findiff_relstepsize: relative stepsize for finite-difference gradients (default sqrt(eps) for forward-difference and eps^(1/3) for central difference). See findiff_relstepsize.

  • findiff_terminate: termination rule when using finite-difference gradients (default 1). See findiff_terminate.

Value

Description

0

use standard termination conditions

1

allow termination based on finite-difference error estimates

  • fstopval: stop based on user-defined function value (default KN_INFINITY). See fstopval.

  • ftol: stop based on small (feasible) changes in the objective function (default 1.0e-15). See ftol.

  • ftol_iters: stop based on small (feasible) changes in the objective function (default 5). See ftol_iters.

  • gradopt: gradient computation method (default 1). See gradopt.

Value

Description

1

use exact gradients

2

compute forward finite-difference approximations

3

compute centered finite-difference approximations

  • hessopt: Hessian (Hessian-vector) computation method (default 1). See hessopt.

Value

Description

1

use exact Hessian derivatives

2

use dense quasi-Newton BFGS Hessian approximation

3

use dense quasi-Newton SR1 Hessian approximation

4

compute Hessian-vector products by finite diffs

5

compute exact Hessian-vector products

6

use limited-memory BFGS Hessian approximation

  • honorbnds: allow or not bounds to be violated during the optimization (default -1). See honorbnds.

Value

Description

-1

automatically determine the best setting

0

allow bounds to be violated during the optimization

1

enforce bounds satisfaction of all iterates

2

enforce bounds satisfaction of initial point

  • infeastol: tolerance for declaring infeasibility (default 1.0e-8). See infeastol.

  • infeastol_iters: stop based on small changes in the feasibility error while infeasible (default 50). See infeastol_iters.

  • initpenalty: initial merit function penalty value (default 1.0e1). See initpenalty.

  • initpt_strategy: the initial point strategy used for the continuous algorithms (default -1). See initpt_strategy.

Value

Description

-1

automatically determine the initial point strategy

1

try basic initial point strategy

2

try more advanced initial point strategy

  • leastsquares: set to 1 to solve the AMPL model as a least-squares model (default 0). See section below on Nonlinear Least Squares.

  • linesearch: linesearch strategy for algorithms using a linesearch (default 0). See linesearch.

Value

Description

0

let Knitro automatically choose the strategy

1

use a simple backtracking linesearch

2

use a cubic interpolation linesearch

3

linesearch satisfying the weak Wolfe conditions (unconstrained only)

  • linesearch_maxtrials: maximum number of linesearch trial evaluations (default 3). See linesearch_maxtrials.

  • linsolver: linear system solver to use inside Knitro (default 0). See linsolver.

Value

Description

0

let Knitro choose the linear system solver

1

(not currently used; same as 0)

2

use a hybrid approach; solver depends on system

3

use a dense QR method (small problems only)

4

use HSL MA27 sparse symmetric indefinite solver

5

use HSL MA57 sparse symmetric indefinite solver

6

use Intel MKL PARDISO sparse symmetric indefinite solver

7

use HSL MA97 sparse symmetric indefinite solver

8

use HSL MA86 sparse symmetric indefinite solver

  • linsolver_maxitref: maximum number of iterative refinement steps when solving a linear system (default 2). See linsolver_maxitref.

  • linsolver_nodeamalg: controls node amalgamation for MA57, MA86 and MA97 linear solvers (default 0). See linsolver_nodeamalg.

Value

Description

0

use default value for linear solver

n>0

set node amalgamation value to n > 0

  • linsolver_numthreads: specify the number of threads to use for linear system solves (default 0). See linsolver_numthreads.

Value

Description

0

let Knitro choose the number of threads

n>0

use n > 0 threads

  • linsolver_ooc: solve linear system out-of-core (default 0). See linsolver_ooc.

Value

Description

0

do not solve linear systems out-of-core

1

invoke Intel MKL PARDISO out-of-core option sometimes (only when linsolver = 6)

2

invoke Intel MKL PARDISO out-of-core option always (only when linsolver = 6)

  • linsolver_ordering: sets ordering method for linear system solvers (default -1). See linsolver_ordering.

Value

Description

-1

let Knitro automatically choose the ordering strategy

0

choose the best between AMD and METIS (try both)

1

use AMD ordering (minimum degree when linsolver = 6)

2

use METIS ordering

  • linsolver_pivottol: initial pivot threshold for matrix factorizations (default 1.0e-8). See linsolver_pivottol.

  • linsolver_scaling: controls scaling for linear solvers (default 0). See linsolver_scaling.

Value

Description

0

do not apply scaling in the linear system solves

1

always apply scaling in the linear system solves

2

dynamically apply scaling in the linear system solves

  • lmsize: number of limited-memory pairs stored in LBFGS approach (default 10). See lmsize.

  • ma_maxtime_cpu: maximum CPU time in seconds before terminating for the multi-algorithm (alg=5) procedure (default 1.0e8). See ma_maxtime_cpu.

  • ma_maxtime_real: maximum real time in seconds before terminating for the multi-algorithm (alg=5) procedure (default 1.0e8). See ma_maxtime_real.

  • ma_outsub: enable writing algorithm output to files for the multi-algorithm (alg=5) procedure (default 0). See ma_outsub.

Value

Description

0

do not write detailed algorithm output to files

1

write detailed algorithm output to files named knitro_ma_*.log

  • ma_terminate: termination condition for multi-algorithm (alg=5) procedure (default 1). See ma_terminate.

Value

Description

0

terminate after all algorithms have completed

1

terminate at first local optimum

2

terminate at first feasible solution

3

terminate after first completed optimization (any termination status)

  • maxfevals: maximum number of function evaluations before terminating (default unlimited). See maxfevals.

  • maxit: maximum number of iterations before terminating (default 0). See maxit.

Value

Description

0

let Knitro set the number based on the problem

n

maximum limit of n > 0 iterations

  • maxtime_cpu: maximum CPU time in seconds before terminating (default 1.0e8). See maxtime_cpu.

  • maxtime_real: maximum real time in seconds before terminating (default 1.0e8). See maxtime_real.

  • mip_branchrule: MIP branching rule (default 0). See mip_branchrule.

Value

Description

0

let Knitro choose the branching rule

1

most-fractional branching

2

pseudo-cost branching

3

strong branching

  • mip_clique: enable clique cuts (default -1). See mip_clique.

Value

Description

-1

automatically determine

0

do not allow clique cuts

1

add clique cuts derived from root node

2

add clique cuts derived at every node

Value

Description

-1

automatically determine

0

do not allow flow cover cuts

1

add flow cover cuts derived from root node

2

add flow cover cuts derived at every node

Value

Description

-1

automatically determine

0

do not allow probing cuts

1

add probing cuts derived from root node

2

add probing cuts derived at every node

  • mip_cutfactor: limit on the number of cuts allowed in node subproblem (default 1.0). See mip_cutfactor.

  • mip_cutoff: objective cutoff value for MIP (default KN_INFINITY). See mip_cutoff.

  • mip_cutting_plane: enable cutting plane procedure (default 1). See mip_cutting_plane.

Value

Description

0

cutting planes not enabled

1

cutting planes enabled at root node

  • mip_debug: MIP debugging level (default 0). See mip_debug.

Value

Description

0

no MIP debugging output

1

print MIP debugging information

  • mip_gomory: enable Gomory mixed-integer cuts (default -1). See mip_gomory.

Value

Description

-1

automatically determine

0

do not allow Gomory cuts

1

add Gomory cuts derived from root node

2

add Gomory cuts derived at every node

Value

Description

0

do not branch on GUB constraints

1

allow branching on GUB constraints

  • mip_heuristic_diving: bit-valued option to enable diving heuristics (default -1). See mip_heuristic_diving.

Bit

Value

Description

NA

-1

automatically determined from mip_heuristic_strategy

0

1

enable fractional diving heuristic

1

2

enable vector length diving heuristic

2

4

enable coefficient diving heuristic

3

8

enable linesearch diving heuristic

4

16

enable guided diving heuristic

Value

Description

-1

automatically determine

0

feasibility pump heuristic not enabled

1

feasibility pump heuristic enabled

  • mip_heuristic_lns: bit-valued option to enable large neighborhood search (LNS) heuristics (default -1). See mip_heuristic_lns.

Bit

Value

Description

NA

-1

automatically determined from mip_heuristic_strategy

0

1

enable relaxation enforced neighborhood search (RENS) heuristic

1

2

enable relaxation induced neighborhood search (RINS) heuristic

Value

Description

-1

automatically determine

0

local search heuristic not enabled

1

local search heuristic enabled

Value

Description

-1

automatically determine

0

MISQP heuristic not enabled

1

MISQP heuristic enabled

Value

Description

-1

automatically determine

0

MPEC heuristic not enabled

1

MPEC heuristic enabled

Value

Description

-1

let Knitro determine automatically

0

do not apply any heuristics

1

apply basic heuristics

2

apply more advanced heuristics

3

apply most extensive heuristics

Value

Description

1

terminate at first feasible point or iteration limit

2

always run the heuristic to the iteration limit

Value

Description

0

do not add constraints from logical implications

1

add constraints from logical implications

  • mip_integer_tol: threshold for deciding integrality (default 1.0e-8). See mip_integer_tol.

  • mip_intvar_strategy: treatment of integer variables (default 0). See mip_intvar_strategy.

Value

Description

0

no special treatment

1

relax all integer variables

2

convert all binary variables to complementarity constraints

  • mip_knapsack: add knapsack cuts (default -1). See mip_knapsack.

Value

Description

-1

automatically determine

0

do not allow knapsack cuts

1

add knapsack cuts derived from root node

2

add knapsack cuts derived at every node

  • mip_liftproject: enable lift and project cuts (default -1). See mip_liftproject.

Value

Description

-1

automatically determine

0

do not allow lift and project cuts

1

enable lift and project cuts at the root node

  • mip_lpalg: LP subproblem algorithm (default 0). See mip_lpalg.

Value

Description

0

let Knitro decide the LP algorithm

1

Interior/Direct (barrier) algorithm

2

Interior/CG (barrier) algorithm

3

Active Set (simplex) algorithm

  • mip_maxnodes: maximum nodes explored (default 0). See mip_maxnodes.

  • mip_maxsolves: maximum subproblem solves (default 0). See mip_maxsolves.

  • mip_maxtime_cpu: maximum CPU time in seconds for MIP (default 1.0e8). See mip_maxtime_cpu.

  • mip_maxtime_real: maximum real time in seconds for MIP (default 1.0e8). See mip_maxtime_real.

  • mip_method: MIP method (default 0). See mip_method.

Value

Description

0

let Knitro choose the method

1

branch-and-bound method

2

hybrid method for convex nonlinear models

3

mixed-integer SQP method

  • mip_mir: enable mixed-integer rounding cuts (default -1). See mip_mir.

Value

Description

-1

let Knitro decide whether to add mixed-integer rounding cuts

0

do not add mixed-integer rounding cuts

1

add mixed-integer rounding cuts derived from root node

2

add mixed-integer rounding cuts derived at every node

  • mip_multistart: enable multi-start at the branch-and-bound level (default 0). See mip_multistart.

Value

Description

0

do not allow MIP multistart

1

enable MIP multistart

  • mip_nodealg: standard node relaxation algorithm (default 0). See mip_nodealg.

Value

Description

0

let Knitro decide the node algorithm

1

Interior/Direct (barrier) algorithm

2

Interior/CG (barrier) algorithm

3

Active Set algorithm

4

SQP algorithm

5

Run multiple algorithms

  • mip_numthreads: specify the number of threads to use for MIP branch-and-bound (default 0). See mip_numthreads.

Value

Description

0

let Knitro choose the number of threads

n

use n > 0 threads

  • mip_opt_gap_abs: absolute optimality gap stop tolerance (default 1.0e-6). See mip_opt_gap_abs.

  • mip_opt_gap_rel: relative optimality gap stop tolerance (default 1.0e-4). See mip_opt_gap_rel.

  • mip_outinterval: MIP node output interval (default 0). See mip_outinterval.

  • mip_outlevel: MIP output level (default 2). See mip_outlevel.

  • mip_outsub: enable MIP subproblem debug output (default 0). See mip_outsub.

  • mip_pseudoinit: method to initialize pseudo-costs (default 0). See mip_pseudoinit.

Value

Description

0

let Knitro choose the method

1

use average value

2

use strong branching

  • mip_relaxable: are integer variables relaxable? (default 1). See mip_relaxable.

Value

Description

0

integer variables are not relaxable

1

all integer variables are relaxable

  • mip_restart: enable the MIP restart procedure? (default 1). See mip_restart.

Value

Description

0

do not enable the MIP restart procedure

1

enable the MIP restart procedure

  • mip_rootalg: root node relaxation algorithm (default 0). See mip_rootalg.

Value

Description

0

let Knitro decide the root algorithm

1

Interior/Direct (barrier) algorithm

2

Interior/CG (barrier) algorithm

3

Active Set algorithm

4

SQP algorithm

5

Run multiple algorithms

  • mip_rounding: MIP rounding rule (default -1). See mip_rounding.

Value

Description

-1

let Knitro choose the rounding rule

0

do not attempt rounding

2

use fast heuristic

3

apply rounding solve selectively

4

apply rounding solve always

  • mip_selectdir: MIP node selection direction (default 0). See mip_selectdir.

Value

Description

0

choose down (i.e. <=) node first

1

choose up (i.e. >=) node first

  • mip_selectrule: MIP node selection rule (default 0). See mip_selectrule.

Value

Description

0

let Knitro choose the node select rule

1

use depth first search

2

use best bound node selection

3

use a combination of depth first and best bound

  • mip_strong_candlim: strong branching candidate limit (default 128). See mip_strong_candlim.

  • mip_strong_level: strong branching level limit (default 10). See mip_strong_level.

  • mip_strong_maxit: strong branching subproblem iteration limit (default 1000). See mip_strong_maxit.

  • mip_terminate: termination condition for MIP (default 0). See mip_terminate.

Value

Description

0

terminate at optimal solution

1

terminate at first integer feasible solution

  • mip_zerohalf: enable zero-half cuts (default -1). See mip_zerohalf.

Value

Description

-1

automatically determine

0

do not add zero-half cuts

1

add zero-half cuts derived from root node

2

add zero-half cuts derived at every node

  • ms_enable: multi-start feature (default 0). See ms_enable.

Value

Description

0

multi-start disabled

1

multi-start enabled

  • ms_initpt_cluster: the clustering strategy used to select initial points for multi-start (default 0). See ms_initpt_cluster.

Value

Description

0

do not use any clustering strategy

1

apply single linkage based clustering

  • ms_maxbndrange: maximum range to vary unbounded x when generating start points (default 1.0e3). See ms_maxbndrange.

  • ms_maxsolves: maximum number of start points to try during multi-start (default 0). See ms_maxsolves.

Value

Description

0

let Knitro set the number based on problem size

n

try exactly n > 0 start points

  • ms_maxtime_cpu: maximum CPU time for multi-start, in seconds (default 1.0e8). See ms_maxtime_cpu.

  • ms_maxtime_real: maximum real time for multi-start, in seconds (default 1.0e8). See ms_maxtime_real.

  • ms_num_to_save: number of feasible points to save in knitro_mspoints.log (default 0). See ms_num_to_save.

  • ms_numthreads: specify the number of threads to use for multi-start (default 0). See ms_numthreads.

Value

Description

0

let Knitro choose the number of threads

n

use n > 0 threads

  • ms_outsub: enable writing output from subproblem solves to files for parallel multi-start (default 0). See ms_outsub.

Value

Description

0

do not write subproblem output to files

1

write detailed subproblem output to files named knitro_ms_*.log

  • ms_savetol: tolerance for feasible points to be considered distinct (default 1.0e-6). See ms_savetol.

  • ms_seed: seed value used to generate random initial points in multi-start; should be a non-negative integer (default 0). See ms_seed.

  • ms_startptrange: maximum range to vary all x when generating start points (default 1.0e20). See ms_startptrange.

  • ms_terminate: termination condition for multi-start (default 4). See ms_terminate.

Value

Description

0

terminate after ms_maxsolves

1

terminate at first local optimum (if before ms_maxsolves)

2

terminate at first feasible solution (if before ms_maxsolves)

3

terminate after first completed optimization (any termination status)

4

terminate using rules that estimate when the probability of finding new local solutions is low

  • ms_terminaterule_tol: tolerance in (0,1] for the rule-based termination of multi-start; non-positive value uses automatic setting (default 0.0). See ms_terminaterule_tol.

  • ncvx_qcqp_init: initialization strategy for non-convex QPs and QCQPs (default -1). See ncvx_qcqp_init.

Value

Description

-1

automatically determine the strategy

0

no special initialization strategy

1

initialize by solving a linear relaxation

2

initialize by solving a hybrid formulation

3

initialize by solving a penalty formulation

4

initialize by solving a convex quadratic relaxation

  • newpoint: how to save new points found by the solver. (default 0). See newpoint.

Value

Description

0

no action

1

save the latest new point to file knitro_newpoint.log

2

append all new points to file knitro_newpoint.log

  • numthreads: specify the number of threads to use for all parallel features (default -1). See numthreads.

Value

Description

-1

let Knitro choose the number of threads

0

determine by environment variable $OMP_NUM_THREADS

n

use n > 0 threads

  • objrange: maximum allowable objective function magnitude (default 1.0e20). See objrange.

  • optionsfile: path that specifies the location of a Knitro options file if used.

  • opttol: optimality termination tolerance (relative) (default 1.0e-6). See opttol.

  • opttol_abs: optimality termination tolerance (absolute) (default 1.0e-3). See opttol_abs.

  • out_csvinfo: create knitro_solve.csv information file (default 0). See out_csvinfo.

Value

Description

0

do not create solve information file

1

create solve information file

  • out_csvname: custom name for csv information file (default knitro_solve.csv). See out_csvname.

  • out_hints: print diagnostic hints at the end of the solve (default 1). See out_hints.

Value

Description

0

do not print hints

1

print hints

  • outappend: append output to existing files (default 0). See outappend.

Value

Description

0

do not append

1

do append

  • outdir: directory where output files are created. See outdir.

  • outlev: printing output level (default 2). See outlev.

Value

Description

0

no printing

1

just print summary information

2

print basic information every 10 iterations

3

print basic information at each iteration

4

print all information at each iteration

5

also print final (primal) variables

6

also print final Lagrange multipliers (sensitivies)

  • outmode: Knitro output redirection (default 0). See outmode.

Value

Description

0

direct Knitro output to standard out (e.g., screen)

1

direct Knitro output to the file knitro.log

2

print to both the screen and file knitro.log

  • outname: custom name for Knitro log file (default knitro.log). See outname.

  • presolve: enable Knitro presolver (default 1). See presolve.

Value

Description

0

do not use the Knitro presolver

1

use the Knitro presolver

  • presolve_dbg: presolve debug output (default 0).

Value

Description

0

no debugging information

2

print the Knitro problem with AMPL model names

  • presolve_initpt: controls presolver shifting of initial point (default -1). See presolve_initpt.

Value

Description

-1

let Knitro choose automatically

0

do not allow presolver to shift user-supplied initial point

1

allow presolver to shift user-supplied initial point if it only appears in linear constraints

2

allow presolver to shift any user-supplied initial point

  • presolve_level: Knitro presolve level (default -1). See presolve_level.

Value

Description

-1

let Knitro choose the presolve level

1

enable basic presolve operatins

2

enable more advanced presolve operatins

  • presolve_passes: limit on the number of passes through the Knitro presolver (default 10). See presolve_passes.

  • presolve_tol: tolerance used by Knitro presolver to remove variables and constraints (default 1.0e-6). See presolve_tol.

  • presolveop_redundant: presolve operations for removal of redundant constraints (default 1). See presolveop_redundant.

Value

Description

0

do not detect redundant constraints

1

detect and remove duplicate constraints

2

detect and remove linearly dependent constraints

  • presolveop_tighten: Knitro presolve tightening operations (default -1). See presolveop_tighten.

Value

Description

-1

let Knitro choose whether to apply tightening

0

do not apply tightening

1

apply tightening on variable bounds

2

apply tightening on coefficients

3

apply tightening on both bounds and coefficients

  • restarts: enable automatic restarts (default 0). See restarts.

Value

Description

0

do not enable automatic restarts

n

maximum of n > 0 restarts allowed

  • restarts_maxit: maximum number of iterations before enforcing a restart (default 0). See restarts_maxit.

  • scale: automatic scaling (default 1). See scale.

Value

Description

0

do not scale the problem

1

perform automatic scaling of functions

  • scale_vars: strategy for variable scaling (default 0). See scale_vars.

Value

Description

0

do not apply any variable scaling

1

apply variable scaling based on their bound values

  • soc: 2nd order corrections (default 1). See soc.

Value

Description

0

do not allow second order correction steps

1

selectively try second order correction steps

2

always try second order correction steps

  • storequadcoefs: store quadratic coefficients for QCQP (default 1).

Value

Description

0

do not store quadratic coefficients

1

store quadratic coefficients

  • strat_warm_start: enable warm-start strategy (default 0). See strat_warm_start.

Value

Description

0

do not enable warm-start strategy

1

enable warm-start strategy (currently just for barrier algorithms)

  • tuner: invoke Knitro-Tuner (default 0). See tuner.

Value

Description

0

tuner disabled

1

tuner enabled

  • tuner_maxtime_cpu: maximum CPU time in seconds before terminating the Knitro-Tuner (tuner=1) procedure (default 1.0e8). See tuner_maxtime_cpu.

  • tuner_maxtime_real: maximum real time in seconds before terminating the Knitro-Tuner (tuner=1) procedure (default 1.0e8). See tuner_maxtime_real.

  • tuner_optionsfile: path that specifies the location of a Knitro-Tuner (tuner=1) options file if used.

  • tuner_outsub: enable writing additional Tuner subproblem solve output to files for the Knitro-Tuner (tuner=1) procedure (default 0). See tuner_outsub.

Value

Description

0

do not write detailed algorithm output to files

1

write summary solve output to a file named knitro_tuner_summary.log

2

write detailed algorithm output to files named knitro_tuner_*.log

  • tuner_terminate: termination condition for Knitro-Tuner (tuner=1) procedure (default 0). See tuner_terminate.

Value

Description

0

terminate after all solves have completed

1

terminate at first local optimum

2

terminate at first feasible solution

3

terminate after first completed optimization (any termination status)

  • xtol: stepsize termination tolerance (default 1.0e-15). See xtol.

  • xtol_iters: stop based on small changes in the solution estimate. See xtol_iters.

Return codes

Upon completion, Knitro displays a message and returns an exit code to AMPL. If Knitro found a solution, it displays the message:

Locally optimal or satisfactory solution

with exit code of zero; the exit code can be seen by typing:

ampl: display solve_result_num;

If a solution is not found, then Knitro returns a non-zero return code from the table below:

Value

Description

0

Locally optimal or satisfactory solution.

100

Current feasible solution estimate cannot be improved. Nearly optimal.

101

Relative change in feasible solution estimate < xtol.

102

Current feasible solution estimate cannot be improved.

103

Relative change in feasible objective < ftol for ftol_iters.

200

Convergence to an infeasible point. Problem may be locally infeasible.

201

Relative change in infeasible solution estimate < xtol.

202

Current infeasible solution estimate cannot be improved.

203

Multistart: No primal feasible point found.

204

Problem determined to be infeasible with respect to constraint bounds.

205

Problem determined to be infeasible with respect to variable bounds.

300

Problem appears to be unbounded.

400

Iteration limit reached. Current point is feasible.

401

Time limit reached. Current point is feasible.

402

Function evaluation limit reached. Current point is feasible.

403

MIP: All nodes have been explored. Integer feasible point found.

404

MIP: Integer feasible point found.

405

MIP: Subproblem solve limit reached. Integer feasible point found.

406

MIP: Node limit reached. Integer feasible point found.

410

Iteration limit reached. Current point is infeasible.

411

Time limit reached. Current point is infeasible.

412

Function evaluation limit reached. Current point is infeasible.

413

MIP: All nodes have been explored. No integer feasible point found.

415

MIP: Subproblem solve limit reached. No integer feasible point found.

416

MIP: Node limit reached. No integer feasible point found.

501

LP solver error.

502

Evaluation error.

503

Not enough memory.

504

Terminated by user.

505

Terminated after derivative check.

506

Input or other API error.

507

Internal Knitro error.

508

Unknown termination.

509

Illegal objno value.

For more information on return codes, see Return codes.

AMPL suffixes defined for Knitro

To represent values associated with a model component, AMPL employs various qualifiers or suffixes appended to component names. A suffix consists of a period or “dot” (.) followed by a short identifier (ex: x1.lb returns the current lower bound of the variable x1).

A lot of built-in suffixes are available in AMPL, you may find the list at http://www.ampl.com/NEW/suffbuiltin.html.

To allow more solver-specific results of optimization, AMPL permits solver drivers to define new suffixes and to associate solution result information with them. Below is the list of the suffixes defined specifically for Knitro.

Suffix Name

Description

Model component

xhonorbnd

Specify variables that must always satisfy bounds; see honorbnds (input)

variable

chonorbnd

Specify constraints that must always satisfy bounds; see bar_feasible (input)

constraint

intvarstrategy

Treatment of integer variables; see mip_intvar_strategy (input)

variable

cfeastol

Specify individual constraint feasibility tolerances (input)

constraint

xfeastol

Specify individual variable bound feasibility tolerances (input)

variable

xscalefactor

Specify custom variable scaling factors (input)

variable

xscalecenter

Specify custom variable scaling centers (input)

variable

cscalefactor

Specify custom constraint scaling factors (input)

constraint

objscalefactor

Specify custom objective scaling factor (input)

objective

relaxbnd

Retrieve the best relaxation bound for MIP (output)

objective

incumbent

Retrieve the incumbent solution for MIP (output)

objective

priority

Specify branch priorities for MIP (input)

variable

numiters

Retrieve the number of iterations (output)

objective

numfcevals

Retrieve the number of function evaluations (output)

objective

opterror

Retrieve the final optimality error (output)

objective, variable, constraint

feaserror

Retrieve the final feasibility error (output)

objective, variable, constraint

Below is an example on how to use the specific Knitro suffixes in AMPL:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var x{j in 1..3} >= 0;

minimize obj: 1000 - x[1]^2 - 2*x[2]^2 - x[3]^2 - x[1]*x[2] - x[1]*x[3];

s.t. c1: 8*x[1] + 14*x[2] + 7*x[3] - 56 = 0;

s.t. c2: x[1]^2 + x[2]^2 + x[3]^2 -25 >= 0;

suffix xfeastol IN, >=0, <=1e6;
suffix cfeastol IN, >=0, <=1e6;
suffix objscalefactor IN, >=1e-6, <=1e6;

let x[1].xfeastol := 1e-1;
let c1.cfeastol := 1e-2;
let obj.objscalefactor := 2;

solve;

display x[1].feaserror;
display c1.opterror;
display obj.numfcevals;
display obj.feaserror;
display obj.opterror;

Below is the corresponding output:

Final Statistics
----------------
Final objective value               =  9.51000000020162e+002
Final feasibility error (abs / rel) =   7.11e-015 / 4.55e-016
Final optimality error  (abs / rel) =   3.84e-009 / 1.37e-010
# of iterations                     =          9
# of CG iterations                  =          2
# of function evaluations           =          0
# of gradient evaluations           =          0
# of Hessian evaluations            =          0
Total program time (secs)           =       0.035 (     0.000 CPU time)
Time spent in evaluations (secs)    =       0.000

===============================================================================

Locally optimal or satisfactory solution.
objective 951; feasibility error 7.11e-15
9 iterations; 0 function evaluations

suffix feaserror OUT;
suffix opterror OUT;
suffix numfcevals OUT;
suffix numiters OUT;
x[1].feaserror = 0

c1.opterror = 0

obj.numfcevals = 12

obj.feaserror = 7.10543e-15

obj.opterror = 3.84018e-09

Nonlinear Least Squares

In some cases it may be more efficient to use the specialized Knitro API for nonlinear least-squares (see Least squares problems), which internally applies the Gauss-Newton Hessian, to solve a least-squares model formulated in AMPL. In particular this may be useful if the exact Hessian computed by AMPL is expensive. You can apply this specialized interface through AMPL by following these steps:

  • Set the objective function to 0

  • Specify each residual function as an equality constraint

  • Turn the AMPL presolver off by setting

option presolve 0;
  • Tell Knitro to apply the least-squares interface and disable presolve by setting

option knitro_options "leastsquares=1 presolve=0";

Below is an example of how to solve nonlinear least-squares problems in AMPL:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
###########################################################
####              LSQ in AMPL with Knitro              ####
####                                                   ####
#### This example illustrates how to optimize least    ####
#### squares problems in AMPL by formulating it using  ####
#### AMPL syntax and also using Knitro least squares   ####
#### dedicated API.                                    ####
###########################################################

# Reset AMPL
reset;

# Reset initial guesses between consecutive runs
option reset_initial_guesses 1;

# Reinitialize random seed for generating same values over runs
option randseed 1;

### The first part of the example will demonstrate how to formulate a
### least squares problem in AMPL using usual AMPL syntax.
### Also, we will illustrate an AMPL trick to improve performances.

# We use a large number to demonstrate the AMPL expansion trick
param M := 1000000;

# Create random values for the "estimates"
param alpha{1..M};
let{i in 1..M} alpha[i] := Uniform01();

# Variable: minimize the sum of squares of the distance between var_alpha
# and the "estimates"
var var_alpha;

### 1. Straightforward least squares formulation with no expansion ###

## Straightforward least square problem.
## The objective is expressed directly, without expanding the square terms.
minimize obj_no_expand:
    0.5 * sum{i in 1..M} (alpha[i]-var_alpha)^2;

# Optimize non-expanded problem
solve obj_no_expand;


### 2. Least squares with square terms expansion ###

## Same problem but this time the objective is expanded.
## Notice that, using this trick, the runtime decreases significantly.
minimize obj_expanded:
    0.5 * (
        M * var_alpha^2 -
        2 * var_alpha * ( sum{i in 1..M} alpha[i] ) +
        sum{i in 1..M} alpha[i]^2
    );

# Optimize expanded problem
solve obj_expanded;

# Check objective value
display obj_expanded - obj_no_expand;


### 3. Least squares using Knitro LSQ API ###

# Set Ampl and Knitro options
option presolve 0; # disable AMPL presolve, this is mandatory!
option knitro_options "leastsquares=1 presolve=0"; # Enable Knitro LSQ

## Same problem but this time based on Knitro's least-squares API.
# Objective must be constant
minimize obj_lsq: 0;

# Each residual is a constraint: residual = 0
# s.t. res{i in 1..M}:(alpha[i]-var_alpha)^2 = 0;
s.t. res{i in 1..M}:
    alpha[i] - var_alpha = 0;

# Optimize problem using on Knitro LSQ API
solve obj_lsq;

Below is the corresponding (filtered) output:

[...]

  Iter      Objective      FeasError   OptError    ||Step||    CGits
--------  --------------  ----------  ----------  ----------  -------
       0   1.665516e+005  0.000e+000
       1   4.168899e+004  0.000e+000  2.754e-013  4.997e-001        0

EXIT: Locally optimal solution found.

Final Statistics
----------------
Final objective value               =  4.16889869527361e+004
Final feasibility error (abs / rel) =   0.00e+000 / 0.00e+000
Final optimality error  (abs / rel) =   2.75e-013 / 3.30e-014
# of iterations                     =          1
# of CG iterations                  =          0
# of function evaluations           =          4
# of gradient evaluations           =          3
# of Hessian evaluations            =          1
Total program time (secs)           =       0.452 (     0.453 CPU time)
Time spent in evaluations (secs)    =       0.274

===============================================================================

[...]

  Iter      Objective      FeasError   OptError    ||Step||    CGits
--------  --------------  ----------  ----------  ----------  -------
       0   1.665516e+005  0.000e+000
       1   4.168899e+004  0.000e+000  0.000e+000  4.997e-001        0

EXIT: Locally optimal solution found.

Final Statistics
----------------
Final objective value               =  4.16889869527314e+004
Final feasibility error (abs / rel) =   0.00e+000 / 0.00e+000
Final optimality error  (abs / rel) =   0.00e+000 / 0.00e+000
# of iterations                     =          1
# of CG iterations                  =          0
# of function evaluations           =          4
# of gradient evaluations           =          3
# of Hessian evaluations            =          1
Total program time (secs)           =       0.002 (     0.000 CPU time)
Time spent in evaluations (secs)    =       0.000

===============================================================================

[...]

  Iter      Objective      FeasError   OptError    ||Step||    CGits
--------  --------------  ----------  ----------  ----------  -------
       0   1.665516e+005  0.000e+000
       1   4.168899e+004  0.000e+000  1.376e-009  4.997e-001        0

EXIT: Locally optimal solution found.

Final Statistics
----------------
Final objective value               =  4.16889869527361e+004
Final feasibility error (abs / rel) =   0.00e+000 / 0.00e+000
Final optimality error  (abs / rel) =   1.38e-009 / 3.30e-014
# of iterations                     =          1
# of CG iterations                  =          0
# of residual evaluations           =          4
# of Jacobian evaluations           =          2
Total program time (secs)           =       0.301 (     0.500 CPU time)
Time spent in evaluations (secs)    =       0.163