一. 示例和解释
1. 代码
#include <iostream>
#include <vector>
#include <cmath>
#include "OsqpEigen/OsqpEigen.h"
using namespace std;
int main(){
Eigen::Matrix3d D;
D << 1, 2, 3, 4, 0, 5, 0, 7, 9;
cout << "Here is the matrix D:" << endl << D << endl;
Eigen::SparseMatrix<double> S;
S = D.sparseView(1, 1e-20);
cout << "Here is the matrix S:" << endl << S << endl;
return 0;
}
seivl@seivl-Default-string:~/my_codebase/path_optimizer_test/build$ ./main
Here is the matrix D:
1 2 3
4 0 5
0 7 9
Here is the matrix S:
Nonzero entries:
(1,0) (4,1) (2,0) (7,2) (3,0) (5,1) (9,2)
Outer pointers:
0 2 4 $
1 2 3
4 0 5
0 7 9
2. 解释
Nonzero entries:
(1,0) (4,1) (2,0) (7,2) (3,0) (5,1) (9,2)
以上计为 A 吧
这个元组里面是这么存的(value, row) , 第一个是值,第二个是所在的行数。
eg:
- (1, 0),值是1,第0行
- (4, 1),值是4,第1行
- (2, 0),值是2,第0行
- (7, 2),值是7,第2行
- (3, 0),值是3,第0行
- (5, 1),值是5,第1行
- (9, 2),值是9,第2行
Outer pointers:
0 2 4 $
存的是原矩阵中每一列的第一个非0元素在 A 中的下标
eg:
- 0 :第0列中的第一个元素是 A[0],A[0] = (1,0),即第0列中的第一个元素是1
- 2 :第1列中的第一个元素是 A[2],A[2] = (2,0),即第1列中的第一个元素是2
- 4 :第2列中的第一个元素是 A[4],A[4] = (3,0),即第2列中的第一个元素是3
二. 还有个栗子
hessian:
0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 -20 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 42 -20 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 42 -20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 22
-------end test TensionSmoother2::setHessianMatrix--------
*matrix_h:
Nonzero entries:
(0.01,0) (0.01,1) (0.01,2) (0.01,3) (0.01,4) (0.01,5) (0.01,6) (0.01,7) (0.01,8) (0.01,9) (22,15) (-20,16) (-20,15) (42,16) (-20,17) (-20,16) (42,17) (-20,18) (-20,17) (22,18)
Outer pointers:
0 1 2 3 4 5 6 7 8 9 10 10 10 10 10 10 12 15 18 $
0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0.01 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 -20 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 42 -20 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 42 -20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 22
同理
|