Skip to content

Commit ee118df

Browse files
committed
[unittest] [eiquadprog-fast] test_nonconvex
1 parent e01c633 commit ee118df

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

unittest/eiquadprog-fast.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,60 @@ BOOST_AUTO_TEST_CASE ( test_unbounded )
414414
BOOST_WARN(status==expected);
415415
}
416416

417+
// min -||x||^2
418+
// s.t.
419+
// 0<= x[0] <= 1
420+
// 0<= x[1] <= 1
421+
// DOES NOT WORK!
422+
423+
BOOST_AUTO_TEST_CASE ( test_nonconvex )
424+
{
425+
EiquadprogFast qp;
426+
qp.reset(2,0,4);
427+
428+
Eigen::MatrixXd Q(2,2);
429+
Q.setZero();
430+
Q(0,0) = -1.0;
431+
Q(1,1) = -1.0;
432+
433+
Eigen::VectorXd C(2);
434+
C.setZero();
435+
436+
Eigen::MatrixXd Aeq(0,2);
437+
438+
Eigen::VectorXd Beq(0);
439+
440+
Eigen::MatrixXd Aineq(4,2);
441+
Aineq.setZero();
442+
Aineq(0,0) = 1.;
443+
Aineq(1,0) = -1.;
444+
Aineq(2,1) = 1.;
445+
Aineq(3,1) = -1.;
446+
447+
Eigen::VectorXd Bineq(4);
448+
Bineq(0) = 0.;
449+
Bineq(1) = -1.;
450+
Bineq(2) = 0.;
451+
Bineq(3) = -1.;
452+
453+
Eigen::VectorXd x(2);
454+
455+
Eigen::VectorXd solution(2);
456+
solution(0) = 1.;
457+
solution(1) = 1.;
458+
459+
double val = -1.;
460+
461+
EiquadprogFast_status expected = EIQUADPROG_FAST_OPTIMAL;
462+
463+
EiquadprogFast_status status = qp.solve_quadprog(Q, C, Aeq, Beq, Aineq, Bineq, x);
464+
465+
BOOST_WARN(status==expected);
466+
467+
BOOST_WARN_CLOSE(qp.getObjValue(),val,1e-6);
468+
469+
BOOST_WARN(x.isApprox(solution));
470+
}
471+
417472
BOOST_AUTO_TEST_SUITE_END ()
418473

0 commit comments

Comments
 (0)