Class QPConstraintMatrix

java.lang.Object
org.hipparchus.linear.AbstractRealMatrix
org.hipparchus.optim.nonlinear.vector.constrained.QPConstraintMatrix
All Implemented Interfaces:
AnyMatrix, RealLinearOperator, RealMatrix, Blendable<RealMatrix>

public final class QPConstraintMatrix extends AbstractRealMatrix
Read-only, zero-copy row-oriented view of all linear constraints of a QP.

The represented matrix has the form:

     A = [ Ae          ]
         [ Ai          ]
         [ Ab          ]
         [ -Ab         ]
 

where each constraint gradient is stored as a row. The class keeps only references to the original equality, inequality and bounded-constraint matrices. In particular, the upper-bound block -Ab is generated on demand and is never stored.

The global row ordering is:

  1. equality constraints,
  2. inequality constraints,
  3. lower bounded constraints,
  4. upper bounded constraints.

The matrix is intentionally read-only. Calling copy() creates a physical independent matrix, but normal solver operations such as getEntry(int, int), getRowVector(int) and operate(RealVector) do not materialize the global matrix.

  • Constructor Details

    • QPConstraintMatrix

      public QPConstraintMatrix(int variableCount, RealMatrix equalityMatrix, RealMatrix inequalityMatrix, RealMatrix boundedMatrix)
      Build a row-oriented virtual QP constraint matrix.
      Parameters:
      variableCount - number of primal variables
      equalityMatrix - equality matrix, or null
      inequalityMatrix - inequality matrix, or null
      boundedMatrix - bounded-expression matrix, or null
  • Method Details

    • getRowDimension

      public int getRowDimension()
      Returns the number of rows of this matrix.
      Specified by:
      getRowDimension in interface AnyMatrix
      Specified by:
      getRowDimension in interface RealLinearOperator
      Specified by:
      getRowDimension in class AbstractRealMatrix
      Returns:
      the number of rows.
    • getColumnDimension

      public int getColumnDimension()
      Returns the number of columns of this matrix.
      Specified by:
      getColumnDimension in interface AnyMatrix
      Specified by:
      getColumnDimension in interface RealLinearOperator
      Specified by:
      getColumnDimension in class AbstractRealMatrix
      Returns:
      the number of columns.
    • getEntry

      public double getEntry(int row, int column)
      Get a coefficient without constructing the global matrix.
      Specified by:
      getEntry in interface RealMatrix
      Specified by:
      getEntry in class AbstractRealMatrix
      Parameters:
      row - global constraint index
      column - primal-variable index
      Returns:
      coefficient A[row, column]
    • getRowVector

      public RealVector getRowVector(int row)
      Get a constraint gradient as a row vector.

      The backing Hipparchus matrix already returns an independent vector. For an upper bound that same newly allocated vector is negated in place, avoiding an additional vector allocation.

      Specified by:
      getRowVector in interface RealMatrix
      Overrides:
      getRowVector in class AbstractRealMatrix
      Parameters:
      row - global constraint index
      Returns:
      constraint gradient
    • getRow

      public double[] getRow(int row)
      Get a constraint gradient as an array.
      Specified by:
      getRow in interface RealMatrix
      Overrides:
      getRow in class AbstractRealMatrix
      Parameters:
      row - global constraint index
      Returns:
      independent coefficient array
    • operate

      public RealVector operate(RealVector x)
      Evaluate all linear constraint expressions A x.

      Each physical backing block is multiplied only once. The product of the bounded matrix is reused for both the lower and upper blocks, with opposite signs.

      Specified by:
      operate in interface RealLinearOperator
      Specified by:
      operate in interface RealMatrix
      Overrides:
      operate in class AbstractRealMatrix
      Parameters:
      x - primal vector
      Returns:
      A x
    • setEntry

      public void setEntry(int row, int column, double value)
      This view is read-only.
      Specified by:
      setEntry in interface RealMatrix
      Specified by:
      setEntry in class AbstractRealMatrix
      Parameters:
      row - Row index of entry to be set.
      column - Column index of entry to be set.
      value - the new value of the entry.
    • createMatrix

      public RealMatrix createMatrix(int rowDimension, int columnDimension)
      Create an independent physical matrix for results of generic operations.
      Specified by:
      createMatrix in interface RealMatrix
      Specified by:
      createMatrix in class AbstractRealMatrix
      Parameters:
      rowDimension - the number of rows in the new matrix
      columnDimension - the number of columns in the new matrix
      Returns:
      a new matrix of the same type as the instance
    • copy

      public RealMatrix copy()
      Materialize an independent deep copy.
      Specified by:
      copy in interface RealMatrix
      Specified by:
      copy in class AbstractRealMatrix
      Returns:
      matrix copy