# Obtaining information

In addition to the Knitro log that is printed on screen, information about the computation performed by Knitro is available in the form of various function calls. This section explains how this information can be retrieved and interpreted.

## Knitro output for continuous problems

This section describes Knitro outputs at various levels
for continuous problems. We examine the output that results from running
`examples/C/callbackExample2.c`

with full output to solve `problemHS15.c`

.

Note

If `outlev=0`

then all printing of output is suppressed.
If `outlev`

is positive, then Knitro prints
information about the solution of your optimization problem either to
standard output (`outmode`

= *screen*), to a file named
`knitro.log`

(`outmode`

= *file*), or to
both (`outmode`

= *both*).
The option `outdir`

controls the directory where output files are
created (if any are) and the option `outappend`

controls whether
output is appended to existing files.

Display of Nondefault Options

Knitro first prints the banner displaying the Artelys license type
and version of Knitro that is installed.
It then lists all user options which are different from their default values
If nothing is listed in this section then it must be that all user options
are set to their default values.
Lastly, Knitro prints messages that describe how it resolved user
options that were set to automatic values.
For example, if option `algorithm`

= *auto*, then Knitro
prints the algorithm that it chooses.

```
=======================================
Commercial License
Artelys Knitro 10.0.0
=======================================
Knitro presolve eliminated 0 variables and 0 constraints.
hessian_no_f: 1
outlev: 6
Knitro changing algorithm from AUTO to 1.
Knitro changing bar_initpt from AUTO to 3.
Knitro changing bar_murule from AUTO to 4.
Knitro changing bar_penaltycons from AUTO to 1.
Knitro changing bar_penaltyrule from AUTO to 2.
Knitro changing bar_switchrule from AUTO to 2.
Knitro changing linsolver from AUTO to 2.
```

In the example above, it is indicated that we are using a more verbose
output level (`outlev`

= 6) instead of the default value
(`outlev`

= 2).
Knitro chose algorithm 1 (Interior/Direct), and then automatically
determined some other options related to the algorithm.

Display of problem characteristics

Knitro next prints a summary description of the problem characteristics including the number and type of variables and constraints and the number of nonzero elements in the Jacobian matrix and Hessian matrix. If the Knitro presolver is enabled, then information about the presolved form of the problem is printed as well.

```
Problem Characteristics ( Presolved)
-----------------------
Objective goal: Minimize
Number of variables: 2 ( 2)
bounded below: 0 ( 0)
bounded above: 1 ( 1)
bounded below and above: 0 ( 0)
fixed: 0 ( 0)
free: 1 ( 1)
Number of constraints: 2 ( 2)
linear equalities: 0 ( 0)
nonlinear equalities: 0 ( 0)
linear inequalities: 0 ( 0)
nonlinear inequalities: 2 ( 2)
range: 0 ( 0)
Number of nonzeros in Jacobian: 4 ( 4)
Number of nonzeros in Hessian: 3 ( 3)
```

Display of Iteration Information

Next, if `outlev`

is greater than 2, Knitro prints
columns of data reflecting detailed information about individual
iterations during the solution process.
An iteration is defined as a step
which generates a new solution estimate (i.e., a successful step).

If `outlev`

= 2, summary data is printed every 10
iterations, and on the final iteration. If
`outlev`

= 3, summary data is printed every
iteration. If `outlev`

= 4, the most verbose
iteration information is printed every iteration.

```
Iter fCount Objective FeasError OptError ||Step|| CGits
-------- -------- -------------- ---------- ---------- ---------- -------
0 2 9.090000e+02 3.000e+00
1 3 7.992179e+02 2.859e+00 2.191e+01 7.245e-02 0
2 4 1.865455e+01 9.076e-01 3.917e+01 2.197e+00 0
3 12 3.211028e+02 8.846e-01 6.751e+00 1.336e+00 8
4 13 1.437527e+01 5.021e-01 6.570e-01 1.162e+00 2
5 14 3.543851e+01 3.873e-01 3.873e-01 2.008e-01 0
6 15 1.144533e+02 2.197e-01 5.820e-01 4.076e-01 0
7 16 2.342032e+02 7.408e-02 7.408e-02 4.123e-01 0
8 17 3.011424e+02 6.019e-03 3.302e-02 1.904e-01 0
9 18 3.064931e+02 9.852e-06 1.490e-04 1.470e-02 0
10 19 3.065000e+02 0.000e+00 7.038e-10 1.970e-05 0
```

