ilog.concert
Interface IloLPMatrix

All Superinterfaces:
IloAddable, IloConstraint, IloIntExpr, IloNumExpr

public interface IloLPMatrix
extends IloConstraint

An IloLPMatrix object allows you to treat a set of range constraints (instances of IloRange) and variables as a matrix. Objects of this class represent a set of linear constraints of the form L <= A x <= U, where L and U are vectors and A is a matrix. It allows you to directly edit A as a sparse matrix.

Every row of an IloLPMatrix corresponds to an instance of IloRange representing a linear constraint. Every column of this matrix is linked to an IloNumVar object. One IloNumVar object cannot be linked to more than one column of A. An IloRange object cannot be linked to more than one row of an IloLPMatrix. The rows of an LP matrix are referenced by integer values, called the row indices, ranging from 0 to getNrows()-1. Similarly, the columns of an LP matrix are referenced by integer values, called the column indices, ranging from 0 to getNcols()-1. Non-zero values in the LP matrix correspond to linear coefficients in the range constraints corresponding to its rows. For example a non-zero coefficient A[i][j] in row i and column j is equivalent to the linear coefficient for the variable corresponding to column j of the LP matrix in the expression of the range constraint corresponding to row i of the LP matrix.

                  Column indices
               0  1  2  ....  n-1
              +--+--+--+--+--+--+
    r i   0   |  |  |  |  |  |  | ----->   IloRange ra;
    o n       +--+--+--+--+--+--+
    w d   1   |  |  |  |  |  |  | ----->   IloRange rb;
      i       +--+--+--+--+--+--+
      c   .   |  |  |  |  |  |  |   .
      e   .   +--+--+--+--+--+--+   .
      s   .   |  |  |  |  |  |  |   .
              +--+--+--+--+--+--+
          m-1 |  |  |  |  |  |  | ----->   IloRange rc;
              +--+--+--+--+--+--+
               |  |           |
               |  |    ...    |
               |  |           |
               V  V           V
    IloNumVar  x, y,   ...    z;
  

IloLPMatrix objects are created by calling method IloMPModeler.LPMatrix() or IloMPModeler.addLPMatrix(). These methods create an empty IloLPMatrix object, that is, an LP matrix with 0 rows and 0 columns. The LP matrix can be populated using methods addRow(), addRows(), addColumn, and addCols.

See Also:
IloMPModeler.LPMatrix(), IloMPModeler.addLPMatrix()

