Skip to content

Commit c0c1a74

Browse files
committed
[unittest] [eiquadprog-rt] test_nonconvex
1 parent cc3ab11 commit c0c1a74

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

unittest/eiquadprog-rt.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,58 @@ BOOST_AUTO_TEST_CASE(test_unbounded) {
352352
BOOST_WARN(status != RT_EIQUADPROG_OPTIMAL); // SHOULD pass!
353353
}
354354

355+
// min -||x||^2
356+
// s.t.
357+
// 0<= x[0] <= 1
358+
// 0<= x[1] <= 1
359+
// DOES NOT WORK!
360+
361+
BOOST_AUTO_TEST_CASE(test_nonconvex) {
362+
RtEiquadprog<2,0,4> qp;
363+
364+
RtMatrixX<2,2>::d Q;
365+
Q.setZero();
366+
Q(0, 0) = -1.0;
367+
Q(1, 1) = -1.0;
368+
369+
RtVectorX<2>::d C;
370+
C.setZero();
371+
372+
RtMatrixX<0,2>::d Aeq;
373+
374+
RtVectorX<0>::d Beq;
375+
376+
RtMatrixX<4,2>::d Aineq(4, 2);
377+
Aineq.setZero();
378+
Aineq(0, 0) = 1.;
379+
Aineq(1, 0) = -1.;
380+
Aineq(2, 1) = 1.;
381+
Aineq(3, 1) = -1.;
382+
383+
RtVectorX<4>::d Bineq;
384+
Bineq(0) = 0.;
385+
Bineq(1) = 1.;
386+
Bineq(2) = 0.;
387+
Bineq(3) = 1.;
388+
389+
RtVectorX<2>::d x;
390+
391+
RtVectorX<2>::d solution;
392+
solution(0) = 1.;
393+
solution(1) = 1.;
394+
395+
double val = -1.;
396+
397+
RtEiquadprog_status expected = RT_EIQUADPROG_OPTIMAL;
398+
399+
RtEiquadprog_status status = qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
400+
401+
BOOST_CHECK_EQUAL(status, expected);
402+
403+
BOOST_WARN_CLOSE(qp.getObjValue(), val, 1e-6);
404+
405+
BOOST_WARN(x.isApprox(solution));
406+
}
407+
355408
BOOST_AUTO_TEST_SUITE_END ()
356409

0 commit comments

Comments
 (0)