Triplet Format for Sparse Matrices

原网站http://www.coin-or.org/Ipopt/documentation/node37.html
Triplet Format for Sparse Matrices

I POPT  was designed for optimizing large sparse nonlinear programs. Because of problem sparsity, the required matrices (like the constraints Jacobian or Lagrangian Hessian) are not stored as dense matrices, but rather in a sparse matrix format. For the tutorials in this document, we use the triplet format. Consider the matrix

$\displaystyle \left[ \begin{array}{ccccccc} 1.1 & 0 & 0 & 0 & 0 & 0 & 0.5 \ 0 ......0 & 0 & 0 & 0.4 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0.9 & 1.7 \ \end{array} \right]$(14)

A standard dense matrix representation would need to store $ 7 \cdot7{=} 49$ floating point numbers, where many entries would be zero. In triplet format, however, only the nonzero entries are stored. The triplet format records the row number, the column number, and the value of all nonzero entries in the matrix. For the matrix above, this means storing $ 14$ integers for the rows, $ 14$ integers for the columns, and $ 14$ floating point numbers for the values. While this does not seem like a huge space saving over the $ 49$ floating point numbers stored in the dense representation, for larger matrices, the space savings are very dramatic24.

The parameter index_style in get_nlp_info tells IPOPT if you prefer to use C style indexing (0-based, i.e., starting the counting at 0) for the row and column indices or Fortran style (1-based). Tables 3 and 4 below show the triplet format for both indexing styles, using the example matrix (14).


Table 3: Triplet Format of Matrix ( 14) with  index_style=FORTRAN_STYLE
rowcolvalue
iRow[0] = 1jCol[0] = 1values[0] = 1.1
iRow[1] = 1jCol[1] = 7values[1] = 0.5
iRow[2] = 2jCol[2] = 2values[2] = 1.9
iRow[3] = 2jCol[3] = 7values[3] = 0.5
iRow[4] = 3jCol[4] = 3values[4] = 2.6
iRow[5] = 3jCol[5] = 7values[5] = 0.5
iRow[6] = 4jCol[6] = 3values[6] = 7.8
iRow[7] = 4jCol[7] = 4values[7] = 0.6
iRow[8] = 5jCol[8] = 4values[8] = 1.5
iRow[9] = 5jCol[9] = 5values[9] = 2.7
iRow[10] = 6jCol[10] = 1values[10] = 1.6
iRow[11] = 6jCol[11] = 5values[11] = 0.4
iRow[12] = 7jCol[12] = 6values[12] = 0.9
iRow[13] = 7jCol[13] = 7values[13] = 1.7



Table 4: Triplet Format of Matrix ( 14) with  index_style=C_STYLE
rowcolvalue
iRow[0] = 0jCol[0] = 0values[0] = 1.1
iRow[1] = 0jCol[1] = 6values[1] = 0.5
iRow[2] = 1jCol[2] = 1values[2] = 1.9
iRow[3] = 1jCol[3] = 6values[3] = 0.5
iRow[4] = 2jCol[4] = 2values[4] = 2.6
iRow[5] = 2jCol[5] = 6values[5] = 0.5
iRow[6] = 3jCol[6] = 2values[6] = 7.8
iRow[7] = 3jCol[7] = 3values[7] = 0.6
iRow[8] = 4jCol[8] = 3values[8] = 1.5
iRow[9] = 4jCol[9] = 4values[9] = 2.7
iRow[10] = 5jCol[10] = 0values[10] = 1.6
iRow[11] = 5jCol[11] = 4values[11] = 0.4
iRow[12] = 6jCol[12] = 5values[12] = 0.9
iRow[13] = 6jCol[13] = 6values[13] = 1.7


The individual elements of the matrix can be listed in any order, and if there are multiple items for the same nonzero position, the values provided for those positions are added.

The Hessian of the Lagrangian is a symmetric matrix. In the case of a symmetric matrix, you only need to specify the lower left triangular part (or, alternatively, the upper right triangular part). For example, given the matrix,

$\displaystyle \left[ \begin{array}{ccccccc} 1.0 & 0 & 3.0 & 0 & 2.0 \ 0 & 1.1 ......& 0 \ 0 & 0 & 6.0 & 1.3 & 9.0 \ 2.0 & 5.0 & 0 & 9.0 & 1.4 \end{array} \right]$(15)

the triplet format is shown in Tables  5  and  6 .


Table 5: Triplet Format of Matrix ( 15) with  index_style=FORTRAN_STYLE
rowcolvalue
iRow[0] = 1jCol[0] = 1values[0] = 1.0
iRow[1] = 2jCol[1] = 1values[1] = 1.1
iRow[2] = 3jCol[2] = 1values[2] = 3.0
iRow[3] = 3jCol[3] = 3values[3] = 1.2
iRow[4] = 4jCol[4] = 3values[4] = 6.0
iRow[5] = 4jCol[5] = 4values[5] = 1.3
iRow[6] = 5jCol[6] = 1values[6] = 2.0
iRow[7] = 5jCol[7] = 2values[7] = 5.0
iRow[8] = 5jCol[8] = 4values[8] = 9.0
iRow[9] = 5jCol[9] = 5values[9] = 1.4




Table 6: Triplet Format of Matrix ( 15) with  index_style=C_STYLE
rowcolvalue
iRow[0] = 0jCol[0] = 0values[0] = 1.0
iRow[1] = 1jCol[1] = 0values[1] = 1.1
iRow[2] = 2jCol[2] = 0values[2] = 3.0
iRow[3] = 2jCol[3] = 2values[3] = 1.2
iRow[4] = 3jCol[4] = 2values[4] = 6.0
iRow[5] = 3jCol[5] = 3values[5] = 1.3
iRow[6] = 4jCol[6] = 0values[6] = 2.0
iRow[7] = 4jCol[7] = 1values[7] = 5.0
iRow[8] = 4jCol[8] = 3values[8] = 9.0
iRow[9] = 4jCol[9] = 4values[9] = 1.4




Footnotes

For an  $ n \times n$ matrix, the dense representation grows with the the square of $ n$ , while the sparse representation grows linearly in the number of nonzeros.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值