30 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_INDICATORS_NSGA3_INDICATOR_H 31 #define SHARK_ALGORITHMS_DIRECTSEARCH_INDICATORS_NSGA3_INDICATOR_H 44 template<
typename ParetofrontType,
typename ParetoArchive>
45 std::vector<std::size_t>
leastContributors(ParetofrontType
const& front, ParetoArchive
const& archive, std::size_t K)
const{
48 std::vector<RealVector> points;
49 for(
auto const& point: archive)
50 points.push_back(point);
51 for(
auto const& point: front)
52 points.push_back(point);
55 RealVector ideal = points.front();
56 for(
auto& point: points){
57 noalias(ideal) = min(ideal,point);
60 for(
auto& point: points)
61 noalias(point) = point - ideal;
62 RealVector normalizer = computeNormalizer(points);
65 for(
auto& point: points)
66 noalias(point) = point/ normalizer;
70 std::vector<Pair> pairing(points.size(),
makeKeyValuePair(std::numeric_limits<double>::max(),std::pair<std::size_t, std::size_t>()));
71 for(std::size_t j = 0; j != points.size(); ++j){
73 for(std::size_t i = 0; i != m_Z.size(); ++i){
78 double dist = norm_sqr(points[j]) -
sqr(inner_prod(m_Z[i],points[j]));
84 std::vector<std::size_t>
rho(m_Z.size(),0);
86 for(; k != archive.size(); ++k){
87 rho[pairing[k].value.second] ++;
90 while(k < points.size() - K){
92 std::size_t index = std::min_element(
rho.begin(),
rho.end()) -
rho.begin();
96 for(std::size_t i = k; i != points.size(); ++i){
97 if(pairing[i].value.second == index){
104 rho[index] = points.size() +1;
114 std::vector<std::size_t> unselected;
115 for(; k != points.size(); ++k){
116 SIZE_CHECK(pairing[k].value.first >= archive.size());
117 unselected.push_back(pairing[k].value.first - archive.size());
123 template<
typename Archive>
136 template<
class random>
137 void init(std::size_t numOfObjectives,
140 std::vector<Preference>
const & preferences = std::vector<Preference>()){
143 if(preferences.empty())
153 numOfObjectives, numLatticeTicks, preferences);
158 m_Z.resize(refs.size1());
159 for(std::size_t i = 0; i < refs.size1(); ++i){
160 m_Z[i] = row(refs, i);
164 std::vector<RealVector> m_Z;
169 RealVector computeNormalizer(std::vector<RealVector>
const& points)
const{
171 double epsilon = 0.00001;
172 std::size_t dimensions = points.front().size();
173 RealMatrix cornerPoints(dimensions, dimensions,0.0);
174 for(std::size_t dim = 0; dim != dimensions; ++dim){
176 for(std::size_t i = 0; i != points.size(); ++i){
177 auto const& point = points[i];
178 double dist = epsilon * sum(point) + (1-epsilon) * point[dim];
181 noalias(row(cornerPoints,dim)) = points[best.
value];
188 RealMatrix A = trans((cornerPoints|1)) % (cornerPoints|1);
189 RealVector b = trans((cornerPoints|1)) % blas::repeat(-1.0,dimensions);
190 blas::symm_pos_semi_definite_solver<RealMatrix> solver(A);
191 if(solver.rank() == dimensions){
192 solver.solve(b, blas::left());
193 RealVector
w = subrange(b,0,dimensions);
195 return blas::repeat(1.0,dimensions)/
w;
202 RealVector nadir = points.front();
203 for(
auto& point: points){
204 noalias(nadir) = max(nadir,point);