From fd5ecd00232db7647852bd67c15c5726320cba8c Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 14 Mar 2021 07:53:29 +0530 Subject: [PATCH] styling fix --- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 40 +++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 6feb4d78f..c33a4b844 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -189,7 +189,7 @@ typename MatType::elem_type NSGA2::Optimize( ElemType performance = std::numeric_limits::max(); - for(const arma::Col& objective: populationFval) + for (const arma::Col& objective: populationFval) if (arma::accu(objective) < performance) performance = arma::accu(objective); @@ -396,37 +396,39 @@ inline void NSGA2::CrowdingDistanceAssignment( std::vector& crowdingDistance) { size_t fSize = front.size(); - std::vector sortedIdx(fSize); // Stores the sorted indices of the fronts. + // Stores the sorted indices of the fronts. + std::vector sortedIdx(fSize); std::iota(sortedIdx.begin(), sortedIdx.end(), 0u); for (size_t m = 0; m < numObjectives; m++) { - std::vector fValues{}; - std::transform( // Cache the Fvalues of individuals for current objective. - front.begin(), front.end(), std::back_inserter(fValues), - [&](const size_t& individual) { - return populationFval[individual](m); - }); - - // Sort the front indices based on ascending FValue of the current objective. + // Cache Fvalues of individuals for current objective. + arma::vec fValues(fSize); + std::transform(front.begin(), front.end(), fValues.begin(), + [&](const size_t& individual) + { + return populationFval[individual](m); + }); + + // Sort front indices by ascending FValue for current objective. std::sort(sortedIdx.begin(), sortedIdx.end(), - [&](const size_t& frontIdxA, const size_t& frontIdxB) { - return (fValues[frontIdxA] < - fValues[frontIdxB]); - }); + [&](const size_t& frontIdxA, const size_t& frontIdxB) + { + return (fValues[frontIdxA] < fValues[frontIdxB]); + }); - crowdingDistance[front[sortedIdx[0]]] = std::numeric_limits::infinity(); + crowdingDistance[front[sortedIdx[0]]] = + std::numeric_limits::infinity(); crowdingDistance[front[sortedIdx[fSize - 1]]] = - std::numeric_limits::infinity(); + std::numeric_limits::infinity(); double minFval = *(std::min_element(fValues.begin(), fValues.end())); double maxFval = *(std::max_element(fValues.begin(), fValues.end())); double scale = (maxFval == minFval) ? 1 : maxFval - minFval; for (size_t i = 1; i < fSize - 1; i++) { - crowdingDistance[front[sortedIdx[i]]] += - (fValues[sortedIdx[i + 1]] - fValues[sortedIdx[i - 1]]) / - scale; + crowdingDistance[front[sortedIdx[i]]] += + (fValues[sortedIdx[i + 1]] - fValues[sortedIdx[i - 1]]) / scale; } } }