Skip to content

Commit a694806

Browse files
committed
add test for new functions
Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent 8f85fc1 commit a694806

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

common/osqp_interface/test/test_osqp_interface.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ using autoware::common::osqp::float64_t;
2626
/// Problem taken from https://github.com/osqp/osqp/blob/master/tests/basic_qp/generate_problem.py
2727
// cppcheck-suppress syntaxError
2828
TEST(TestOsqpInterface, BasicQp) {
29+
using autoware::common::osqp::CSC_Matrix;
30+
using autoware::common::osqp::calCSCMatrix;
31+
using autoware::common::osqp::calCSCMatrixTrapezoidal;
32+
2933
auto check_result =
3034
[](const std::tuple<std::vector<float64_t>, std::vector<float64_t>, int, int, int> & result) {
3135
EXPECT_EQ(std::get<2>(result), 1);
@@ -87,5 +91,46 @@ TEST(TestOsqpInterface, BasicQp) {
8791
result = osqp.optimize();
8892
check_result(result);
8993
}
94+
{
95+
// Define problem during initialization with csc matrix
96+
Eigen::MatrixXd P(2, 2);
97+
P << 4, 1, 1, 2;
98+
CSC_Matrix P_csc = calCSCMatrixTrapezoidal(P);
99+
Eigen::MatrixXd A(4, 2);
100+
A << 1, 1, 1, 0, 0, 1, 0, 1;
101+
CSC_Matrix A_csc = calCSCMatrix(A);
102+
std::vector<float64_t> q = {1.0, 1.0};
103+
std::vector<float64_t> l = {1.0, 0.0, 0.0, -autoware::common::osqp::INF};
104+
std::vector<float64_t> u = {1.0, 0.7, 0.7, autoware::common::osqp::INF};
105+
autoware::common::osqp::OSQPInterface osqp(P_csc, A_csc, q, l, u, 1e-6);
106+
std::tuple<std::vector<float64_t>, std::vector<float64_t>, int, int, int> result = osqp.optimize();
107+
check_result(result);
108+
}
109+
{
110+
std::tuple<std::vector<float64_t>, std::vector<float64_t>, int, int, int> result;
111+
// Dummy initial problem with csc matrix
112+
Eigen::MatrixXd P = Eigen::MatrixXd::Zero(2, 2);
113+
CSC_Matrix P_csc = calCSCMatrixTrapezoidal(P);
114+
Eigen::MatrixXd A = Eigen::MatrixXd::Zero(4, 2);
115+
CSC_Matrix A_csc = calCSCMatrix(A);
116+
std::vector<float64_t> q(2, 0.0);
117+
std::vector<float64_t> l(4, 0.0);
118+
std::vector<float64_t> u(4, 0.0);
119+
autoware::common::osqp::OSQPInterface osqp(P_csc, A_csc, q, l, u, 1e-6);
120+
osqp.optimize();
121+
// Redefine problem before optimization
122+
Eigen::MatrixXd P_new(2, 2);
123+
P_new << 4, 1, 1, 2;
124+
CSC_Matrix P_new_csc = calCSCMatrixTrapezoidal(P_new);
125+
Eigen::MatrixXd A_new(4, 2);
126+
A_new << 1, 1, 1, 0, 0, 1, 0, 1;
127+
CSC_Matrix A_new_csc = calCSCMatrix(A_new);
128+
std::vector<float64_t> q_new = {1.0, 1.0};
129+
std::vector<float64_t> l_new = {1.0, 0.0, 0.0, -autoware::common::osqp::INF};
130+
std::vector<float64_t> u_new = {1.0, 0.7, 0.7, autoware::common::osqp::INF};
131+
osqp.initializeProblem(P_new_csc, A_new_csc, q_new, l_new, u_new);
132+
result = osqp.optimize();
133+
check_result(result);
134+
}
90135
}
91136
} // namespace

0 commit comments

Comments
 (0)