Question about Problem Setup

I have read the document and the example QP, but I’m not quite sure whether the Hessian matrix(P matrix) is setup as upper-triangular matrix or lower-triangular matrix, it seems that it is set up as upper-triangular matrix, according to the data filled in row indices P_i and column pointers P_p. Someone please tell me which one is true.

Another question, are all matrices in column-major form or row-major form?

the link is below

Upper triangular. Sparse matrices are in compressed sparse column format.

1 Like

Thanks, one more question, for each of the column pointers in the p[] array, if that column is all zeros, then what will the pointer be? Pointing to the tail of the array?

Consecutive elements in the p array can be thought of as the position of the start of each column and one past the end. A repeated entry indicates an empty column.

1 Like

Hello

Hopefully it is OK to revive this topic. But I think my problem fits here.

I am trying to setup a problem in c which I already solved (res.x = [-0.14, -0.36, 0.05]) in Matlab.

P = sparse([4, 0.1 0.1; 0.1, 2, 0.1; 0.1, 0.1, 3]);
q = [1; 1; -0.1];
A = sparse([1, 0, 0; 0, 1, 0; 1, 1, 0]);
l = [-0.14; -0.4; -0.5];
u = [ 0.14; 0.4; -0.5];

p = osqp;
p.setup(P, q, A, l, u, ‘alpha’, 1);
res = p.solve();

I tried to set up the same problem in c and it puzzles me. I started with the example ‘Setup and Solve’ from the homepage, compiled it ran it and got a solution. Then I changed the problem setup to the following lines.

c_int n = 3;
c_float P_x[6] = {4.0, 0.1, 2.0, 0.1, 0.1, 3.0,};
c_int P_nnz = 6;
c_int P_i[6] = {0, 0, 1, 0, 1, 2, };
c_int P_p[4] = {0, 1, 3, 6, };

c_float q[3] = {1.0, 1.0, -0.1,};
c_int m = 3;

c_int A_nnz = 4;
c_float A_x[4] = {1.0, 1.0, 1.0, 1.0, };
c_int A_i[4] = {0, 2, 1, 2, };
c_int A_p[3] = {0, 2, 4, };

c_float l[3] = {-0.14, -0.4, -0.5, };
c_float u[3] = { 0.14, 0.5, -0.5, };

May somebody can see my mistake?

Thank you in advance

You should have c_int A_p[4] = { 0, 2, 4, 4, };

Thank you for your answer but as I do not really understand why I need the second 4 i would appreciate if you can clarify this for me.

Edit: Just read the topic again and found the post from paul.goulart about the double entry for an empty column.

.

It helps to think of the column index variable A_p as indicating, for each column, the index of the first element in the column followed by the index of the element one beyond the last entry in the column. A repeated element (4 in this case) means that the corresponding column contains entries 4 … 3, which means that it will be empty.