@@ -34,7 +34,8 @@ class BiMPPI {
34
34
void guideMPPI ();
35
35
void partitioningControl ();
36
36
37
- void dbscan (std::vector<std::vector<int >> &clusters, const Eigen::VectorXd &Di, const Eigen::VectorXd &costs, const int &N, const int &T);
37
+ void dbscan (std::vector<std::vector<int >> &clusters, const Eigen::MatrixXd &Di, const Eigen::VectorXd &costs, const int &N, const int &T);
38
+ // void dbscan(std::vector<std::vector<int>> &clusters, const Eigen::VectorXd &Di, const Eigen::VectorXd &costs, const int &N, const int &T);
38
39
void calculateU (Eigen::MatrixXd &U, const std::vector<std::vector<int >> &clusters, const Eigen::VectorXd &costs, const Eigen::MatrixXd &Ui, const int &T);
39
40
void show ();
40
41
void showTraj ();
@@ -187,16 +188,19 @@ void BiMPPI::solve() {
187
188
// elapsed_1 = finish - start;
188
189
// std::cout<<"Fir = "<<elapsed_1.count()<<std::endl;
189
190
191
+ std::cout<<" a" <<std::endl;
190
192
start = std::chrono::high_resolution_clock::now ();
191
193
backwardRollout ();
192
194
forwardRollout ();
193
195
finish = std::chrono::high_resolution_clock::now ();
194
196
elapsed_1 = finish - start;
195
197
// std::cout<<"Sec = "<<elapsed_1.count()<<std::endl;
196
198
199
+ std::cout<<" b" <<std::endl;
197
200
// 2. Select Connection
198
201
start = std::chrono::high_resolution_clock::now ();
199
202
selectConnection ();
203
+ std::cout<<" c" <<std::endl;
200
204
concatenate ();
201
205
finish = std::chrono::high_resolution_clock::now ();
202
206
elapsed_2 = finish - start;
@@ -206,6 +210,7 @@ void BiMPPI::solve() {
206
210
guideMPPI ();
207
211
finish = std::chrono::high_resolution_clock::now ();
208
212
elapsed_3 = finish - start;
213
+ std::cout<<" d" <<std::endl;
209
214
210
215
// 4. Partitioning Control
211
216
start = std::chrono::high_resolution_clock::now ();
@@ -220,7 +225,8 @@ void BiMPPI::solve() {
220
225
221
226
void BiMPPI::backwardRollout () {
222
227
Eigen::MatrixXd Ui = U_b0.replicate (Nb, 1 );
223
- Eigen::VectorXd Di (Nb);
228
+ Eigen::MatrixXd Di (dim_u, Nb);
229
+ // Eigen::VectorXd Di(Nf);
224
230
Eigen::VectorXd costs (Nb);
225
231
bool all_feasible = true ;
226
232
#pragma omp parallel for
@@ -242,15 +248,15 @@ void BiMPPI::backwardRollout() {
242
248
cost += p (Xi.col (j), x_init);
243
249
}
244
250
cost += p (Xi.col (0 ), x_init);
245
- for (int j = 0 ; j <= Tb; ++ j) {
251
+ for (int j = Tb ; j >= 0 ; -- j) {
246
252
if (collision_checker->getCollisionGrid (Xi.col (j))) {
247
- cost = 1e8 ;
248
253
all_feasible = false ;
254
+ cost = 1e8 ;
249
255
break ;
250
256
}
251
257
}
252
258
costs (i) = cost;
253
- Di (i) = Xi. row (dim_x - 1 ).mean ();
259
+ Di. col (i) = (Ui. middleRows (i * dim_u, dim_u) - U_b0). rowwise ( ).mean ();
254
260
}
255
261
256
262
if (!all_feasible) {dbscan (clusters_b, Di, costs, Nb, Tb);}
@@ -275,7 +281,8 @@ void BiMPPI::backwardRollout() {
275
281
276
282
void BiMPPI::forwardRollout () {
277
283
Eigen::MatrixXd Ui = U_f0.replicate (Nf, 1 );
278
- Eigen::VectorXd Di (Nf);
284
+ Eigen::MatrixXd Di (dim_u, Nf);
285
+ // Eigen::VectorXd Di(Nf);
279
286
Eigen::VectorXd costs (Nf);
280
287
bool all_feasible = true ;
281
288
#pragma omp parallel for
@@ -296,11 +303,12 @@ void BiMPPI::forwardRollout() {
296
303
if (collision_checker->getCollisionGrid (Xi.col (j))) {
297
304
all_feasible = false ;
298
305
cost = 1e8 ;
306
+ // std::cout<<"F = "<<cost<<std::endl;
299
307
break ;
300
308
}
301
309
}
302
310
costs (i) = cost;
303
- Di (i) = Xi. row (dim_x - 1 ).mean ();
311
+ Di. col (i) = (Ui. middleRows (i * dim_u, dim_u) - U_f0). rowwise ( ).mean ();
304
312
}
305
313
306
314
if (!all_feasible) {dbscan (clusters_f, Di, costs, Nf, Tf);}
@@ -324,7 +332,7 @@ void BiMPPI::selectConnection() {
324
332
double min_norm = std::numeric_limits<double >::max ();
325
333
int cb, df, db;
326
334
for (int cb_ = 0 ; cb_ < clusters_b.size (); ++cb_) {
327
- for (int df_ = 1 ; df_ < Tf; ++df_) {
335
+ for (int df_ = 1 ; df_ < Tf- 1 ; ++df_) {
328
336
for (int db_ = 0 ; db_ < Tb-1 ; ++db_) {
329
337
double norm = (Xf.block (cf * dim_x, df_, dim_x, 1 ) - Xb.block (cb_ * dim_x, db_, dim_x, 1 )).norm ();
330
338
if (norm < min_norm) {
@@ -336,6 +344,7 @@ void BiMPPI::selectConnection() {
336
344
}
337
345
}
338
346
}
347
+ // std::cout << "F: " << clusters_b.size() << ", B: " << clusters_b.size() << ", cf: " << cf << ", cb: " << cb << ", df: " << df << ", db: " << db << std::endl;
339
348
joints.push_back ({cf, cb, df, db});
340
349
}
341
350
}
@@ -349,6 +358,7 @@ void BiMPPI::concatenate() {
349
358
int cb = joint[1 ];
350
359
int df = joint[2 ];
351
360
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;
352
362
353
363
Eigen::MatrixXd U (dim_u, df + (Tb - db) + 1 );
354
364
Eigen::MatrixXd X (dim_x, df + (Tb - db) + 2 );
@@ -451,10 +461,12 @@ void BiMPPI::partitioningControl() {
451
461
int n = std::ceil (psi * (T-1 ));
452
462
453
463
U_f0 = Uo.leftCols (std::min (n,T-1 ));
464
+ // U_b0 = Eigen::MatrixXd::Zero(dim_u, std::min(n,T-1));
454
465
U_b0 = Uo.rightCols (std::min (n,T-1 ));
455
466
}
456
467
457
- void BiMPPI::dbscan (std::vector<std::vector<int >> &clusters, const Eigen::VectorXd &Di, const Eigen::VectorXd &costs, const int &N, const int &T) {
468
+ 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) {
458
470
clusters.clear ();
459
471
std::vector<bool > core_points (N, false );
460
472
std::map<int , std::vector<int >> core_tree;
@@ -464,7 +476,9 @@ void BiMPPI::dbscan(std::vector<std::vector<int>> &clusters, const Eigen::Vector
464
476
if (costs (i) > 1E7 ) {continue ;}
465
477
for (int j = i + 1 ; j < N; ++j) {
466
478
if (costs (j) > 1E7 ) {continue ;}
467
- if (deviation_mu * std::abs (Di (i) - Di (j)) < epsilon) {
479
+ // std::cout<<(Di.col(i) - Di.col(j)).norm()<<std::endl;
480
+ if (deviation_mu * (Di.col (i) - Di.col (j)).norm () < epsilon) {
481
+ // if (deviation_mu * std::abs(Di(i) - Di(j)) < epsilon) {
468
482
#pragma omp critical
469
483
{
470
484
core_tree[i].push_back (j);
@@ -525,7 +539,7 @@ void BiMPPI::calculateU(Eigen::MatrixXd &U, const std::vector<std::vector<int>>
525
539
}
526
540
}
527
541
528
- void BiMPPI::show () {
542
+ void BiMPPI:: show() {
529
543
namespace plt = matplotlibcpp;
530
544
// plt::subplot(1,2,1);
531
545
@@ -584,28 +598,28 @@ void BiMPPI::show() {
584
598
// }
585
599
// }
586
600
587
- // for (int index = 0; index < clusters_f.size(); ++index) {
588
- // std::vector<std::vector<double>> X_MPPI(dim_x, std::vector<double>(Tf));
589
- // for (int i = 0; i < dim_x; ++i) {
590
- // for (int j = 0; j < Tf + 1; ++j) {
591
- // X_MPPI[i][j] = Xf(index * dim_x + i, j);
592
- // }
593
- // }
594
- // std::string color = "C" + std::to_string(index%10);
595
- // plt::plot(X_MPPI[0], X_MPPI[1], {{"color", color}, {"linewidth", "10.0"}});
596
- // }
597
-
598
- // for (int index = 0; index < clusters_b.size(); ++index) {
599
- // std::vector<std::vector<double>> X_MPPI(dim_x, std::vector<double>(Tb));
600
- // for (int i = 0; i < dim_x; ++i) {
601
- // for (int j = 0; j < Tb + 1; ++j) {
602
- // X_MPPI[i][j] = Xb(index * dim_x + i, j);
603
- // }
604
- // }
605
- // std::string color = "C" + std::to_string(index%10);
606
- // plt::plot(X_MPPI[0], X_MPPI[1], {{"color", color}, {"linewidth", "10.0"}});
607
- // }
601
+ for (int index = 0 ; index < clusters_f.size (); ++index) {
602
+ std::vector<std::vector<double >> F_BRANCH (dim_x, std::vector<double >(Tf+1 ));
603
+ for (int i = 0 ; i < dim_x; ++i) {
604
+ for (int j = 0 ; j < Tf + 1 ; ++j) {
605
+ F_BRANCH[i][j] = Xf (index * dim_x + i, j);
606
+ }
607
+ }
608
+ std::string color = " C" + std::to_string (index%10 );
609
+ plt::plot (F_BRANCH[0 ], F_BRANCH[1 ], {{" color" , color}, {" linewidth" , " 10.0" }});
610
+ }
608
611
612
+ for (int index = 0 ; index < clusters_b.size (); ++index) {
613
+ std::vector<std::vector<double >> B_BRANCH (dim_x, std::vector<double >(Tb+1 ));
614
+ for (int i = 0 ; i < dim_x; ++i) {
615
+ for (int j = 0 ; j < Tb + 1 ; ++j) {
616
+ B_BRANCH[i][j] = Xb (index * dim_x + i, j);
617
+ }
618
+ }
619
+ std::string color = " C" + std::to_string (index%10 );
620
+ plt::plot (B_BRANCH[0 ], B_BRANCH[1 ], {{" color" , color}, {" linewidth" , " 10.0" }});
621
+ }
622
+
609
623
// // plt::xlim(0, 3);
610
624
// // plt::ylim(0, 5);
611
625
// // plt::grid(true);
0 commit comments