Method Summary
 int addCols(ilog.concert.IloNumVar[] var)
          Adds new empty columns to LP matrix.
 int addCols(ilog.concert.IloNumVar[] var, int[][] indices, double[][] values)
          Adds new columns to the LP matrix.
 int addCols(ilog.concert.IloNumVar[] var, int start, int num)
          Adds new empty columns to LP matrix.
 int addColumn(ilog.concert.IloNumVar var)
          Adds a new empty column to an LP matrix.
 int addColumn(ilog.concert.IloNumVar var, int[] ind, double[] val)
          Adds a new column to an LP matrix.
 int addRow(double lb, double ub, int[] ind, double[] val)
          Adds a new row to the LP matrix.
 int addRow(ilog.concert.IloRange rng)
          Adds a range constraint as a new row to an LP matrix.
 int addRows(double[] lb, double[] ub, int[][] ind, double[][] val)
          Adds a set of new rows to LP matrix.
 int addRows(ilog.concert.IloRange[] rng)
          Adds range constraints as new rows to an LP matrix.
 int addRows(ilog.concert.IloRange[] rng, int start, int num)
          Adds a set of range constraints as new rows to an LP matrix.
 void clear()
          Removes all rows and columns from invoking LP matrix.
 void getCols(int begin, int num, int[][] ind, double[][] val)
          Returns columns in a sparse matrix representation.
 int getIndex(ilog.concert.IloNumVar var)
          Returns the column index corresponding to a variable in the invoking LP matrix.
 int getIndex(ilog.concert.IloRange rng)
          Returns the row index corresponding to a ranged constraint in the invoking LP matrix.
 int getNcols()
          Returns the number of columns in the invoking LP matrix.
 int getNNZs()
          Returns the number of nonzeros in the invoking LP matrix.
 int getNrows()
          Returns the number of rows in the invoking LP matrix.
 ilog.concert.IloNumVar getNumVar(int i)
          Returns the variable corresponding to the i-th column of LP matrix.
 ilog.concert.IloNumVar[] getNumVars()
          Returns an array of variables corresponding to the columns of the LP matrix.
 double getNZ(int row, int column)
          Returns the value of the matrix element row and col from the invoking LP matrix.
 ilog.concert.IloRange getRange(int i)
          Returns the ranged constraint corresponding to the i-th row of the LP matrix.
 ilog.concert.IloRange[] getRanges()
          Returns an array of range constraints corresponding to the rows of the LP matrix.
 void getRows(int start, int num, double[] lb, double[] ub, int[][] ind, double[][] val)
          Returns rows in a sparse matrix representation.
 void removeCols(int[] ind)
          Removes a set columns from the invoking LP matrix.
 void removeCols(int[] ind, int start, int num)
          Removes a set of columns from the invoking LP matrix.
 void removeCols(int begin, int num)
          Remove a range of columns from the LP matrix.
 void removeColumn(int ind)
          Removes one column from the LP matrix.
 void removeRow(int ind)
          Removes one row from the LP matrix.
 void removeRows(int[] ind)
          Removes a set of rows from the invoking LP matrix.
 void removeRows(int[] ind, int start, int num)
          Removes as set of rows from the invoking LP matrix.
 void removeRows(int start, int num)
          Removes a range of rows rows from the LP matrix.
 void setNZ(int rowind, int colind, double val)
          Sets one non-zero of the coefficient matrix of the invoking LP matrix.
 void setNZs(int[] rowind, int[] colind, double[] val)
          Sets non-zero elements of the coefficient matrix of the invoking LP matrix.
 
Methods inherited from interface ilog.concert.IloAddable
getName, setName
 

Method Detail

getNcols

public int getNcols()
             throws IloException
Returns the number of columns in the invoking LP matrix.

Returns:
The number of columns in the invoking LP matrix.
IloException

getNrows

public int getNrows()
             throws IloException
Returns the number of rows in the invoking LP matrix.

Returns:
The number of rows in the invoking LP matrix.
IloException

getNNZs

public int getNNZs()
            throws IloException
Returns the number of nonzeros in the invoking LP matrix.

Returns:
The number of nonzeros in the invoking LP matrix.
IloException

getCols

public void getCols(int begin,
                    int num,
                    int[][] ind,
                    double[][] val)
             throws IloException
Returns columns in a sparse matrix representation. This means that for every column, an array of row indices and an array of values is returned, corresponding to the non-zeros in the specified columns.

Parameters:
begin - The index of the first column being queried.
num - The number of columns being queried.
ind - An array of arrays of integers to where the row indices of the queried columns will be copied. The non-zero indices of column begin+i will be copied into an array returned as ind[i]. This array must be initialized at least to size num.
val - An array of arrays of doubles to where the non-zero coefficients of the queried columns will be copied. The non-zero values of column begin+i will be copied into an array returned as val[i]. This array must be initialized to at least size num.
IloException

getRows

public void getRows(int start,
                    int num,
                    double[] lb,
                    double[] ub,
                    int[][] ind,
                    double[][] val)
             throws IloException
Returns rows in a sparse matrix representation. This means that for every row, an array of column indices and an array of values is returned, corresponding to the non-zeros in the specified rows, as well as the bounds of the constraints corresponding to the queried rows. This implies that the expression of the range constraint of a queried row can be expressed as the scalar product of the values returned for the queried row and the variables corresponding to the column indices returned for the queried row.

Parameters:
start - The index of the first row being queried.
num - The number of rows being queried.
lb - An array where to copy the lower bound values for the range constraints corresponding to the queried rows. The lower bound of the range corresponding to row begin+i will be returned as lb[i]. This array must be allocated at least length num.
ub - An array where to copy the upper bound values for the range constraints corresponding to the queried rows. The upper bound of the range corresponding to row begin+i will be returned as ub[i]. This array must be allocated at least length num.
ind - An array of arrays of integers to which the column indices of the queried rows will be copied. The non-zero indices of row begin+i will be copied into an array returned as ind[i]. This array must be initialized to at least size num.
val - An array of arrays of doubles to which the non-zero coefficients of the queried rows will be copied. The non-zero values of row begin+i will be copied into an array returned as val[i]. This array must be initialized to at least size num.
IloException

