robotology / osqp-eigen

Simple Eigen-C++ wrapper for OSQP library
https://robotology.github.io/osqp-eigen/
BSD 3-Clause "New" or "Revised" License
385 stars 114 forks source link

how to set the initial value replacing the defaule default value #87

Closed chenguoxi1987 closed 3 years ago

chenguoxi1987 commented 3 years ago

how to set the initial value replacing the defaule default value

S-Dafarra commented 3 years ago

Hi @chenguoxi1987, can you please specify which value you are referring to? Is it the initial guess?

chenguoxi1987 commented 3 years ago

Hi @chenguoxi1987, can you please specify which value you are referring to? Is it the initial guess?

yes,it's the initial guess how can set the initial guess

S-Dafarra commented 3 years ago

You can use these methods: https://github.com/robotology/osqp-eigen/blob/9b0091038cf0fb9099a5d6c55820d6e5846034a7/include/OsqpEigen/Solver.hpp#L207-L215

The primal variables are probably what you are looking for (i.e. the initial guess for the optimization variables). The dual variables instead are the Lagrange multipliers. You can initialize also those if you have them (maybe from a previous run).

chenguoxi1987 commented 3 years ago

You can use these methods:

https://github.com/robotology/osqp-eigen/blob/9b0091038cf0fb9099a5d6c55820d6e5846034a7/include/OsqpEigen/Solver.hpp#L207-L215

The primal variables are probably what you are looking for (i.e. the initial guess for the optimization variables). The dual variables instead are the Lagrange multipliers. You can initialize also those if you have them (maybe from a previous run).

i try the setPrimalVariable,but "segmentation fault (core dumped)"

Eigen::Matrix<double,2,1> primavariable; primavariable << 0.5,0.5; solver.setPrimalVariable(primavariable);

S-Dafarra commented 3 years ago

Hi @chenguoxi1987, it is pretty hard to figure out what is going wrong from those three lines. Can you provide some more information? Also, if you can share the code that is failing, it may help.

chenguoxi1987 commented 3 years ago

Ho @chenguoxi1987, it is pretty hard to figure out what is going wrong from those three lines. Can you provide some more information? Also, if you can share the code that is failing, it may help.

thank you, I put the "solver.setPrimalVariable" command after the "solver.initSolver", and the problem was colsed。

S-Dafarra commented 3 years ago

Ho @chenguoxi1987, it is pretty hard to figure out what is going wrong from those three lines. Can you provide some more information? Also, if you can share the code that is failing, it may help.

thank you, I put the "solver.setPrimalVariable" command after the "solver.initSolver", and the problem was colsed。

Nice catch @chenguoxi1987, indeed this should not happen. I have opened #88 to fix this.