14 __attribute__((format(printf, 2, 3)))
18 vsnprintf(msg,
sizeof(msg), format, args);
24 fprintf(stderr,
"[%s] => %.6f [s]\n", msg,
sec() - start);
28 gettimeofday(&tv,
NULL);
29 return tv.tv_sec + tv.tv_usec * 1e-6;
31 operator bool() {
return false; }
34 #define mtimer(...) if(__mtimer__ __b__ = __mtimer__(__VA_ARGS__));else 38 #include <qpOASES.hpp> 42 USING_NAMESPACE_QPOASES
44 printf(
"demo-qp1\n");
46 real_t H[2*2] = {2,1,1,4};
48 real_t g[2] = {-8,-12};
49 real_t ub[1*2] = {1e10, 1e10};
50 real_t lb[1*2] = {-1e10, -1e10};
51 real_t ubA[1*1] = {1e10};
52 real_t lbA[1*1] = {-1e10};
54 QProblem example( 2,1 );
56 options.printLevel = PL_NONE;
57 example.setOptions( options );
60 getSimpleStatus(example.init( H,g,A,lb,ub,lbA,ubA, nWSR ), BT_FALSE);
63 example.getPrimalSolution( xOpt );
64 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
65 xOpt[0],xOpt[1],example.getObjVal() );
69 printf(
"demo-qp2\n");
71 real_t H[2*2] = {2,1,1,4};
72 real_t
A[2*2] = { 2.0, 1.0};
73 real_t g[2] = {-8,-12};
74 real_t ub[1*2] = {1e10, 1e10};
75 real_t lb[1*2] = {-1e10, -1e10};
76 real_t ubA[1*2] = {2.0, 2.0};
77 real_t lbA[1*2] = {2.0,2.0};
79 QProblem example( 2,1 );
81 options.printLevel = PL_NONE;
82 example.setOptions( options );
85 getSimpleStatus(example.init( H,g,A,lb,ub,lbA,ubA, nWSR ), BT_FALSE);
88 example.getPrimalSolution( xOpt );
89 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
90 xOpt[0],xOpt[1],example.getObjVal() );
94 printf(
"demo-qp3\n");
96 real_t H[2*2] = {4,1,1,2};
97 real_t
A[2*1] = {1, 2};
98 real_t g[2] = {-3, -4};
99 real_t ub[1*2] = {1e10, 1e10};
100 real_t lb[1*2] = {0,0};
101 real_t ubA[1*1] = {1};
102 real_t lbA[1*1] = {1};
104 QProblem example( 2,1 );
106 options.printLevel = PL_NONE;
107 example.setOptions( options );
110 example.init( H,g,A,lb,ub,lbA,ubA, nWSR );
113 example.getPrimalSolution( xOpt );
114 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
115 xOpt[0],xOpt[1],example.getObjVal() );
120 printf(
"demo-qp3, use hotstart\n");
121 real_t H[2*2] = {4,1,1,2};
122 real_t
A[2*1] = {1, 2};
123 real_t g[2] = {-3, -4};
124 real_t ub[1*2] = {1e10, 1e10};
125 real_t lb[1*2] = {0,0};
126 real_t ubA[1*1] = {1};
127 real_t lbA[1*1] = {1};
129 mtimer(
"init x 10 time") {
130 for (
size_t i = 0; i < 10; i++) {
131 QProblem example( 2,1 );
133 options.printLevel = PL_NONE;
134 example.setOptions( options );
136 example.init( H,g,A,lb,ub,lbA,ubA, nWSR );
138 example.getPrimalSolution( xOpt );
139 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
140 xOpt[0],xOpt[1],example.getObjVal() );
143 printf(
" hotstart\n");
144 QProblem example( 2,1 );
146 options.printLevel = PL_NONE;
147 example.setOptions( options );
149 example.init( H,g,A,lb,ub,lbA,ubA, nWSR );
151 example.getPrimalSolution( xOpt );
152 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
153 xOpt[0],xOpt[1],example.getObjVal() );
154 mtimer(
"hotstart x 10 time") {
155 for (
size_t i = 0; i < 10; i++) {
157 example.hotstart(g,lb,ub,lbA,ubA, nWSR2 );
158 example.getPrimalSolution( xOpt );
159 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
160 xOpt[0],xOpt[1],example.getObjVal() );
166 printf(
"demo-qp3, use SQP init and hotstart\n");
167 real_t H[2*2] = {4,1,1,2};
168 real_t
A[2*1] = {1, 2};
169 real_t g[2] = {-3, -4};
170 real_t ub[1*2] = {1e10, 1e10};
171 real_t lb[1*2] = {0,0};
172 real_t ubA[1*1] = {1};
173 real_t lbA[1*1] = {1};
175 SQProblem example( 2,1 );
177 options.printLevel = PL_NONE;
178 example.setOptions( options );
179 mtimer(
"init x 10 time") {
180 for (
size_t i = 0; i < 10; i++) {
182 example.init( H,g,A,lb,ub,lbA,ubA, nWSR);
184 example.getPrimalSolution( xOpt );
185 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
186 xOpt[0],xOpt[1],example.getObjVal() );
189 mtimer(
"hotstart x 10 time") {
190 for (
size_t i = 0; i < 10; i++) {
192 example.hotstart( H,g,A,lb,ub,lbA,ubA, nWSR);
194 example.getPrimalSolution( xOpt );
195 printf(
" xOpt = [ %f, %f ]; objVal = %f\n\n",
196 xOpt[0],xOpt[1],example.getObjVal() );
__mtimer__(const char *format,...) __attribute__((format(printf
vsnprintf(msg, sizeof(msg), format, args)