Loading a model
The simplest way to use HiGHS to solve a model is to load it from a file using the method readModel. Different file formats are recognised from the filename extension. HiGHS can read plain text MPS files and (CPLEX) LP files. In general, HiGHS can read compressed files.
Alternatively, data generated by an application can be passed to HiGHS via an instance of the HighsLp class populated by the user and passed using the method passModel. In languages where such structures cannot be used, data constituting an LP model can be passed via individual parameters.
Building a model
The model in HiGHS can be built using a sequence of calls to add variables and constraints. This is most easily done one-by-one using the methods addCol and addRow. Alterntively, addVar and addRow can be used, with changeColCost used to define each objective coefficient.
Addition of multiple variables and constraints can be achieved using addVars and addRows, with changeColsCost used to define objective coefficients. Note that defining the model in this way requires vectors of data and the specification of constraint coefficients as compressed row-wise or column-wise matrices.
Solving a model
The incumbent model in HiGHS is solved by a call to the method run. Where possible, HiGHS will hot start the solver using solution information obtained on previous runs, or supplied by the user.
Model and solution management
HiGHS has comprehensive tools for defining and extracting models. This can be done either to/from MPS or (CPLEX) format LP files, or via method calls. HiGHS also has methods that permit the incumbent model to be modified. Solutions can be supplied and extracted using either files or method calls.
Solving a model
HiGHS is used to solve a model by calling the method run. By default, HiGHS minimizes the model's objective function.
Extracting the results
After solving a model, its status is the value returnedby the method getModelStatus. This value is of type HighsModelStatus, and may be interpreted via the names in the corresponding enum. The objective function value and iteration count are obtained using the methods getObjectiveValue and getIterationCount. The solution and basis are returned by the methods getSolution and getBasis respectively. Note that these are const references to internal data. HiGHS can also be used to write the solution to a file using the method writeSolution, with the output going to stdout if the filename is blank.
Option values
The option values that control HiGHS are of type string, bool, int and double. Options are referred to by a string identical to the name of their identifier. A full specification of the options is given here. An option value is changed by passing its name and value to the method setHighsOptionValue. This returns a HighsStatus error if the name is unrecognised or the value is illegal. The current value of an option is obtained by passing its name to the method getHighsOptionValue.
Extracting model data
The numbers of column, rows and nonzeros in the model are returned by the methods getNumCols, getNumRows and getNumEntries respectively. Data for columns and rows from the model may be extracted using the methods getCols and getRows, and specific matrix coefficients obtained using the method getCoeff.
Modifying a model
The most immediate model modification is to change the sense of the objective. By default, HiGHS minimizes the model's objective function. The objective sense can be set to minimize (maximize) by passing the value 1 (-1) to the method changeObjectiveSense. The cost coefficient or bounds of a column are changed by passing its index and new value(s) to the methods changeColCost, changeColBounds. The corresponding method for a row is changeRowBounds.
For the convenience of application developers, data for multiple columns and rows can be changed in three different ways in HiGHS. This is introduced in the case of column costs. The columns can be defined by the first and last indices of the interval of columns whose costs will be changed, together with the corresponding values. When costs for a non-contiguous set of columns are changed, they may be specified as a set of indices (which need not be ordered), the number of entries in the set and the corresponding values. Alternatively, the columns to be changed (not changed) may be specified by setting values of +1 (0) in an integer mask of dimension equal to the number of columns, together with a full-length vector of values. In all three cases, the method used is called changeColsCosts. The bounds of multiple columns or rows are changed using the methods changeColsBounds or changeRowsBounds respectively.
An individual matrix coefficient is changed by passing its row index, column index and new value to changeCoeff.
To add a column or row to the model, pass the necessary data to the method addCol or addRow respectively. Multiple columns and rows can be added using the methods addCols or addRows.
Columns or rows can be deleted from the model using the methods deleteCols or deleteRows. As above, the columns or rows to be deleted may be specified as a contiguous interval, a set or via a mask. In the case of the latter, the new indices of any remaining columns or rows are returned in place of the entries of 0.
Other operations
To run HiGHS from a user-defined solution or basis, this is passed to HiGHS using the methods setSolution or setBasis.
HiGHS has a suite of methods for operations with the invertible representation of the current basis matrix $B$. To use these requires knowledge of the corresponding (ordered) basic variables. This is obtained using the method getBasicVariables, with non-negative values being columns and negative values corresponding to row indices plus one [so -1 indicates row 0]. Methods getBasisInverseRow and getBasisInverseRow yield a specific row or column of $B^{-1}$. Methods getBasisSolve and getBasisTransposeSolve yield the solution of $Bx=b$ and $Bx=b$ respectively. Finally, the methods getReducedRow and getReducedColumn yield a specific row or column of $B^{-1}A$. In all cases, HiGHS can return the number and indices of the nonzeros in the result.