Knitro solution files (.knsol)
Overview
The file is divided into several sections, each serving a specific purpose in describing the solution of an optimization problem. All data is represented in plain text and follows a simple key-value structure.
Solution files can be read and written using KN_read_solution() and KN_write_solution().
See Reading model/solution properties for the full API documentation.
File Sections
Info
The Info section contains various key performance indicators (KPIs) or diagnostic metrics related to the solution process.
This section is intended only for debugging and is not parsed by solution readers.
[Info]
iteration = 12
objective = 123.0
objgoal = min
Primals
The Primals section lists the variable names and their corresponding values in solution.
[Primals]
x1 = 1.5
x2 = 0.0
y = 2.75
Duals.Constraints
The Duals.Constraints section contains the names of constraints and their associated Lagrange multiplier values.
This section is only present in continuous optimization problems (e.g., LPs, QPs, NLPs).
[Duals.Constraints]
constraint_1 = 0.0
balance_constraint = -1.2
Duals.Variables
The Duals.Variables section provides Lagrange multipliers associated with variable bounds (dual values for bound constraints).
Like the previous section, it appears only in continuous problem solves.
[Duals.variables]
x1 = 0.0
x2 = -0.05
y = 3.32
Format specifications
The Knitro solution file is inspired from the standard INI file format (see the INI file format on Wikipedia).
The following conventions are used:
Section names must be enclosed in square brackets (e.g.
[info]). Section name comparisons are case-insensitive. Sections can appear in any order.Each line contains one key-value pair formatted as
key = value. Any number of spaces may appear around the=character.Lines starting with
#or;are treated as comments and ignored by parsers.Variable and constraint names can not contain the
=character, and can not start with#or;to avoid confusion with commented lines. However, they can contain any other characters.Empty lines are permitted and ignored.
Example of syntax:
# Example of valid formatting
[Info]
iteration = 12
objective = 123.0
objgoal = min
; This is another style of comment
[Primals]
x1 = 3.14 ; This is an inline comment
x2=0.0 # This is another inline comment
Parsing rules and error handling
When parsing a solution file, the following rules apply to variable and constraint names:
Duplicate names will return an error.
Unknown names (not recognized by the context) are skipped: a warning is issued, but no error is returned and parsing continues normally.
Missing names are allowed: the file is still parsed even if some variables or constraints are absent, enabling users to provide partial solution files that specify only a subset of variables or constraints.
Unnamed variables or constraints (when the Knitro context has no names) are automatically assigned default names:
x0,x1, etc. for variables, andc0,c1, etc. for constraints, in the order they are defined in the model.