@@ -165,42 +165,27 @@ Eigen::MatrixXd BiMPPI::getNoise(const int &T) {
165
165
166
166
void BiMPPI::move () {
167
167
x_init = x_init + (dt * f (x_init, u0));
168
- U_f0 = U_f0.rightCols (U_f0.cols () - 1 );
168
+ U_f0.leftCols (U_f0.cols () - 1 ) = U_f0.rightCols (U_f0.cols () - 1 );
169
+ // U_f0 = U_f0.rightCols(U_f0.cols() - 1);
169
170
}
170
171
171
172
void BiMPPI::solve () {
172
173
// omp setting for nested parallel
173
174
omp_set_nested (1 );
174
175
175
176
// 1. Clustered MPPI
176
- Tf = U_f0.cols ();
177
- Tb = U_b0.cols ();
178
- // start = std::chrono::high_resolution_clock::now();
179
- // #pragma omp parallel sections num_threads(12)
180
- // {
181
- // #pragma omp section
182
- // backwardRollout();
183
-
184
- // #pragma omp section
185
- // forwardRollout();
186
- // }
187
- // finish = std::chrono::high_resolution_clock::now();
188
- // elapsed_1 = finish - start;
189
- // std::cout<<"Fir = "<<elapsed_1.count()<<std::endl;
190
-
191
- std::cout<<" a" <<std::endl;
177
+ // Tf = U_f0.cols();
178
+ // Tb = U_b0.cols();
192
179
start = std::chrono::high_resolution_clock::now ();
193
180
backwardRollout ();
194
181
forwardRollout ();
195
182
finish = std::chrono::high_resolution_clock::now ();
196
183
elapsed_1 = finish - start;
197
184
// std::cout<<"Sec = "<<elapsed_1.count()<<std::endl;
198
185
199
- std::cout<<" b" <<std::endl;
200
186
// 2. Select Connection
201
187
start = std::chrono::high_resolution_clock::now ();
202
188
selectConnection ();
203
- std::cout<<" c" <<std::endl;
204
189
concatenate ();
205
190
finish = std::chrono::high_resolution_clock::now ();
206
191
elapsed_2 = finish - start;
@@ -210,13 +195,9 @@ void BiMPPI::solve() {
210
195
guideMPPI ();
211
196
finish = std::chrono::high_resolution_clock::now ();
212
197
elapsed_3 = finish - start;
213
- std::cout<<" d" <<std::endl;
214
198
215
199
// 4. Partitioning Control
216
- start = std::chrono::high_resolution_clock::now ();
217
200
partitioningControl ();
218
- finish = std::chrono::high_resolution_clock::now ();
219
- elapsed_4 = finish - start;
220
201
221
202
elapsed = elapsed_1.count () + elapsed_2.count () + elapsed_3.count ();
222
203
@@ -303,7 +284,6 @@ void BiMPPI::forwardRollout() {
303
284
if (collision_checker->getCollisionGrid (Xi.col (j))) {
304
285
all_feasible = false ;
305
286
cost = 1e8 ;
306
- // std::cout<<"F = "<<cost<<std::endl;
307
287
break ;
308
288
}
309
289
}
@@ -332,8 +312,8 @@ void BiMPPI::selectConnection() {
332
312
double min_norm = std::numeric_limits<double >::max ();
333
313
int cb, df, db;
334
314
for (int cb_ = 0 ; cb_ < clusters_b.size (); ++cb_) {
335
- for (int df_ = 1 ; df_ < Tf- 1 ; ++df_) {
336
- for (int db_ = 0 ; db_ < Tb- 1 ; ++db_) {
315
+ for (int df_ = 0 ; df_ <= Tf; ++df_) {
316
+ for (int db_ = 0 ; db_ <= Tb; ++db_) {
337
317
double norm = (Xf.block (cf * dim_x, df_, dim_x, 1 ) - Xb.block (cb_ * dim_x, db_, dim_x, 1 )).norm ();
338
318
if (norm < min_norm) {
339
319
min_norm = norm;
@@ -344,7 +324,6 @@ void BiMPPI::selectConnection() {
344
324
}
345
325
}
346
326
}
347
- // std::cout << "F: " << clusters_b.size() << ", B: " << clusters_b.size() << ", cf: " << cf << ", cb: " << cb << ", df: " << df << ", db: " << db << std::endl;
348
327
joints.push_back ({cf, cb, df, db});
349
328
}
350
329
}
@@ -358,13 +337,28 @@ void BiMPPI::concatenate() {
358
337
int cb = joint[1 ];
359
338
int df = joint[2 ];
360
339
int db = joint[3 ];
361
- // std::cout << "F: " << clusters_b.size() << ", B: " << clusters_b.size() << ", cf: " << cf << ", cb: " << cb << ", df: " << df << ", db: " << db << std::endl;
362
340
363
- Eigen::MatrixXd U (dim_u, df + (Tb - db) + 1 );
364
- Eigen::MatrixXd X (dim_x, df + (Tb - db) + 2 );
341
+ Eigen::MatrixXd U (dim_u, std::max (Tf, df + (Tb - db)) );
342
+ Eigen::MatrixXd X (dim_x, std::max (Tf, df + (Tb - db)) + 1 );
365
343
366
- U << Uf.block (cf * dim_u, 0 , dim_u, df+1 ), Ub.block (cb * dim_u, db, dim_u, Tb - db);
367
- X << Xf.block (cf * dim_x, 0 , dim_x, df+1 ), Xb.block (cb * dim_x, db, dim_x, Tb - db + 1 );
344
+ if (df == 0 ) {
345
+ X.leftCols (df+1 ) = Xf.block (cf * dim_x, 0 , dim_x, df+1 );
346
+ }
347
+ else {
348
+ U.leftCols (df) = Uf.block (cf * dim_u, 0 , dim_u, df);
349
+ X.leftCols (df+1 ) = Xf.block (cf * dim_x, 0 , dim_x, df+1 );
350
+ }
351
+
352
+ if (db != Tb) {
353
+ U.middleCols (df+1 , Tb - db - 1 ) = Ub.block (cb * dim_u, db + 1 , dim_u, Tb - db - 1 );
354
+ X.middleCols (df+2 , Tb - db - 1 ) = Xb.block (cb * dim_x, db + 1 , dim_x, Tb - db - 1 );
355
+ }
356
+
357
+ // Fill if lenght is shorter than Tf
358
+ if (df + (Tb - db) < Tf) {
359
+ U.rightCols (Tf - (df + (Tb - db))).colwise () = Eigen::VectorXd::Zero (dim_u);
360
+ X.rightCols (Tf - (df + (Tb - db))).colwise () = x_target;
361
+ }
368
362
369
363
Uc.push_back (U);
370
364
Xc.push_back (X);
@@ -394,12 +388,11 @@ void BiMPPI::guideMPPI() {
394
388
Xi.col (0 ) = x_init;
395
389
double cost = 0.0 ;
396
390
for (int j = 0 ; j < Tr; ++j) {
397
- // cost += q(Xi.col(j), Ui.block(i * dim_u, j, dim_u, 1));
398
391
cost += p (Xi.col (j), x_target);
399
392
Xi.col (j+1 ) = Xi.col (j) + (dt * f (Xi.col (j), Ui.block (i * dim_u, j, dim_u, 1 )));
400
393
}
401
- // Guide Cost
402
394
cost = p (Xi.col (Tr), x_target);
395
+ // Guide Cost
403
396
cost += (Xi - X_ref).colwise ().norm ().sum ();
404
397
for (int j = 0 ; j < Tr + 1 ; ++j) {
405
398
if (collision_checker->getCollisionGrid (Xi.col (j))) {
@@ -426,7 +419,6 @@ void BiMPPI::guideMPPI() {
426
419
double cost = 0.0 ;
427
420
for (int j = 0 ; j < Tr; ++j) {
428
421
cost += p (Xi.col (j), x_target);
429
- // cost += q(Xi.col(j), Ures.col(j));
430
422
Xi.col (j+1 ) = Xi.col (j) + (dt * f (Xi.col (j), Ures.col (j)));
431
423
}
432
424
cost += p (Xi.col (Tr), x_target);
@@ -457,16 +449,11 @@ void BiMPPI::guideMPPI() {
457
449
}
458
450
459
451
void BiMPPI::partitioningControl () {
460
- int T = Uo.cols ();
461
- int n = std::ceil (psi * (T-1 ));
462
-
463
- U_f0 = Uo.leftCols (std::min (n,T-1 ));
464
- // U_b0 = Eigen::MatrixXd::Zero(dim_u, std::min(n,T-1));
465
- U_b0 = Uo.rightCols (std::min (n,T-1 ));
452
+ U_f0 = Uo.leftCols (Tf);
453
+ U_b0 = Eigen::MatrixXd::Zero (dim_u, Tb);
466
454
}
467
455
468
456
void BiMPPI::dbscan (std::vector<std::vector<int >> &clusters, const Eigen::MatrixXd &Di, const Eigen::VectorXd &costs, const int &N, const int &T) {
469
- // void BiMPPI::dbscan(std::vector<std::vector<int>> &clusters, const Eigen::VectorXd &Di, const Eigen::VectorXd &costs, const int &N, const int &T) {
470
457
clusters.clear ();
471
458
std::vector<bool > core_points (N, false );
472
459
std::map<int , std::vector<int >> core_tree;
@@ -476,9 +463,7 @@ void BiMPPI::dbscan(std::vector<std::vector<int>> &clusters, const Eigen::Matrix
476
463
if (costs (i) > 1E7 ) {continue ;}
477
464
for (int j = i + 1 ; j < N; ++j) {
478
465
if (costs (j) > 1E7 ) {continue ;}
479
- // std::cout<<(Di.col(i) - Di.col(j)).norm()<<std::endl;
480
466
if (deviation_mu * (Di.col (i) - Di.col (j)).norm () < epsilon) {
481
- // if (deviation_mu * std::abs(Di(i) - Di(j)) < epsilon) {
482
467
#pragma omp critical
483
468
{
484
469
core_tree[i].push_back (j);
@@ -536,10 +521,11 @@ void BiMPPI::calculateU(Eigen::MatrixXd &U, const std::vector<std::vector<int>>
536
521
for (size_t i = 0 ; i < pts; ++i) {
537
522
U.middleRows (index * dim_u, dim_u) += (weights[i] / total_weight) * Ui.middleRows (clusters[index][i] * dim_u, dim_u);
538
523
}
524
+ h (U.middleRows (index * dim_u, dim_u));
539
525
}
540
526
}
541
527
542
- void BiMPPI:: show() {
528
+ void BiMPPI::show () {
543
529
namespace plt = matplotlibcpp;
544
530
// plt::subplot(1,2,1);
545
531
0 commit comments