The meaning of each column is described below.

**Iter**: iteration number.**fCount**: the cumulative number of function evalutions. (This information is only printed if`outlev`

is greater than 3).**Objective**: the value of the objective function at the current iterate.**FeasError**: a measure of the feasibility violation at the current iterate**OptError**: a measure of the violation of the Karush-Kuhn-Tucker (KKT) (first-order) optimality conditions (not including feasibility) at the current iterate.**Step**: the 2-norm length of the step (i.e., the distance between the new iterate and the previous iterate).**CGits**: the number of Projected Conjugate Gradient (CG) iterations required to compute the step.

Display of termination status

At the end of the run a termination message is printed indicating whether or not the optimal solution was found and if not, why Knitro stopped. The termination message typically starts with the word “EXIT”. If Knitro was successful in satisfying the termination test, the message will look as follows:

```
EXIT: Locally optimal solution found.
```

Display of Final Statistics

Following the termination message, a summary of some final statistics on the run are printed. Both relative and absolute error values are printed.

```
Final Statistics
----------------
Final objective value = 3.06500000082417e+02
Final feasibility error (abs / rel) = 0.00e+00 / 0.00e+00
Final optimality error (abs / rel) = 7.04e-10 / 4.82e-11
# of iterations = 10
# of CG iterations = 10
# of function evaluations = 19
# of gradient evaluations = 12
# of Hessian evaluations = 10
Total program time (secs) = 0.00390 ( 0.002 CPU time)
Time spent in evaluations (secs) = 0.00001
```

Display of solution vector and constraints

If `outlev`

equals 5 or 6, the values of the solution vector are printed
after the final statistics. If `outlev`

equals 6, the final constraint
values are also printed, and the values of the
Lagrange multipliers (or dual variables) are printed next to their corresponding
constraint or bound.

```
Constraint Vector Lagrange Multipliers
----------------- ---------------------
c[ 0] = 1.00000000001e+00, lambda[ 0] = -7.00000000020e+02
c[ 1] = 4.50000000072e+00, lambda[ 1] = -1.69345778120e-08
Solution Vector
---------------
x[ 0] = 4.99999999956e-01, lambda[ 2] = 1.75099999991e+03
x[ 1] = 2.00000000019e+00, lambda[ 3] = 0.00000000000e+00
```

Debugging / profiling information

Knitro can produce
additional information which may be useful in debugging or analyzing
performance. If `outlev`

is positive and
`debug`

= 1, then multiple files named `kdbg_*.log`

are
created which contain detailed information on performance.
If `outlev`

is positive and `debug`

= 2,
then Knitro prints information useful for debugging program execution.
The information produced by `debug`

is primarily intended for developers, and should not be
used in a production setting.

Intermediate iterates

Users can generate a file containing iterates and/or solution points
with option `newpoint`

. The output file is called
`knitro_newpoint.log`

.

## Knitro output for discrete problems

This section describes Knitro outputs at various levels
for discrete or mixed integer problems. We examine the output
that results from running `examples/C/callbackMINLP_static`

to
solve `problemMINLP.c`

.

Note

When `outlev`

is positive, the options `mip_outlevel`

,
`mip_debug`

, `mip_outinterval`

and
`mip_outsub`

control the
amount and type of MIP output generated as described below.

Knitro first prints the banner displaying the license type
and version of Knitro that is installed.
It then lists all user options which are different from their default values.
If nothing is listed in this section then it must be that all user options
are set to their default values.
Lastly, Knitro prints messages that describe how it resolved user
options that were set to automatic values. For example, if
option `mip_branchrule`

= *auto*,
then Knitro prints the branching rule that it chooses.

```
=======================================
Commercial License
Artelys Knitro 10.0.0
=======================================
mip_method: 1
mip_outinterval: 1
Knitro changing mip_rootalg from AUTO to 1.
Knitro changing mip_lpalg from AUTO to 3.
Knitro changing mip_branchrule from AUTO to 2.
Knitro changing mip_selectrule from AUTO to 2.
Knitro changing mip_rounding from AUTO to 3.
Knitro changing mip_heuristic from AUTO to 1.
Knitro changing mip_pseudoinit from AUTO to 1.
```

