@@ -34,14 +34,14 @@ void ttk::PDBarycenter::runMatching(
3434 std::vector<std::vector<MatchingType>> *all_matchings,
3535 bool use_kdt,
3636 bool actual_distance) {
37- Timer time_matchings;
37+ Timer const time_matchings;
3838
3939 double local_cost = *total_cost;
4040#ifdef TTK_ENABLE_OPENMP
4141#pragma omp parallel for num_threads(threadNumber_) schedule(dynamic, 1) reduction(+:local_cost)
4242#endif
4343 for (int i = 0 ; i < numberOfInputs_; i++) {
44- double delta_lim = 0.01 ;
44+ double const delta_lim = 0.01 ;
4545 PersistenceDiagramAuction auction (
4646 current_bidder_diagrams_[i], barycenter_goods_[i], wasserstein_,
4747 geometrical_factor_, lambda_, delta_lim, kdt, correspondence_kdt_map,
@@ -56,15 +56,16 @@ void ttk::PDBarycenter::runMatching(
5656 min_diag_price->at (i) = auction.getMinimalDiagonalPrice ();
5757 min_price->at (i) = getMinimalPrice (i);
5858 std::vector<MatchingType> matchings;
59- double cost = auction.getMatchingsAndDistance (matchings, true );
59+ double const cost = auction.getMatchingsAndDistance (matchings, true );
6060 all_matchings->at (i) = matchings;
6161 if (actual_distance) {
6262 local_cost += sqrt (cost);
6363 } else {
6464 local_cost += cost;
6565 }
6666
67- double quotient = epsilon * auction.getAugmentedNumberOfBidders () / cost;
67+ double const quotient
68+ = epsilon * auction.getAugmentedNumberOfBidders () / cost;
6869 precision_[i] = quotient < 1 ? 1 . / sqrt (1 - quotient) - 1 : 10 ;
6970 if (auction.getRelativePrecision () == 0 )
7071 precision_[i] = 0 ;
@@ -95,7 +96,7 @@ void ttk::PDBarycenter::runMatchingAuction(
9596 geometrical_factor_, lambda_, 0.01 , kdt, correspondence_kdt_map, 0 ,
9697 (*min_diag_price)[i], use_kdt);
9798 std::vector<MatchingType> matchings;
98- double cost = auction.run (matchings, i);
99+ double const cost = auction.run (matchings, i);
99100 all_matchings->at (i) = matchings;
100101 if (actual_distance) {
101102 local_cost += sqrt (cost);
@@ -140,7 +141,7 @@ std::vector<std::vector<ttk::MatchingType>> ttk::PDBarycenter::correctMatchings(
140141 // 1. Invert the current_bidder_ids_ vector
141142 std::vector<int > new_to_old_id (current_bidder_diagrams_[i].size ());
142143 for (size_t j = 0 ; j < current_bidder_ids_[i].size (); j++) {
143- int new_id = current_bidder_ids_[i][j];
144+ int const new_id = current_bidder_ids_[i][j];
144145 if (new_id >= 0 ) {
145146 new_to_old_id[new_id] = j;
146147 }
@@ -149,7 +150,7 @@ std::vector<std::vector<ttk::MatchingType>> ttk::PDBarycenter::correctMatchings(
149150 std::vector<MatchingType> matchings_diagram_i;
150151 for (size_t j = 0 ; j < previous_matchings[i].size (); j++) {
151152 MatchingType m = previous_matchings[i][j];
152- int new_id = std::get<0 >(m);
153+ int const new_id = std::get<0 >(m);
153154 if (new_id >= 0 && std::get<1 >(m) >= 0 ) {
154155 std::get<0 >(m) = new_to_old_id[new_id];
155156 matchings_diagram_i.push_back (m);
@@ -163,10 +164,10 @@ std::vector<std::vector<ttk::MatchingType>> ttk::PDBarycenter::correctMatchings(
163164double ttk::PDBarycenter::updateBarycenter (
164165 std::vector<std::vector<MatchingType>> &matchings) {
165166 // 1. Initialize variables used in the sequel
166- Timer t_update;
167- size_t n_goods = barycenter_goods_[0 ].size ();
167+ Timer const t_update;
168+ size_t const n_goods = barycenter_goods_[0 ].size ();
168169
169- size_t n_diagrams = current_bidder_diagrams_.size ();
170+ size_t const n_diagrams = current_bidder_diagrams_.size ();
170171 points_added_ = 0 ;
171172 points_deleted_ = 0 ;
172173 double max_shift = 0 ;
@@ -203,8 +204,8 @@ double ttk::PDBarycenter::updateBarycenter(
203204 for (size_t j = 0 ; j < matchings.size (); j++) {
204205 double weight = useCustomWeights_ ? (*customWeights_)[j] : 0.0 ;
205206 for (size_t i = 0 ; i < matchings[j].size (); i++) {
206- int bidder_id = std::get<0 >(matchings[j][i]);
207- int good_id = std::get<1 >(matchings[j][i]);
207+ int const bidder_id = std::get<0 >(matchings[j][i]);
208+ int const good_id = std::get<1 >(matchings[j][i]);
208209 if (good_id < 0 && bidder_id >= 0 ) {
209210 // Future new barycenter point
210211 points_to_append.emplace_back (
@@ -282,19 +283,19 @@ double ttk::PDBarycenter::updateBarycenter(
282283 }
283284
284285 // TODO Weight by persistence
285- double new_crit_coord_x
286+ double const new_crit_coord_x
286287 = crit_coords_x[i] / (double )(n_diagrams - count_diag_matchings[i]);
287- double new_crit_coord_y
288+ double const new_crit_coord_y
288289 = crit_coords_y[i] / (double )(n_diagrams - count_diag_matchings[i]);
289- double new_crit_coord_z
290+ double const new_crit_coord_z
290291 = crit_coords_z[i] / (double )(n_diagrams - count_diag_matchings[i]);
291292
292293 // 3.3 Compute and store how much the point has shifted
293294 // TODO adjust shift with geometrical_factor_
294- double dx = barycenter_goods_[0 ].at (i).x_ - new_x;
295- double dy = barycenter_goods_[0 ].at (i).y_ - new_y;
296- double shift = Geometry::pow (std::abs (dx), wasserstein_)
297- + Geometry::pow (std::abs (dy), wasserstein_);
295+ double const dx = barycenter_goods_[0 ].at (i).x_ - new_x;
296+ double const dy = barycenter_goods_[0 ].at (i).y_ - new_y;
297+ double const shift = Geometry::pow (std::abs (dx), wasserstein_)
298+ + Geometry::pow (std::abs (dy), wasserstein_);
298299 if (shift > max_shift) {
299300 max_shift = shift;
300301 }
@@ -323,7 +324,7 @@ double ttk::PDBarycenter::updateBarycenter(
323324 for (size_t i = 0 ; i < n_goods; i++) {
324325 if (count_diag_matchings[i] == n_diagrams) {
325326 points_deleted_ += 1 ;
326- double shift
327+ double const shift
327328 = 2
328329 * Geometry::pow (
329330 barycenter_goods_[0 ].at (i).getPersistence () / 2 ., wasserstein_);
@@ -360,7 +361,7 @@ double ttk::PDBarycenter::updateBarycenter(
360361 std::get<2 >(critical_coordinates));
361362 }
362363 barycenter_goods_[j].emplace_back (g);
363- double shift
364+ double const shift
364365 = 2
365366 * Geometry::pow (
366367 barycenter_goods_[j].at (g.id_ ).getPersistence () / 2 ., wasserstein_);
@@ -440,7 +441,7 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams(
440441 max_diagram_size = current_bidder_diagrams_[i].size ();
441442 }
442443 }
443- int max_points_to_add = std::max (
444+ int const max_points_to_add = std::max (
444445 min_points_to_add, min_points_to_add + (int )(max_diagram_size / 10 ));
445446
446447 // 2. Get which points can be added, deduce the new minimal persistence
@@ -450,8 +451,8 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams(
450451
451452 std::vector<double > persistences;
452453 for (size_t j = 0 ; j < bidder_diagrams_[i].size (); j++) {
453- Bidder b = bidder_diagrams_[i].at (j);
454- double persistence = b.getPersistence ();
454+ Bidder const b = bidder_diagrams_[i].at (j);
455+ double const persistence = b.getPersistence ();
455456 if (persistence >= min_persistence
456457 && persistence < previous_min_persistence) {
457458 candidates_to_be_added[i].push_back (j);
@@ -463,9 +464,9 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams(
463464 return ((persistences[a] > persistences[b])
464465 || ((persistences[a] == persistences[b]) && (a > b)));
465466 });
466- int size = candidates_to_be_added[i].size ();
467+ int const size = candidates_to_be_added[i].size ();
467468 if (size >= max_points_to_add) {
468- double last_persistence_added
469+ double const last_persistence_added
469470 = persistences[idx[i][max_points_to_add - 1 ]];
470471 if (last_persistence_added > new_min_persistence) {
471472 new_min_persistence = last_persistence_added;
@@ -479,7 +480,7 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams(
479480 int compteur_for_adding_points = 0 ;
480481
481482 for (int i = 0 ; i < numberOfInputs_; i++) {
482- int size = candidates_to_be_added[i].size ();
483+ int const size = candidates_to_be_added[i].size ();
483484 for (int j = 0 ; j < std::min (max_points_to_add, size); j++) {
484485 Bidder b = bidder_diagrams_[i].at (candidates_to_be_added[i][idx[i][j]]);
485486 if (b.getPersistence () >= new_min_persistence) {
@@ -491,7 +492,7 @@ double ttk::PDBarycenter::enrichCurrentBidderDiagrams(
491492 current_bidder_ids_[i][candidates_to_be_added[i][idx[i][j]]]
492493 = current_bidder_diagrams_[i].size () - 1 ;
493494
494- int to_be_added_to_barycenter
495+ int const to_be_added_to_barycenter
495496 = deterministic_ ? compteur_for_adding_points % numberOfInputs_
496497 : rand () % numberOfInputs_;
497498 // We add the bidder as a good with probability 1/n_diagrams
@@ -516,8 +517,8 @@ double ttk::PDBarycenter::getMaxPersistence() {
516517 BidderDiagram &D = bidder_diagrams_[i];
517518 for (size_t j = 0 ; j < D.size (); j++) {
518519 // Add bidder to bidders
519- Bidder &b = D.at (j);
520- double persistence = b.getPersistence ();
520+ Bidder const &b = D.at (j);
521+ double const persistence = b.getPersistence ();
521522 if (persistence > max_persistence) {
522523 max_persistence = persistence;
523524 }
@@ -534,8 +535,8 @@ double ttk::PDBarycenter::getMinimalPrice(int i) {
534535 return 0 ;
535536 }
536537 for (size_t j = 0 ; j < D.size (); j++) {
537- Good &b = D.at (j);
538- double price = b.getPrice ();
538+ Good const &b = D.at (j);
539+ double const price = b.getPrice ();
539540 if (price < min_price) {
540541 min_price = price;
541542 }
@@ -552,8 +553,8 @@ double ttk::PDBarycenter::getLowestPersistence() {
552553 BidderDiagram &D = bidder_diagrams_[i];
553554 for (size_t j = 0 ; j < D.size (); j++) {
554555 // Add bidder to bidders
555- Bidder &b = D.at (j);
556- double persistence = b.getPersistence ();
556+ Bidder const &b = D.at (j);
557+ double const persistence = b.getPersistence ();
557558 if (persistence < lowest_persistence && persistence > 0 ) {
558559 lowest_persistence = persistence;
559560 }
@@ -579,7 +580,7 @@ void ttk::PDBarycenter::setInitialBarycenter(double min_persistence) {
579580 int count = 0 ;
580581 for (size_t j = 0 ; j < CTDiagram->size (); j++) {
581582 // Add bidder to bidders
582- Good g = Good ((*CTDiagram)[j], count, lambda_);
583+ Good const g = Good ((*CTDiagram)[j], count, lambda_);
583584 if (g.getPersistence () >= min_persistence) {
584585 goods.emplace_back (g);
585586 count++;
@@ -617,7 +618,7 @@ typename ttk::PDBarycenter::KDTreePair ttk::PDBarycenter::getKDTree() const {
617618 }
618619
619620 for (size_t idx = 0 ; idx < barycenter_goods_.size (); idx++) {
620- std::vector<double > empty_weights;
621+ std::vector<double > const empty_weights;
621622 weights.push_back (empty_weights);
622623 for (size_t i = 0 ; i < barycenter_goods_[idx].size (); i++) {
623624 const Good &g = barycenter_goods_[idx].at (i);
@@ -638,15 +639,15 @@ std::vector<std::vector<ttk::MatchingType>>
638639 ttk::PDBarycenter::executeAuctionBarycenter (DiagramType &barycenter) {
639640
640641 std::vector<std::vector<MatchingType>> previous_matchings;
641- double min_persistence = 0 ;
642+ double const min_persistence = 0 ;
642643 double min_cost = std::numeric_limits<double >::max ();
643644 int last_min_cost_obtained = 0 ;
644645
645646 this ->setBidderDiagrams ();
646647 this ->setInitialBarycenter (
647648 min_persistence); // false for a determinist initialization
648649
649- double max_persistence = getMaxPersistence ();
650+ double const max_persistence = getMaxPersistence ();
650651
651652 std::vector<double > min_diag_price (numberOfInputs_);
652653 std::vector<double > min_price (numberOfInputs_);
@@ -655,7 +656,7 @@ std::vector<std::vector<ttk::MatchingType>>
655656 min_price[i] = 0 ;
656657 }
657658
658- int min_points_to_add = std::numeric_limits<int >::max ();
659+ int const min_points_to_add = std::numeric_limits<int >::max ();
659660 this ->enrichCurrentBidderDiagrams (2 * max_persistence, min_persistence,
660661 min_diag_price, min_price,
661662 min_points_to_add, false );
@@ -665,7 +666,7 @@ std::vector<std::vector<ttk::MatchingType>>
665666 double total_cost;
666667
667668 while (!finished) {
668- Timer tm;
669+ Timer const tm;
669670
670671 std::pair<std::unique_ptr<KDT>, std::vector<KDT *>> pair;
671672 bool use_kdt = false ;
@@ -686,13 +687,13 @@ std::vector<std::vector<ttk::MatchingType>>
686687
687688 barycenter.clear ();
688689 for (size_t j = 0 ; j < barycenter_goods_[0 ].size (); j++) {
689- Good &g = barycenter_goods_[0 ].at (j);
690+ Good const &g = barycenter_goods_[0 ].at (j);
690691 barycenter.emplace_back (PersistencePair{CriticalVertex{0 , nt1_, g.x_ , {}},
691692 CriticalVertex{0 , nt2_, g.y_ , {}},
692693 diagramType_, true });
693694 }
694695
695- bool actual_distance = (numberOfInputs_ == 2 );
696+ bool const actual_distance = (numberOfInputs_ == 2 );
696697 runMatchingAuction (&total_cost, sizes, *pair.first , pair.second ,
697698 &min_diag_price, &all_matchings, use_kdt,
698699 actual_distance);
@@ -737,7 +738,7 @@ std::vector<std::vector<ttk::MatchingType>>
737738 }
738739 barycenter.resize (0 );
739740 for (size_t j = 0 ; j < barycenter_goods_[0 ].size (); j++) {
740- Good &g = barycenter_goods_[0 ].at (j);
741+ Good const &g = barycenter_goods_[0 ].at (j);
741742 barycenter.emplace_back (PersistencePair{CriticalVertex{0 , nt1_, g.x_ , {}},
742743 CriticalVertex{0 , nt2_, g.y_ , {}},
743744 diagramType_, true });
@@ -755,10 +756,10 @@ double ttk::PDBarycenter::computeRealCost() {
755756 for (int i = 0 ; i < numberOfInputs_; i++) {
756757 PersistenceDiagramAuction auction (
757758 wasserstein_, geometrical_factor_, lambda_, 0.01 , true );
758- GoodDiagram current_barycenter = barycenter_goods_[0 ];
759- BidderDiagram current_bidder_diagram = bidder_diagrams_[i];
759+ GoodDiagram const current_barycenter = barycenter_goods_[0 ];
760+ BidderDiagram const current_bidder_diagram = bidder_diagrams_[i];
760761 auction.BuildAuctionDiagrams (current_bidder_diagram, current_barycenter);
761- double cost = auction.run (fake_matchings);
762+ double const cost = auction.run (fake_matchings);
762763 total_real_cost += cost * cost;
763764 }
764765 return sqrt (total_real_cost);
@@ -773,7 +774,7 @@ bool ttk::PDBarycenter::isPrecisionObjectiveMet(double precision_objective,
773774 }
774775 }
775776 } else if (mode == 1 ) { // AVERAGE PRECISION
776- double average_precision
777+ double const average_precision
777778 = std::accumulate (precision_.begin (), precision_.end (), 0.0 )
778779 / numberOfInputs_;
779780 if (average_precision > precision_objective) {
0 commit comments