getNZ

public double getNZ(int row,
                    int column)
             throws IloException
Returns the value of the matrix element row and col from the invoking LP matrix.

Parameters:
row - The row index of the matrix element to query.
Returns:
The value of the matrix element.
IloException

getIndex

public int getIndex(ilog.concert.IloRange rng)
             throws IloException
Returns the row index corresponding to a ranged constraint in the invoking LP matrix. If the constraint is not linked to any row of the invoking LP matrix, -1 is returned.

Parameters:
rng - Ranged constraint for which to query the row index.
Returns:
The row index of a range constraint.
IloException

getRange

public ilog.concert.IloRange getRange(int i)
                               throws IloException
Returns the ranged constraint corresponding to the i-th row of the LP matrix.

Parameters:
i - The row index of the ranged constraint to be queried.
Returns:
The ranged constraint corresponding to row i.
IloException

getRanges

public ilog.concert.IloRange[] getRanges()
                                  throws IloException
Returns an array of range constraints corresponding to the rows of the LP matrix.

Returns:
An array of range constraints corresponding to the rows of the LP matrix.
IloException

getIndex

public int getIndex(ilog.concert.IloNumVar var)
             throws IloException
Returns the column index corresponding to a variable in the invoking LP matrix. If the variable is not linked to any column of the invoking LP matrix, -1 is returned.

Parameters:
var - The variable whose column index is queried.
Returns:
The column index of the variable var.
IloException

getNumVar

public ilog.concert.IloNumVar getNumVar(int i)
                                 throws IloException
Returns the variable corresponding to the i-th column of LP matrix.

Parameters:
i - The column index of the variable to be queried.
Returns:
The variable corresponding to column i.
IloException

getNumVars

public ilog.concert.IloNumVar[] getNumVars()
                                    throws IloException
Returns an array of variables corresponding to the columns of the LP matrix.

Returns:
An array of variables corresponding to the columns of the LP matrix.
IloException

addRow

public int addRow(double lb,
                  double ub,
                  int[] ind,
                  double[] val)
           throws IloException
Adds a new row to the LP matrix.

The row being added is represented in sparse matrix notation. That is, the non-zero coefficients of the new row are given as an array ind of column indices, and an array of corresponding values val. These arrays must match in length.

A new range constraint is implicitly constructed for the added row. Its lower and upper bound values are provided as parameters lb and ub. The expression of the implicitly added range constraint is the scalar product of the values specified by parameter val and the variables corresponding to the columns specified by parameter ind.

Parameters:
lb - The lower bound for the newly created range constraint added as a new row to the invoking LP matrix.
ub - The upper bound for the newly created range constraint added as a new row to the invoking LP matrix.
ind - An array of column indices for the non-zeros of the new row. An index must appear at most one time, and must be in the range 0 through getNcols()-1.
val - An array of the corresponding values of the non-zeros of the row to be added.
Returns:
The row index of the new row.
IloException

addRows

public int addRows(double[] lb,
                   double[] ub,
                   int[][] ind,
                   double[][] val)
            throws IloException
Adds a set of new rows to LP matrix.

The rows being added are represented in sparse matrix notation. That is, the non-zero coefficients of the new rows are given as arrays of column indices and corresponding arrays of values. Each pair of corresponding arrays must match in length.

For each of the added rows, a new range constraint is implicitly constructed. The lower and upper bound value of the i-th newly created range constraint are provided in parameters lb[i] and ub[i]. Its expression is the scalar product of the values specified in array val[i] and the variables corresponding to the columns specified in array ind[i].