In the example above, it is indicated that we are using
`mip_method`

= 1 which is the standard branch and bound method,
and that we are printing output
information at every node since `mip_outinterval`

= 1.
It then determined seven other options related to the MIP method.

Display of Problem Characteristics

Knitro next prints a summary description of the problem characteristics including the number and type of variables and constraints and the number of nonzero elements in the Jacobian matrix and Hessian matrix (if providing the exact Hessian).

If no initial point is provided by the user, Knitro indicates that it is computing one. Knitro also prints the results of any MIP preprocessing to detect special structure and indicates which MIP method it is using.

```
Problem Characteristics
-----------------------
Objective goal: Minimize
Number of variables: 6
bounded below: 0
bounded above: 0
bounded below and above: 6
fixed: 0
free: 0
Number of binary variables: 3
Number of integer variables: 0
Number of constraints: 6
linear equalities: 0
nonlinear equalities: 0
linear inequalities: 4
nonlinear inequalities: 2
range: 0
Number of nonzeros in Jacobian: 16
Number of nonzeros in Hessian: 3
No start point provided -- Knitro computing one.
Knitro detected 1 GUB constraints
Knitro derived 0 knapsack covers after examining 3 constraints
Knitro solving root node relaxation
Knitro MIP using Branch and Bound method
```

Display of Node Information

Next, if `mip_outlevel`

= 1, Knitro prints
columns of data reflecting detailed information about individual
nodes during the solution process.
If `mip_outlevel`

= 2, the accumulated time is printed at
each node also.
The frequency of this node
information is controlled by the `mip_outinterval`

parameter.
For example, if `mip_outinterval`

= 100, this node information
is printed only for every 100th node (printing output less
frequently may save significant CPU time in some cases). In the example
below, `mip_outinterval`

= 1, so information about every node is
printed (without the accumulated time).

```
Node Left Iinf Objective Best relaxatn Best incumbent
------ ------ ------ -------------- -------------- --------------
1 0 2 7.592845e-01 7.592845e-01
2 1 1 5.171320e+00 7.592845e-01
* 2 1 r 7.671320e+00
* 3 2 0 6.009759e+00 f 5.171320e+00 6.009759e+00
4 1 1.000000e+01 pr 5.171320e+00 6.009759e+00
5 0 7.092732e+00 pr 6.009759e+00 6.009759e+00
```

The meaning of each column is described below.

**Node:**the node number. If an integer feasible point was found at a given node, then it is marked with a star (*).**Left:**the current number of active nodes left in the branch and bound tree.**Iinf:**the number of integer infeasible variables at the current node solution.**Objective:**the value of the objective function at the solution of the relaxed subproblem solved at the current node. If the subproblem was infeasible or failed, this is indicated. Additional symbols may be printed at some nodes if the node was pruned (*pr*), integer feasible (*f*), or an integer feasible point was found through rounding (*r*).**Best relaxatn:**the value of the current best relaxation (lower bound on the solution if minimizing).**Best incumbent:**the value of the current best integer feasible point (upper bound on the solution if minimizing).

Display of Termination Status

At the end of the run a termination message is printed indicating whether or not the optimal solution was found and if not, why Knitro stopped. The termination message typically starts with the word “EXIT”. If Knitro was successful in satisfying the termination test, the message will look as follows:

```
EXIT: Optimal solution found.
```

See the reference manual (Return codes) for a list of possible termination
messages and a description of their meaning and the corresponding
value returned by `KTR_mip_solve()`

.

Display of Final Statistics

Following the termination message, a summary of some final statistics on the run are printed.

```
Final Statistics for MIP
------------------------
Final objective value = 6.00975890892825e+00
Final integrality gap (abs / rel) = 0.00e+00 / 0.00e+00 (0.00%)
# of nodes processed = 5
# of subproblems solved = 6
Total program time (secs) = 0.09930 (0.099 CPU time)
Time spent in evaluations (secs) = 0.00117
```

Display of Solution Vector and Constraints

If `outlev`

equals 5 or 6, the values of the solution vector are printed
after the final statistics. If `outlev`

equals 6, the constraint values
at the solution are also printed.

