public interface IloLPMatrix extends IloConstraint
IloLPMatrix
allows you to treat a set of variables and
range constraints (instances of IloRange
)
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.
This modeling object allows
you to edit A
directly as a sparse matrix.
Every row of an instance of IloLPMatrix
corresponds to an instance of
IloRange
representing a linear constraint. Every column of
this matrix is linked to
an IloNumVar
object. An 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
(zero) to
getNrows-1
. Similarly, the columns of an LP matrix are
referenced by integer values, called the column indices, ranging from
0
(zero) to getNcols-1
. Nonzero values in the LP
matrix correspond to linear coefficients in the range constraints
corresponding to its rows. For example, a nonzero 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;
Create an instance of IloLPMatrix
by calling the method
IloMPModeler.LPMatrix
or
IloMPModeler.addLPMatrix
.
These methods create an empty instance of
IloLPMatrix
, that is, an LP matrix with
0 (zero) rows and 0 (zero) columns.
Populate the LP matrix by using the
methods addRow
, addRows
,
addColumn
, and addCols
.
Although you can add multiple ranges (that is, instances of
IloRange
) and multiple variables (that is, instances of
IloNumVar
) to an instance of IloLPMatrix
,
it still remains a single modeling object. Any objects of
IloRange
or IloNumVar
added to an instance
of IloLPMatrix
that is subsequently added to an instance
of IloCplex
are not directly accessible through
the methods of IloCplex
. For example, consider
r1
, an instance of
IloRange
added to an instance of IloLPMatrix
subsequently added to an instance of IloCplex
, and
r2
, an instance of IloRange
added directly
to the instance of IloCplex
. The range r1
differs from the range r2
; r1
cannot be
modified directly by the methods of IloCplex
; in contrast,
you can use methods of IloCplex
to modify r2
.
Modifier and Type | Method and Description |
---|---|
int |
addCols(IloNumVar[] var)
Adds new empty columns to the 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 the LP matrix.
|
int |
addColumn(IloNumVar var)
Adds a new empty column to an LP matrix.
|
int |
addColumn(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(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(IloRange[] rng)
Adds range constraints as new rows to an LP matrix.
|
int |
addRows(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 the invoking LP matrix.
|
void |
getCols(int begin,
int num,
int[][] ind,
double[][] val)
Returns 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
the LP matrix. |
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. |
IloRange |
getRange(int i)
Returns the ranged constraint corresponding to the
i -th row
of the LP matrix. |
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 of 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 from the LP matrix.
|
void |
setNZ(int rowind,
int colind,
double val)
Sets one nonzero of the coefficient matrix of the invoking LP matrix.
|
void |
setNZs(int[] rowind,
int[] colind,
double[] val)
Sets nonzero elements of the coefficient matrix of the invoking LP matrix.
|
getName, setName
int getNcols() throws IloException
IloException
int getNrows() throws IloException
IloException
int getNNZs() throws IloException
IloException
void getCols(int begin, int num, int[][] ind, double[][] val) throws IloException
For every column, an array of row indices and an array of values is returned, corresponding to the nonzeros in the specified columns.
IloException
begin
- The index of the first column being queried.num
- The number of consecutive columns being queried.ind
- An array of arrays of integers to where the row
indices of the queried columns will be copied. The
nonzero 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 nonzero
coefficients of the queried columns will be copied.
The nonzero 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
.void getRows(int start, int num, double[] lb, double[] ub, int[][] ind, double[][] val) throws IloException
For every row, an array of column indices and an array of values is returned, corresponding to the nonzeros 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.
IloException
start
- The index of the first row being queried.num
- The number of consecutive 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
nonzero 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 nonzero
coefficients of the queried rows will be copied.
The nonzero 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
.double getNZ(int row, int column) throws IloException
row
and
col
from the invoking LP matrix.IloException
row
- The row index of the matrix element to query.column
- The column index of the matrix element to query.int getIndex(IloRange rng) throws IloException
If the constraint is not linked to any row of the
invoking LP matrix, -1
is returned.
IloException
rng
- Ranged constraint for which to query the row index.IloRange getRange(int i) throws IloException
i
-th row
of the LP matrix.IloException
i
- The row index of the ranged constraint to be queried.i
.IloRange[] getRanges() throws IloException
IloException
int getIndex(IloNumVar var) throws IloException
If the variable is not linked to any column of the
invoking LP matrix, -1
is returned.
IloException
var
- The variable whose column index is queried.var
.IloNumVar getNumVar(int i) throws IloException
i
-th column of
the LP matrix.IloException
i
- The column index of the variable to be queried.i
.IloNumVar[] getNumVars() throws IloException
IloException
int addRow(double lb, double ub, int[] ind, double[] val) throws IloException
The row being added is represented in
sparse matrix notation. That is, the nonzero 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
.
IloException
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 nonzeros 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 nonzeros of
the row to be added.int addRows(double[] lb, double[] ub, int[][] ind, double[][] val) throws IloException
The rows being added are represented in sparse matrix notation. That is, the nonzero 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 the arguments
lb[i]
and ub[i]
. Its expression is the scalar
product of the values specified in the array val[i]
and the
variables corresponding to the columns specified in the array
ind[i]
.
IloException
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 nonzeros 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
nonzeros of the rows to be added.int addRow(IloRange rng) throws IloException
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 expression as nonzeros.
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.
IloException
rng
- The range constraint that is to become the new row.int addRows(IloRange[] rng) throws IloException
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 expression as nonzeros.
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.
IloException
rng
- The array of range constraints to be added as new rows.int addRows(IloRange[] rng, int start, int num) throws IloException
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 expression as
nonzeros. 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.
IloException
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 consecutive ranges in rng
to be added as new rows.void removeRow(int ind) throws IloException
The remaining rows will be kept in the same order.
IloException
ind
- The index of the row to be removed.void removeRows(int start, int num) throws IloException
The remaining rows will be kept in the same order.
IloException
start
- The index of the first row to be removed.num
- The number of consecutive rows to be removed.void removeRows(int[] ind) throws IloException
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
.
IloException
ind
- An array containing row indices of the rows to be
removed.void removeRows(int[] ind, int start, int num) throws IloException
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 (zero) to getNrows()-1
.
IloException
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 consecutive indices in ind
of the rows to be removed.int addColumn(IloNumVar var, int[] ind, double[] val) throws IloException
The column being added is represented
in sparse matrix notation. The nonzero 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.
IloException
var
- The variable to be linked with the added column.ind
- An array of row indices of the nonzeros 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 nonzeros of
the column to be added.int addColumn(IloNumVar var) throws IloException
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.
IloException
var
- The variable to be linked with the new column.int addCols(IloNumVar[] var, int[][] indices, double[][] values) throws IloException
The columns being added are represented
in sparse matrix notation. That is, the nonzero coefficients of the
j
-th new column 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
.
IloException
var
- An array of variables to be linked to the new columns.indices
- An array or arrays of row indices of the nonzeros of
the new columns. An index must appear at most one time
in each column and must be in the range
0(zero) through getNrows()-1
.values
- An array or arrays containing the corresponding values
of the nonzeros of the columns to be added.int addCols(IloNumVar[] var) throws IloException
Empty columns have no nonzeros.
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
.
IloException
var
- An array of variables to be linked to the new columns.int addCols(IloNumVar[] var, int start, int num) throws IloException
Empty columns have no nonzeros.
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]
.
IloException
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.void removeColumn(int ind) throws IloException
The remaining columns will be kept in the same order.
IloException
ind
- The index of the column to be removed.void removeCols(int begin, int num) throws IloException
The remaining columns will be kept in the same order.
IloException
begin
- The index of the first column to be removed.num
- Number of columns to be removed.void removeCols(int[] ind) throws IloException
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 (zero) to getNcols-1
.
IloException
ind
- An array containing the indices of the columns to
be removed.void removeCols(int[] ind, int start, int num) throws IloException
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
.
IloException
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.void clear() throws IloException
IloException
void setNZ(int rowind, int colind, double val) throws IloException
By doing this, you are implicitly changing the expression of the range constraint corresponding to the row index of the affected nonzero element.
IloException
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.void setNZs(int[] rowind, int[] colind, double[] val) throws IloException
By doing this, you are implicitly changing the expressions of the range constraints corresponding to the row indices of the affected nonzero elements.
IloException
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.