Parameters:
lb - An array of double values containing the lower bounds for the range constraints to be created and added as rows to the invoking LP matrix.
ub - An array of double values containing the upper bounds for the range constraints to be created and added as rows to the invoking LP matrix.
ind - An array or arrays of column indices for the non-zeros of the new rows. An index must appear at most one time for each new row and must be in the range 0 through getNcols()-1.
val - An array or arrays of the corresponding values of the non-zeros of the rows to be added.
Returns:
The row index of the first new row.
IloException

addRow

public int addRow(ilog.concert.IloRange rng)
           throws IloException
Adds a range constraint as a new row to an LP matrix. The range to be added must have a linear expression. The added row of the LP matrix will contain the linear terms of the range's expression as non-zeros. If the expression of the ranged constraint being added contains variables that do not correspond to columns of the invoking IloLPMatrix, new columns are automatically added as needed.

Parameters:
rng - The range constraint that is to become the new row.
Returns:
The row index of the added row.
IloException

addRows

public int addRows(ilog.concert.IloRange[] rng)
            throws IloException
Adds range constraints as new rows to an LP matrix. The ranges to be added must all have linear expressions. The added rows of the LP matrix will contain the linear terms of the range's expression as non-zeros. If the expression of a ranged constraint being added contains variables that do not correspond to columns of the invoking IloLPMatrix, new columns are automatically added as needed.

Parameters:
rng - The array of range constraints to be added as new rows.
Returns:
The row index of the first added row.
IloException

addRows

public int addRows(ilog.concert.IloRange[] rng,
                   int start,
                   int num)
            throws IloException
Adds a set of range constraints as new rows to an LP matrix. The ranges to be added must all have linear expressions. The added rows of the LP matrix will contain the linear terms of the range's expression as non-zeros. If the expression of a ranged constraint being added contains variables that do not correspond to columns of the invoking IloLPMatrix, new columns are automatically added as needed.

Parameters:
rng - An array containing the range constraints to be added as new rows.
start - The index of the first range in rng to be added as a new row.
num - The number of ranges in rng to be added as new rows.
Returns:
The row index of the first added row.
IloException

removeRow

public void removeRow(int ind)
               throws IloException
Removes one row from the LP matrix. The remaining rows will be kept in the same order.

Parameters:
ind - The index of the row to be removed.
IloException

removeRows

public void removeRows(int start,
                       int num)
                throws IloException
Removes a range of rows rows from the LP matrix. The remaining rows will be kept in the same order.

Parameters:
start - The index of the first row to be removed.
num - The number of rows to be removed.
IloException

removeRows

public void removeRows(int[] ind)
                throws IloException
Removes a set of rows from the invoking LP matrix. The indices of the rows to be removed are specified in the array ind. Rows that are not removed remain in their original order, but they are assigned new row indices from 0 to getNrows()-1.

Parameters:
ind - An array containing row indices of the rows to be removed.
IloException

removeRows

public void removeRows(int[] ind,
                       int start,
                       int num)
                throws IloException
Removes as set of rows from the invoking LP matrix. The indices of the rows to be removed are specified in the array ind[start], ..., ind[start+num-1]. Rows that are not removed remain in their original order, but they are assigned new row indices from 0 to getNrows()-1.

Parameters:
ind - An array containing row indices of the rows to be removed.
start - The first index in ind of the rows to be removed.
num - The number of indices in ind of the rows to be removed.
IloException

addColumn

public int addColumn(ilog.concert.IloNumVar var,
                     int[] ind,
                     double[] val)
              throws IloException
Adds a new column to an LP matrix.

The column being added is represented in sparse matrix notation. The non-zero coefficients of the new column are given as an array ind of row indices, and an array of corresponding values val. These arrays must match in length.

The added column is linked to the variable provided as parameter var. This variable must not originally be linked to a column of the invoking LP matrix.

Parameters:
var - The variable to be linked with the added column.
ind - An array of row indices of the non-zeros of the new column. An index must appear at most one time and must be in the range 0 through getNrows()-1.
val - An array of the corresponding values of the non-zeros of the column to be added.
Returns:
The column index of the added column.
IloException

addColumn

public int addColumn(ilog.concert.IloNumVar var)
              throws IloException
Adds a new empty column to an LP matrix. All elements in an empty column are 0 (zero). The added column is linked to the variable provided as parameter var. This variable must not originally be linked to a column of the invoking LP matrix.