```
Solution Vector
---------------
x[0] = 1.30097589089e+00
x[1] = 0.00000000000e+00
x[2] = 1.00000000000e+00
x[3] = 0.00000000000e+00 (binary variable)
x[4] = 1.00000000000e+00 (binary variable)
x[5] = 0.00000000000e+00 (binary variable)
```

Knitro can produce
additional information which may be useful in debugging or analyzing
MIP performance. If `outlev`

is positive and
`mip_debug`

= 1, then the file named `kdbg_mip.log`

is
created which contains detailed information on the MIP performance.
In addition, if `mip_outsub`

= 1, this file will contain
extensive output for each subproblem solve in the MIP solution process.
The information produced by `mip_debug`

is primarily intended for developers, and should not be
used in a production setting.

## Getting information programmatically in callable library

Important solution information from Knitro is either made
available as output from the call to `KTR_solve()`

or `KTR_mip_solve()`

,
or can be retrieved through special function calls.

The `KTR_solve()`

and `KTR_mip_solve()`

functions return the
final value of the objective function in *obj*, the final (primal)
solution vector in the array *x* and the final values of the
Lagrange multipliers (or dual variables) in the array *lambda*.
The solution status code is given by the return value from
`KTR_solve()`

or `KTR_mip_solve()`

.

In addition, information related to the final statistics can be retrieved through the following function calls. The precise meaning of each option is described in the reference manual (Knitro user options).

```
int KTR_get_number_FC_evals (const KTR_context_ptr kc);
int KTR_get_number_GA_evals (const KTR_context_ptr kc);
int KTR_get_number_H_evals (const KTR_context_ptr kc);
int KTR_get_number_HV_evals (const KTR_context_ptr kc);
int KTR_get_solution (const KTR_context_ptr kc,
int * const status,
double * const obj,
double * const x,
double * const lambda);
int KTR_get_constraint_values (const KTR_context_ptr kc, double * const c);
```

Continuous problems

```
int KTR_get_number_iters (const KTR_context_ptr kc);
int KTR_get_number_cg_iters (const KTR_context_ptr kc);
double KTR_get_abs_feas_error (const KTR_context_ptr kc);
double KTR_get_rel_feas_error (const KTR_context_ptr kc);
double KTR_get_abs_opt_error (const KTR_context_ptr kc);
double KTR_get_rel_opt_error (const KTR_context_ptr kc);
int KTR_get_objgrad_values (const KTR_context_ptr kc, double * const objGrad);
int KTR_get_jacobian_values (const KTR_context_ptr kc, double * const jac);
int KTR_get_hessian_values (const KTR_context_ptr kc, double * const hess);
```

Discrete or mixed integer problems

```
int KTR_get_mip_num_nodes (const KTR_context_ptr kc);
int KTR_get_mip_num_solves (const KTR_context_ptr kc);
double KTR_get_mip_abs_gap (const KTR_context_ptr kc);
double KTR_get_mip_rel_gap (const KTR_context_ptr kc);
double KTR_get_mip_incumbent_obj (const KTR_context_ptr kc);
int KTR_get_mip_incumbent_x (const KTR_context_ptr kc, double * const x);
double KTR_get_mip_relaxation_bnd (const KTR_context_ptr kc);
double KTR_get_mip_lastnode_obj (const KTR_context_ptr kc);
```

## Getting information programmatically in the object-oriented interface

Solution information can be retrieved after a call to
`KTRSolver::solve()`

. After `solve()`

is called, `KTRSolver::getObj()`

returns the objective function value, and `KTRSolver::getXValues()`

and `KTRSolver::getLambdaValues()`

return the final primal and
and dual variable values, respectively. The solution status code
is returned by `KTRSolver::solve()`

method.

In addition, information related to the final statistics can be
retrieved through the following `KTRSolver`

methods.
The precise meaning of each option is described in the reference manual
(Knitro user options).

```
int KTRSolver::getNumberFCEvals();
int KTRSolver::getNumberGAEvals();
int KTRSolver::getNumberHEvals();
int KTRSolver::getNumberHVEvals();
std::vector<double> KTRSolver::getConstraintValues();
```

Continuous problems

