ilog.concert
Interface IloLPMatrix


public interface IloLPMatrix
extends IloConstraint

An IloLPMatrix object allows you to treat a set or range constraints (instances of IloRange) and variables as a matrix. Objects of this class represent a set of linear constraints of the form lhs <= A x <= rhs, where lhs and rhs 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. 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 c_ij 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.

See Also:
IloMPModeler.addLPMatrix()

Method Summary
 int addCols(IloNumVar[] var)
          Adds new empty columns to LP matrix.
 int addCols(IloNumVar[] var, int[][] indices, double[][] values)
          Adds new columns to the LP matrix.
 int addCols(IloNumVar[] var, int start, int num)
          Adds new empty columns to LP matrix.
 int addColumn(IloNumVar var)
          Adds a new empty column to LP matrix.
 int addColumn(IloNumVar var, int[] ind, double[] val)
          Adds a new column to LP matrix.
 int addRow(double lb, double ub, int[] ind, double[] val)
          Adds a new row to LP matrix.
 int addRow(IloRange rng)
          Adds range constraint as a new row to LP matrix.
 int addRows(double[] lb, double[] ub, int[][] indices, double[][] values)
          Adds a set of new rows to LP matrix.
 int addRows(IloRange[] rng)
          Adds range constraints as new rows to LP matrix.
 int addRows(IloRange[] rng, int start, int num)
          Adds range constraints as new rows to LP matrix.
 void clear()
          Deletes all rows and columns from invoking LP matrix.
 void getCols(int begin, int end, int[][] ind, double[][] val)
          Returns the queried columns in a sparse matrix representation.
 int getIndex(IloNumVar var)
          Returns the column index corresponding to a variable in the invoking LP matrix.
 int getIndex(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.
 IloNumVar getNumVar(int i)
          Returns the variable corresponding to the i-th column of LP matrix.
 IloNumVar[] getNumVars()
          Returns the 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.
 IloRange getRange(int i)
          Returns the ranged constraint corresponding to the i-th row of the LP matrix.
 IloRange[] getRanges()
          Returns the 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 the queried rows in a sparse matrix representation.
 void removeCols(int[] ind)
          Removes all columns with column index listed in parameter ind from the invoking LP matrix.
 void removeCols(int[] ind, int start, int num)
          Removes all columns with column index listed in parameter ind[start], ... ind[start+num-1] from the invoking LP matrix.
 void removeCols(int begin, int num)
          Remove 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 all rows from the invoking LP matrix, with row index listed in parameter ind.
 void removeRows(int[] ind, int start, int num)
          Removes all rows from the invoking LP matrix, with row index listed in parameter ind[start], ... ind[start+num-1].
 void removeRows(int start, int num)
          Removes 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()
Returns the number of columns in the invoking LP matrix.
Returns:
The number of columns in the invoking LP matrix.

getNrows

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

getNNZs

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

getCols

public void getCols(int begin,
                    int end,
                    int[][] ind,
                    double[][] val)
             throws IloException
Returns the queried columns in a sparse matrix representation. This means that for every column an array of row indices, an array of values is returned corresponding to the non-zeros in the specified columns.
Parameters:
begin - The number of first column being queried.
end - The number of last column being queried.
ind - An array or 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 ind[end-begin+1][].
val - An array or arrays of doubles to where the non-zero coefficients 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 val[end-begin+1][].

getRows

public void getRows(int start,
                    int num,
                    double[] lb,
                    double[] ub,
                    int[][] ind,
                    double[][] val)
             throws IloException
Returns the queried 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. This implies that 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 first row being queried.
num - The number rows being queried.
lb - 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 to at least length end-begin+1.
ub - 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 to at least length end-begin+1.
ind - An array or 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 at least to size ind[end-begin+1][].
val - an array or arrays of doubles to which the non-zero coefficients 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 at least to size val[end-begin+1][].

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.
col - The column index of the matrix element to query.
Returns:
The value of the matrix element.

getIndex

public int getIndex(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.
Returns:
The row index of a range constraint.

getRange

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

getRanges

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

getIndex

public int getIndex(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 required.
Returns:
The column index of the variable var.

getNumVar

public IloNumVar getNumVar(int i)
Returns the variable corresponding to the i-th column of LP matrix.
Returns:
The variable corresponding to column i.

getNumVars

public IloNumVar[] getNumVars()
Returns the array of variables corresponding to the columns of the LP matrix.
Returns:
The array of variables corresponding to the columns of the LP matrix.

addRow

public int addRow(double lb,
                  double ub,
                  int[] ind,
                  double[] val)
           throws IloException
Adds a new row to 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 var of column indices, and an array of corresponding values val. Both 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 row to the invoking LP matrix.
ub - The upper bound for the newly created range constraint added as row to the invoking LP matrix.
ind - An array of column indices of 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 added row.

addRows

public int addRows(double[] lb,
                   double[] ub,
                   int[][] indices,
                   double[][] values)
            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 an array of column indices and an array of corresponding values. Both 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 by parameter val[i] and the variables corresponding to the columns specified by parameter ind[i].
Parameters:
lb - The lower bounds for the newly created range constraints added as rows to the invoking LP matrix.
ub - The upper bounds for the newly created range constraints 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 added row.

addRow

public int addRow(IloRange rng)
           throws IloException
Adds range constraint as a new row to 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 ranges expression as non-zeros. If the expression of the ranged constraint to be added contains variables that do not correspond to columns of the invoking IloLPMatrix, new columns will automatically be added as needed.
Parameters:
rng - The range constraint that is to become the new row.
Returns:
The row index of the added row.

addRows

public int addRows(IloRange[] rng)
            throws IloException
Adds range constraints as new rows to 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 ranges expression as non-zeros. If the expression of a ranged constraint to be added contains variables that do not correspond to columns of the invoking IloLPMatrix, new columns will automatically be 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.

addRows

public int addRows(IloRange[] rng,
                   int start,
                   int num)
            throws IloException
Adds range constraints as new rows to 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 ranges expression as non-zeros. If the expression of a ranged constraint to be added contains variables that do not correspond to columns of the invoking IloLPMatrix, new columns will automatically be added as needed.
Parameters:
rng - The 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.

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.

removeRows

public void removeRows(int start,
                       int num)
                throws IloException
Removes 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 - number of rows to be removed.

removeRows

public void removeRows(int[] ind)
                throws IloException
Removes all rows from the invoking LP matrix, with row index listed in parameter ind. The remaining rows will be kept in the same order.
Parameters:
ind - an array of row indices of the rows to be removed

removeRows

public void removeRows(int[] ind,
                       int start,
                       int num)
                throws IloException
Removes all rows from the invoking LP matrix, with row index listed in parameter ind[start], ... ind[start+num-1]. The remaining rows will be kept in the same order.
Parameters:
ind - An array of row indices of the rows to be removed.
start - The index of first row index in ind of the rows to be removed.
start - The number of row indices in ind of the rows to be removed.

addColumn

public int addColumn(IloNumVar var,
                     int[] ind,
                     double[] val)
              throws IloException
Adds a new column to 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. Both arrays must match in length. The added column will be linked to the variable provided as parameter var. This variable must not currently be linked to a column of the invoking LP matrix.
Parameters:
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.

addColumn

public int addColumn(IloNumVar var)
              throws IloException
Adds a new empty column to LP matrix. All elements in an empty column are non-zero. The added column will be linked to the variable provided as parameter var. This variable must not currently be linked to a column of the invoking LP matrix.
Returns:
The column index of the added column.

addCols

public int addCols(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.
ind - An array or arrays of row indices of the non-zeros of the new columns. An index must appear at most one time in each column and must be in the range 0 through getNrows()-1.
val - An array or arrays containing the corresponding values of the non-zeros of the columns to be added.
Returns:
The column index of the first added column.

addCols

public int addCols(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. This variable 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.

addCols

public int addCols(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 as parameter var. This variable 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.

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.

removeCols

public void removeCols(int begin,
                       int num)
                throws IloException
Remove 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.

removeCols

public void removeCols(int[] ind)
                throws IloException
Removes all columns with column index listed in parameter ind from the invoking LP matrix. The remaining columns will be kept in the same order.
Parameters:
ind - An array of column indices of the columns to be removed.

removeCols

public void removeCols(int[] ind,
                       int start,
                       int num)
                throws IloException
Removes all columns with column index listed in parameter ind[start], ... ind[start+num-1] from the invoking LP matrix. The remaining columns will be kept in the same order.
Parameters:
ind - An array of column indices of the columns to be removed.
start - The index of first column index in ind of the columns to be removed.
num - The number of column indices in ind of the columns to be removed.

clear

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

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.

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 expression of the range constraints corresponding to the row indices of the affected non-zero.
Parameters:
rowind - The row indices of the matrix coefficients to be set.
colind - The column indices of the matrix coefficients to be set.
val - The values of the matrix coefficients to be set.