43 {
45 bool solver_flag = false;
46
47 if (planner_open_space_config_.dual_variable_warm_start_config()
48 .qp_format() ==
OSQP) {
49 DualVariableWarmStartOSQPInterface ptop =
50 DualVariableWarmStartOSQPInterface(
51 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
52 obstacles_b, xWS, planner_open_space_config_);
53
54 if (ptop.optimize()) {
55 ADEBUG <<
"dual warm up done.";
56 ptop.get_optimization_results(l_warm_up, n_warm_up);
57
59 solver_flag = true;
60 } else {
61 AWARN <<
"dual warm up fail.";
62 ptop.get_optimization_results(l_warm_up, n_warm_up);
63 solver_flag = false;
64 }
67 DualVariableWarmStartSlackOSQPInterface ptop =
68 DualVariableWarmStartSlackOSQPInterface(
69 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
70 obstacles_b, xWS, planner_open_space_config_);
71
72 if (ptop.optimize()) {
73 ADEBUG <<
"dual warm up done.";
74 ptop.get_optimization_results(l_warm_up, n_warm_up, s_warm_up);
75
77 solver_flag = true;
78 } else {
79 AWARN <<
"dual warm up fail.";
80 ptop.get_optimization_results(l_warm_up, n_warm_up, s_warm_up);
81 solver_flag = false;
82 }
85 DualVariableWarmStartIPOPTQPInterface* ptop =
86 new DualVariableWarmStartIPOPTQPInterface(
87 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
88 obstacles_b, xWS, planner_open_space_config_);
89
90 Ipopt::SmartPtr<Ipopt::TNLP> problem = ptop;
91
92 Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
93
94 app->Options()->SetIntegerValue(
95 "print_level",
99 app->Options()->SetIntegerValue(
100 "mumps_mem_percent",
104 app->Options()->SetNumericValue(
105 "mumps_pivtol",
109 app->Options()->SetIntegerValue(
113 app->Options()->SetNumericValue(
117 app->Options()->SetNumericValue(
118 "acceptable_constr_viol_tol",
122 app->Options()->SetNumericValue(
123 "min_hessian_perturbation",
127 app->Options()->SetNumericValue(
128 "jacobian_regularization_value",
132 app->Options()->SetStringValue(
133 "print_timing_statistics",
137 app->Options()->SetStringValue(
138 "alpha_for_y",
142 app->Options()->SetStringValue(
146
147 app->Options()->SetStringValue("mehrotra_algorithm", "yes");
148
149 Ipopt::ApplicationReturnStatus status = app->Initialize();
150 if (status != Ipopt::Solve_Succeeded) {
151 AERROR <<
"*** Dual variable wart start problem error during "
152 "initialization!";
153 return false;
154 }
155
156 status = app->OptimizeTNLP(problem);
157
158 if (status == Ipopt::Solve_Succeeded ||
159 status == Ipopt::Solved_To_Acceptable_Level) {
160
161 Ipopt::Index iter_count = app->Statistics()->IterationCount();
162 ADEBUG <<
"*** The problem solved in " << iter_count <<
" iterations!";
163
164 Ipopt::Number final_obj = app->Statistics()->FinalObjective();
165 ADEBUG <<
"*** The final value of the objective function is " << final_obj
166 << '.';
168 } else {
169 ADEBUG <<
"Solve not succeeding, return status: " << int(status);
170 }
171
172 ptop->get_optimization_results(l_warm_up, n_warm_up);
173
174 solver_flag = (status == Ipopt::Solve_Succeeded ||
175 status == Ipopt::Solved_To_Acceptable_Level);
178 DualVariableWarmStartIPOPTInterface* ptop =
179 new DualVariableWarmStartIPOPTInterface(
180 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
181 obstacles_b, xWS, planner_open_space_config_);
182
183 Ipopt::SmartPtr<Ipopt::TNLP> problem = ptop;
184
185 Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
186
187 app->Options()->SetIntegerValue(
188 "print_level",
192 app->Options()->SetIntegerValue(
193 "mumps_mem_percent",
197 app->Options()->SetNumericValue(
198 "mumps_pivtol",
202 app->Options()->SetIntegerValue(
206 app->Options()->SetNumericValue(
210 app->Options()->SetNumericValue(
211 "acceptable_constr_viol_tol",
215 app->Options()->SetNumericValue(
216 "min_hessian_perturbation",
220 app->Options()->SetNumericValue(
221 "jacobian_regularization_value",
225 app->Options()->SetStringValue(
226 "print_timing_statistics",
230 app->Options()->SetStringValue(
231 "alpha_for_y",
235 app->Options()->SetStringValue(
239
240 Ipopt::ApplicationReturnStatus status = app->Initialize();
241 if (status != Ipopt::Solve_Succeeded) {
242 AERROR <<
"*** Dual variable wart start problem error during "
243 "initialization!";
244 return false;
245 }
246
247 status = app->OptimizeTNLP(problem);
248 if (status == Ipopt::Solve_Succeeded ||
249 status == Ipopt::Solved_To_Acceptable_Level) {
250
251 Ipopt::Index iter_count = app->Statistics()->IterationCount();
252 ADEBUG <<
"*** The problem solved in " << iter_count <<
" iterations!";
253
254 Ipopt::Number final_obj = app->Statistics()->FinalObjective();
255 ADEBUG <<
"*** The final value of the objective function is " << final_obj
256 << '.';
258 } else {
259 ADEBUG <<
"Solve not succeeding, return status: " << int(status);
260 }
261
262 ptop->get_optimization_results(l_warm_up, n_warm_up);
263
264 solver_flag = (status == Ipopt::Solve_Succeeded ||
265 status == Ipopt::Solved_To_Acceptable_Level);
266 } else {
267 DualVariableWarmStartOSQPInterface* ptop_osqp =
268 new DualVariableWarmStartOSQPInterface(
269 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
270 obstacles_b, xWS, planner_open_space_config_);
271 bool succ = ptop_osqp->optimize();
272
273 if (!succ) {
274 AERROR <<
"dual warm up fail.";
275 ptop_osqp->get_optimization_results(l_warm_up, n_warm_up);
276 }
277
278 ADEBUG <<
"dual warm up done.";
279 ptop_osqp->get_optimization_results(l_warm_up, n_warm_up);
280
282
283
284 Eigen::MatrixXd l_warm_up_ipoptqp(l_warm_up->rows(), l_warm_up->cols());
285 Eigen::MatrixXd n_warm_up_ipoptqp(n_warm_up->rows(), n_warm_up->cols());
286
287 DualVariableWarmStartIPOPTQPInterface* ptop_ipoptqp =
288 new DualVariableWarmStartIPOPTQPInterface(
289 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
290 obstacles_b, xWS, planner_open_space_config_);
291
292 Ipopt::SmartPtr<Ipopt::TNLP> problem = ptop_ipoptqp;
293
294 Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
295
296 app->Options()->SetIntegerValue(
297 "print_level",
301 app->Options()->SetIntegerValue(
302 "mumps_mem_percent",
306 app->Options()->SetNumericValue(
307 "mumps_pivtol",
311 app->Options()->SetIntegerValue(
315 app->Options()->SetNumericValue(
319 app->Options()->SetNumericValue(
320 "acceptable_constr_viol_tol",
324 app->Options()->SetNumericValue(
325 "min_hessian_perturbation",
329 app->Options()->SetNumericValue(
330 "jacobian_regularization_value",
334 app->Options()->SetStringValue(
335 "print_timing_statistics",
339 app->Options()->SetStringValue(
340 "alpha_for_y",
344 app->Options()->SetStringValue(
348
349 app->Options()->SetStringValue("mehrotra_algorithm", "yes");
350
351 Ipopt::ApplicationReturnStatus status = app->Initialize();
352 if (status != Ipopt::Solve_Succeeded) {
353 AERROR <<
"*** Dual variable wart start problem error during "
354 "initialization!";
355 return false;
356 }
357
358 status = app->OptimizeTNLP(problem);
359
360 if (status == Ipopt::Solve_Succeeded ||
361 status == Ipopt::Solved_To_Acceptable_Level) {
362
363 Ipopt::Index iter_count = app->Statistics()->IterationCount();
364 ADEBUG <<
"*** IPOPTQP: The problem solved in " << iter_count
365 << " iterations!";
366 Ipopt::Number final_obj = app->Statistics()->FinalObjective();
367 ADEBUG <<
"*** IPOPTQP: The final value of the objective function is "
368 << final_obj << '.';
369 } else {
370 ADEBUG <<
"Solve not succeeding, return status: " << int(status);
371 }
372
373 ptop_ipoptqp->get_optimization_results(&l_warm_up_ipoptqp,
374 &n_warm_up_ipoptqp);
375
376
377 Eigen::MatrixXd l_warm_up_ipopt(l_warm_up->rows(), l_warm_up->cols());
378 Eigen::MatrixXd n_warm_up_ipopt(n_warm_up->rows(), n_warm_up->cols());
379
380 DualVariableWarmStartIPOPTInterface* ptop_ipopt =
381 new DualVariableWarmStartIPOPTInterface(
382 horizon, ts, ego, obstacles_edges_num, obstacles_num, obstacles_A,
383 obstacles_b, xWS, planner_open_space_config_);
384
385 problem = ptop_ipopt;
386
387
388 status = app->Initialize();
389 if (status != Ipopt::Solve_Succeeded) {
390 AERROR <<
"*** Dual variable wart start problem error during "
391 "initialization!";
392 return false;
393 }
394
395 status = app->OptimizeTNLP(problem);
396 if (status == Ipopt::Solve_Succeeded ||
397 status == Ipopt::Solved_To_Acceptable_Level) {
398
399 Ipopt::Index iter_count = app->Statistics()->IterationCount();
400 ADEBUG <<
"*** IPOPT: The problem solved in " << iter_count
401 << " iterations!";
402 Ipopt::Number final_obj = app->Statistics()->FinalObjective();
403 ADEBUG <<
"*** IPOPT: The final value of the objective function is "
404 << final_obj << '.';
405 } else {
406 ADEBUG <<
"Solve not succeeding, return status: " << int(status);
407 }
408
409 ptop_ipopt->get_optimization_results(&l_warm_up_ipopt, &n_warm_up_ipopt);
410
411
412 double l_max_diff1 = 0.0;
413 double l_max_diff2 = 0.0;
414 double l_max_diff3 = 0.0;
415 for (int c = 0; c < l_warm_up->cols(); ++c) {
416 for (int r = 0; r < l_warm_up->rows(); ++r) {
417 l_max_diff1 = std::max(l_max_diff1, std::abs(l_warm_up->coeff(r, c) -
418 l_warm_up_ipopt(r, c)));
419 l_max_diff2 = std::max(l_max_diff2, std::abs(l_warm_up->coeff(r, c) -
420 l_warm_up_ipoptqp(r, c)));
421 l_max_diff3 = std::max(l_max_diff3, std::abs(l_warm_up_ipoptqp(r, c) -
422 l_warm_up_ipopt(r, c)));
423 }
424 }
425 ADEBUG <<
"max l warm up diff between osqp & ipopt: " << l_max_diff1;
426 ADEBUG <<
"max l warm up diff between osqp & ipoptqp: " << l_max_diff2;
427 ADEBUG <<
"max l warm up diff between ipopt & ipoptqp: " << l_max_diff3;
428
429 double n_max_diff1 = 0.0;
430 double n_max_diff2 = 0.0;
431 double n_max_diff3 = 0.0;
432 for (int c = 0; c < n_warm_up->cols(); ++c) {
433 for (int r = 0; r < n_warm_up->rows(); ++r) {
434 n_max_diff1 = std::max(n_max_diff1, std::abs(n_warm_up->coeff(r, c) -
435 n_warm_up_ipopt(r, c)));
436 n_max_diff2 = std::max(n_max_diff2, std::abs(n_warm_up->coeff(r, c) -
437 n_warm_up_ipoptqp(r, c)));
438 n_max_diff3 = std::max(n_max_diff3, std::abs(n_warm_up_ipoptqp(r, c) -
439 n_warm_up_ipopt(r, c)));
440 }
441 }
442 ADEBUG <<
"max n warm up diff between osqp & ipopt: " << n_max_diff1;
443 ADEBUG <<
"max n warm up diff between osqp & ipoptqp: " << n_max_diff2;
444 ADEBUG <<
"max n warm up diff between ipopt & ipoptqp: " << n_max_diff3;
445
446 return true;
447 }
448
449 if (solver_flag == false) {
450
451 for (int r = 0; r < l_warm_up->rows(); ++r) {
452 for (int c = 0; c < l_warm_up->cols(); ++c) {
453 (*l_warm_up)(r, c) = 0.0;
454 }
455 }
456
457 for (int r = 0; r < n_warm_up->rows(); ++r) {
458 for (int c = 0; c < n_warm_up->cols(); ++c) {
459 (*n_warm_up)(r, c) = 0.0;
460 }
461 }
462 }
463
464 return true;
465}
#define PERF_BLOCK_START()
optional DualWarmUpMode qp_format
optional IpoptConfig ipopt_config
optional int32 ipopt_max_iter
optional string ipopt_alpha_for_y
optional double ipopt_jacobian_regularization_value
optional string ipopt_recalc_y
optional double ipopt_acceptable_constr_viol_tol
optional string ipopt_print_timing_statistics
optional int32 ipopt_print_level
optional int32 mumps_mem_percent
optional double ipopt_tol
optional double mumps_pivtol
optional double ipopt_min_hessian_perturbation
optional DualVariableWarmStartConfig dual_variable_warm_start_config