@@ -26,6 +26,10 @@ using autoware::common::osqp::float64_t;
26
26
// / Problem taken from https://github.com/osqp/osqp/blob/master/tests/basic_qp/generate_problem.py
27
27
// cppcheck-suppress syntaxError
28
28
TEST (TestOsqpInterface, BasicQp) {
29
+ using autoware::common::osqp::CSC_Matrix;
30
+ using autoware::common::osqp::calCSCMatrix;
31
+ using autoware::common::osqp::calCSCMatrixTrapezoidal;
32
+
29
33
auto check_result =
30
34
[](const std::tuple<std::vector<float64_t >, std::vector<float64_t >, int , int , int > & result) {
31
35
EXPECT_EQ (std::get<2 >(result), 1 );
@@ -87,5 +91,46 @@ TEST(TestOsqpInterface, BasicQp) {
87
91
result = osqp.optimize ();
88
92
check_result (result);
89
93
}
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
+ }
90
135
}
91
136
} // namespace
0 commit comments