364 {
365
366
367
368
369
370
371
372 int r1_index = 0;
373 int r2_index = 2 * obstacles_num_ * (horizon_ + 1);
374 int r3_index = 3 * obstacles_num_ * (horizon_ + 1);
375 int r4_index = 3 * obstacles_num_ * (horizon_ + 1) + lambda_horizon_;
376 int first_row_location = 0;
377
378
379 for (int i = 0; i < horizon_ + 1; ++i) {
380 int edges_counter = 0;
381
382 Eigen::MatrixXd R(2, 2);
383 R <<
cos(xWS_(2, i)),
sin(xWS_(2, i)),
sin(xWS_(2, i)),
cos(xWS_(2, i));
384
385 Eigen::MatrixXd t_trans(1, 2);
386 t_trans << (xWS_(0, i) +
cos(xWS_(2, i)) * offset_),
387 (xWS_(1, i) +
sin(xWS_(2, i)) * offset_);
388
389
390 for (int j = 0; j < obstacles_num_; ++j) {
391 int current_edges_num = obstacles_edges_num_(j, 0);
392 Eigen::MatrixXd Aj =
393 obstacles_A_.block(edges_counter, 0, current_edges_num, 2);
394 Eigen::MatrixXd bj =
395 obstacles_b_.block(edges_counter, 0, current_edges_num, 1);
396
397 Eigen::MatrixXd r1_block(2, current_edges_num);
398 r1_block = R * Aj.transpose();
399
400 Eigen::MatrixXd r2_block(1, current_edges_num);
401 r2_block = t_trans * Aj.transpose() - bj.transpose();
402
403
404 for (int k = 0; k < current_edges_num; ++k) {
405 A_data->emplace_back(r1_block(0, k));
406 A_indices->emplace_back(r1_index);
407
408 A_data->emplace_back(r1_block(1, k));
409 A_indices->emplace_back(r1_index + 1);
410
411 A_data->emplace_back(r2_block(0, k));
412 A_indices->emplace_back(r2_index);
413
414 A_data->emplace_back(1.0);
415 A_indices->emplace_back(r3_index);
416 r3_index++;
417
418 A_indptr->emplace_back(first_row_location);
419 first_row_location += 4;
420 }
421
422
423 edges_counter += current_edges_num;
424 r1_index += 2;
425 r2_index += 1;
426 }
427 }
428
429
430
431
432 r1_index = 0;
433 r2_index = 2 * obstacles_num_ * (horizon_ + 1);
434 for (int i = 0; i < horizon_ + 1; ++i) {
435 for (int j = 0; j < obstacles_num_; ++j) {
436 for (int k = 0; k < 4; ++k) {
437
438 if (k < 2) {
439 A_data->emplace_back(1.0);
440 } else {
441 A_data->emplace_back(-1.0);
442 }
443 A_indices->emplace_back(r1_index + k % 2);
444
445
446 A_data->emplace_back(-g_[k]);
447 A_indices->emplace_back(r2_index);
448
449
450 A_data->emplace_back(1.0);
451 A_indices->emplace_back(r4_index);
452 r4_index++;
453
454
455 A_indptr->emplace_back(first_row_location);
456 first_row_location += 3;
457 }
458
459
460 r1_index += 2;
461 r2_index += 1;
462 }
463 }
464
465 A_indptr->emplace_back(first_row_location);
466
467 CHECK_EQ(A_data->size(), A_indices->size());
468 CHECK_EQ(A_indptr->size(), static_cast<size_t>(num_of_variables_) + 1);
469}