```
int KTRSolver::getNumberIters();
int KTRSolver::getNumberCGIters();
double KTRSolver::getAbsFeasError();
double KTRSolver::getRelFeasError();
double KTRSolver::getAbsOptError();
double KTRSolver::getRelOptError();
std::vector<double> KTRSolver::getObjgradValues();
std::vector<double> KTRSolver::getJacobianValues();
std::vector<double> KTRSolver::getHessianValues();
```

Discrete or mixed integer problems

```
int KTRSolver::getMipNumNodes();
int KTRSolver::getMipNumSolves();
double KTRSolver::getMipAbsGap();
double KTRSolver::getMipRelGap();
double KTRSolver::getMipIncumbentObj();
std::vector<double> KTRSolver::getMipIncumbentX );
double KTRSolver::getMipRelaxationBnd();
double KTRSolver::getMipLastnodeObj();
```

## User-defined names in Knitro output

By default Knitro uses *x* for variable names and *c* for constraint names
in the output. However, the user can define more meaningful and customized names
for the objective function, the variables and the constraint functions through the
the API function `KTR_set_names()`

when using the callable library API.

When using the AMPL modeling language, you can have Knitro output objective function, variable and constraint names specified in the AMPL model by issuing the following command in the AMPL session:

```
option knitroampl_auxfiles rc;
```

## Suppressing all output in AMPL

Even when setting the options:

```
ampl: option solver_msg 0;
ampl: option knitro_options "outlev=0";
```

in an AMPL session, AMPL will still print some basic information like the solver name and non-default user option settings to the screen. In order to suppress all AMPL and Knitro output you must change your AMPL solve commands to something like:

```
ampl: solve >scratch-file;
```

where scratch-file is the name of some temporary file where the unwanted output can be sent. Under Unix, “solve >/dev/null” automatically throws away the unwanted output and under Windows, “solve > NUL” does the same.

## AMPL solution information through suffixes

Some Knitro solution information can be retrieved and displayed through AMPL
using AMPL suffixes defined for Knitro (see AMPL suffixes defined for Knitro). In particular, when solving a MIP
using Knitro/AMPL, the best relaxation bound and the incumbent solution
can be displayed using the *relaxbnd* and *incumbent* suffixes. For example,
if the objective function is named *obj*, then:

```
ampl: display obj.relaxbnd;
```

give the current relaxation bound and:

```
ampl: display obj.incumbent;
```

will give the current incumbent solution (if one exists).

## AMPL presolve

AMPL will often perform a reordering of the variables and constraints defined in the AMPL model. The AMPL presolver may also simplify the form of the problem by eliminating certain variables or constraints. The output printed by Knitro corresponds to the reordered, reformulated problem. To view final variable and constraint values in the original AMPL model, use the AMPL display command after Knitro has completed solving the problem.

It is possible to correlate Knitro variables and constraints with the original AMPL model. You must type an extra command in the AMPL session:

```
option knitroampl_auxfiles rc;
```

and set Knitro option `presolve_dbg`

= 2. Then the solver will
print the variables and constraints that Knitro receives, with their
upper and lower bounds, and their AMPL model names. The extra AMPL command
causes the model names to be passed to the Knitro/AMPL solver.

The output below is obtained with the
example file `testproblem.mod`

supplied with the distribution.
The center column of variable and constraint names are those used by
Knitro, while the names in the right-hand column are from the AMPL model:

```
ampl: model testproblem.mod;
ampl: option solver knitroampl;
ampl: option knitroampl_auxfiles rc;
ampl: option knitro_options "presolve_dbg=2 outlev=0";
Knitro 10.0.0: presolve_dbg=2
outlev=0
----- AMPL problem for Knitro -----
Objective name: obj
0.000000e+00 <= x[ 0] <= 1.000000e+20 x[1]
0.000000e+00 <= x[ 1] <= 1.000000e+20 x[2]
0.000000e+00 <= x[ 2] <= 1.000000e+20 x[3]
2.500000e+01 <= c[ 0] <= 1.000000e+20 c2 (general)
5.600000e+01 <= c[ 1] <= 5.600000e+01 c1 (linear)
-----------------------------------
Knitro 10.0.0: Locally optimal or satisfactory solution.
objective 935.9999978; feasibility error 6.74e-08
5 iterations; 7 function evaluations
```