highs-js API reference
    Preparing search index...

    Interface SparseMatrixInput

    Constraint matrix in compressed sparse column (CSC) or compressed sparse row (CSR) form.

    format chooses the major axis. With "csc", each packed segment is one column and indices contains row indices. With "csr", each segment is one row and indices contains column indices. Define majorDimension = format === "csc" ? numCols : numRows. The arrays must obey:

    • starts.length === majorDimension + 1
    • starts[0] === 0
    • starts is nondecreasing
    • starts[majorDimension] === indices.length === values.length
    • every minor index is in the opposite matrix dimension
    • a packed row or column contains no duplicate minor index

    For example, the matrix [[1, 0], [2, 3]] is CSC-encoded as starts: [0, 2, 3], indices: [0, 1, 1], values: [1, 2, 3]. Explicit zeros and coefficients at or below HiGHS' small-matrix threshold may be removed. All arrays are copied before the call returns.

    interface SparseMatrixInput {
        format: MatrixFormat;
        indices: IndexInput;
        numCols: number;
        numRows: number;
        starts: IndexInput;
        values: NumberInput;
    }
    Index
    format: MatrixFormat

    Chooses how the one-dimensional arrays encode the two-dimensional matrix.

    • "csc" (compressed sparse column): coefficients are grouped by column. starts[j]..starts[j + 1] locates column j, and each corresponding indices[k] is a row index.
    • "csr" (compressed sparse row): coefficients are grouped by row. starts[i]..starts[i + 1] locates row i, and each corresponding indices[k] is a column index.

    This changes the meanings and required length of both starts and indices; it does not transpose the mathematical matrix. Use "csc" when constructing columns naturally and "csr" when constructing rows naturally.

    indices: IndexInput

    Minor-axis coordinate for every packed coefficient in values. indices[k] and values[k] always describe the same matrix entry.

    In CSC, packed position k belongs to the column determined by starts, and indices[k] is its zero-based row. In CSR, position k belongs to the row determined by starts, and indices[k] is its zero-based column. Consequently CSC indices must be below numRows, while CSR indices must be below numCols.

    indices.length must equal values.length and the final starts entry. A single packed row/column must not repeat a minor index, because that would specify the same matrix coordinate twice. Indices in different packed rows/columns may naturally repeat.

    For CSC starts: [0, 2, 3], indices: [0, 1, 1] means column 0 has entries in rows 0 and 1, while column 1 has one entry in row 1.

    numCols: number

    Number of columns in the mathematical matrix. It must be a non-negative signed 32-bit integer.

    In CSR format, every entry of indices is a column index and must satisfy 0 <= indices[k] < numCols. In CSC format, this is the number of packed column segments, so starts.length must equal numCols + 1.

    numRows: number

    Number of rows in the mathematical matrix. It must be a non-negative signed 32-bit integer.

    In CSC format, every entry of indices is a row index and must satisfy 0 <= indices[k] < numRows. In CSR format, this is the number of packed row segments, so starts.length must equal numRows + 1.

    starts: IndexInput

    Boundaries of the packed rows or columns inside indices and values. These are offsets, not model row/column indices.

    In CSC, column j occupies positions k from starts[j] inclusive to starts[j + 1] exclusive. In CSR, the same formula describes row j. Therefore an empty row/column has equal adjacent offsets.

    The array must have numCols + 1 entries for CSC or numRows + 1 entries for CSR. It must start with 0, be nondecreasing, and end with the exact number of stored entries: starts[starts.length - 1] === indices.length === values.length.

    Example: starts: [0, 2, 2, 3] describes three major-axis items. The first has two entries at packed positions 0 and 1, the second is empty, and the third has one entry at position 2.

    values: NumberInput

    Numerical matrix coefficient at every packed position. values[k] is at the minor coordinate indices[k] within the row/column selected by starts; all three arrays must therefore be interpreted together.

    values.length must equal indices.length and the final starts entry. Values must be numbers other than NaN; matrix coefficients should be finite rather than using infinity to represent a bound. Explicit zero and coefficients whose magnitude is at or below small_matrix_value may be removed by HiGHS, so the later extracted matrix can contain fewer entries.

    For the CSC encoding starts: [0, 2, 3], indices: [0, 1, 1], and values: [1, 2, 3], the stored coordinates are (row 0, col 0) = 1, (row 1, col 0) = 2, and (row 1, col 1) = 3.