cgal icon indicating copy to clipboard operation
cgal copied to clipboard

Could I set 'd' as dense matrix?

Open zed654 opened this issue 5 years ago • 9 comments

when write d as set_d(), now it work only diagonal shape.

How can i reform this shape like

d = 
[
    1.0037   -0.9975    0.0014    0.0005    0
   -0.9975    2.0018   -0.9989    0.0004    0
    0.0014   -0.9989    2.0007   -0.9997    0
    0.0005    0.0004   -0.9997    2.0001   -1.0000
         0         0         0   -1.0000    1.0000
]

I want solve this equation, 0.5 X' d X + cX + c0

and, why this method is not working?

qp.set_d(0,0,1); qp.set_d(0,1,1); qp.set_d(0,2,0);
qp.set_d(1,0,1); qp.set_d(1,1,1); qp.set_d(1,2,0);
qp.set_d(2,0,1); qp.set_d(2,1,1); qp.set_d(2,2,1);

zed654 avatar Dec 11 '20 13:12 zed654

Could you please add more context?

sloriot avatar Dec 11 '20 13:12 sloriot

I add more context, please save me--!

zed654 avatar Dec 11 '20 13:12 zed654

What do you mean by "it doesn't not work"?

set_d(i, j) should also only be used with j <= i, see its documentation.

MaelRL avatar Dec 12 '20 14:12 MaelRL

I add more context, please save me--!

What do you mean by "it doesn't not work"?

set_d(i, j) should also only be used with j <= i, see its documentation.

Thanks you!

If i wanna do this, should I use other library...?

zed654 avatar Dec 12 '20 14:12 zed654

What I meant was that D can be a dense matrix, but since it is symmetrical, calling it with j > i is pointless.

What is your error?

MaelRL avatar Dec 12 '20 14:12 MaelRL

What I meant was that D can be a dense matrix, but since it is symmetrical, calling it with j > i is pointless.

What is your error?

My 'd' is like that

d = 
[
    1.0037   -0.9975    0.0014    0.0005    0
   -0.9975    2.0018   -0.9989    0.0004    0
    0.0014   -0.9989    2.0007   -0.9997    0
    0.0005    0.0004   -0.9997    2.0001   -1.0000
         0         0         0   -1.0000    1.0000
]

It's not symmetrical.

How can i operate the solver by using this 'd'?

( And, the error what i saw is ' j > i' )

zed654 avatar Dec 12 '20 14:12 zed654

The matrix you gave is symmetric.

Just fill the coefficients (i,j), with j <= i and the other ones will be set up automatically.

Important: set_d() actually sets the coefficients of the matrix 2 * D with D in the formulation at the top of the doc.

MaelRL avatar Dec 12 '20 15:12 MaelRL

The matrix you gave is symmetric.

Just fill the coefficients (i,j), with j <= i and the other ones will be set up automatically.

Important: set_d() actually sets the coefficients of the matrix 2 * D with D in the formulation at the top of the doc.

Oh Thanks!!

It's working. 👍

But, I have one question.

At first, when my code is not working, I merged 'l <= x <= u' to 'Ax <= b'. For example,

set_a
=
[ 1 0
  0 1
  -1 0
  0 -1
].transpose()

set_b
=
[
  0.5
  0.5
  -0.5
  -0.5
]

But, It's not working. So, when I separated it as 'set_l' and 'set_u', It working. For example

set_l
=
[
  -0.5
  -0.5
]
set_u
=
[
  0.5
  0.5
]

.

Why it is not working when I merge the variable set_l and set_u as set_a and set_b ?

zed654 avatar Dec 13 '20 08:12 zed654

The matrix A is an m x n matrix, with m the number of constraints and n the number of variables. With your (transposed) set_a, the matrix is an n x m matrix.

Note that the function set_a() has signature set_a(j, i) to write the coefficient A(i, j).

MaelRL avatar Dec 14 '20 08:12 MaelRL