Parameters:
var - The variable to be linked with the new column.
Returns:
The column index of the added column.
IloException

addCols

public int addCols(ilog.concert.IloNumVar[] var,
                   int[][] indices,
                   double[][] values)
            throws IloException

Adds new columns to the LP matrix. The columns being added are represented in sparse matrix notation. That is, the non-zero coefficients of the j-th new columns to be added are provided by array ind[j] containing the row indices, and by array val[j] containing corresponding values. Each pair of arrays ind[j] and val[j] must match in length.

The added columns will be linked to the variables provided as parameter var. These variables must not currently be linked to a column of the invoking LP matrix, nor may a variable be listed more than once in var.

Parameters:
var - An array of variables to be linked to the new columns.
Returns:
The column index of the first added column.
IloException

addCols

public int addCols(ilog.concert.IloNumVar[] var)
            throws IloException
Adds new empty columns to LP matrix. Empty columns have no non-zeros. The added columns will be linked to the variables provided as parameter var. These variables must not currently be linked to a column of the invoking LP matrix, nor may a variable be listed more than once in var.

Parameters:
var - An array of variables to be linked to the new columns.
Returns:
The column index of the first added column.
IloException

addCols

public int addCols(ilog.concert.IloNumVar[] var,
                   int start,
                   int num)
            throws IloException
Adds new empty columns to LP matrix. Empty columns have no non-zeros. The added columns will be linked to the variables provided in parameter var. These variables must not currently be linked to a column of the invoking LP matrix, nor may a variable be listed more than once in var[start], ... var[start+num-1].

Parameters:
var - An array containing the variables to be added as columns.
start - The first variable in var to be added.
num - The number of variables in var to be added.
Returns:
The column index of the first added column.
IloException

removeColumn

public void removeColumn(int ind)
                  throws IloException
Removes one column from the LP matrix. The remaining columns will be kept in the same order.

Parameters:
ind - The index of the column to be removed.
IloException

removeCols

public void removeCols(int begin,
                       int num)
                throws IloException
Remove a range of columns from the LP matrix. The remaining columns will be kept in the same order.

Parameters:
begin - The index of the first column to be removed.
num - Number of column to be removed.
IloException

removeCols

public void removeCols(int[] ind)
                throws IloException
Removes a set columns from the invoking LP matrix. The indices of columns to be removed are specified in the array ind. Columns that are not removed remain in their original order but are assigned new column indices from 0 to getNcols()-1.

Parameters:
ind - An array containing the indices of the columns to be removed.
IloException

removeCols

public void removeCols(int[] ind,
                       int start,
                       int num)
                throws IloException
Removes a set of columns from the invoking LP matrix. The indices of columns to be removed are specified in the array ind[start], ..., ind[start+num-1]. Columns that are not removed remain in their original order but are assigned new column indices from 0 to getNcols()-1.

Parameters:
ind - An array containing the indices of the columns to be removed.
start - The first index in ind of the columns to be removed.
num - The number of indices in ind of the columns to be removed.
IloException

clear

public void clear()
           throws IloException
Removes all rows and columns from invoking LP matrix.

IloException

setNZ

public void setNZ(int rowind,
                  int colind,
                  double val)
           throws IloException
Sets one non-zero of the coefficient matrix of the invoking LP matrix. Note that by doing this, you are implicitly changing the expression of the range constraint corresponding to the row index of the affected non-zero.

Parameters:
rowind - The row index of the matrix coefficient to be set.
colind - The column index of the matrix coefficient to be set.
val - The value of the matrix coefficient to be set.
IloException

setNZs

public void setNZs(int[] rowind,
                   int[] colind,
                   double[] val)
            throws IloException
Sets non-zero elements of the coefficient matrix of the invoking LP matrix. Note that by doing this, you are implicitly changing the expressions of the range constraints corresponding to the row indices of the affected non-zero.

Parameters:
rowind - An array containing the row indices of the matrix coefficients to be set.
colind - An array containing the column indices of the matrix coefficients to be set.
val - An array containing the values of the new matrix coefficients to be set.
IloException