52 auto front =
fast_nds(pop, island_pool);
53 for (
size_t i = 0; i< front.size(); i++)
58 vector<size_t> selected(0);
59 for (
int i = 0; i < island_pool.size(); ++i)
62 *
r.select_randomly(island_pool.begin(), island_pool.end()),
63 *
r.select_randomly(island_pool.begin(), island_pool.end()));
65 selected.push_back(winner);
77 std::vector<size_t> island_pool;
80 island_pool.insert(island_pool.end(), indexes.begin(), indexes.end());
84 auto front =
fast_nds(pop, island_pool);
87 vector<size_t> selected;
93 && ( selected.size() + front.at(i).size() < params.
pop_size )
96 std::vector<int>& Fi = front.at(i);
100 for (
int j = 0; j < Fi.size(); ++j)
101 selected.push_back(Fi.at(j));
108 std::sort(front.at(i).begin(),front.at(i).end(),
sort_n(pop));
111 const int extra = params.
pop_size - selected.size();
112 for (
int j = 0; j < extra; ++j)
113 selected.push_back(front.at(i).at(j));
126 vector<vector<int>> front;
131 for (
int i = 0; i < island_pool.size(); ++i) {
133 std::vector<unsigned int> dom;
138 for (
int j = 0; j < island_pool.size(); ++j) {
142 int compare = p->fitness.dominates(q.
fitness);
145 dom.push_back(island_pool[j]);
146 }
else if (compare == -1) {
151 p->fitness.dcounter = dcount;
152 p->fitness.dominated = dom;
155 if (p->fitness.dcounter == 0) {
157 p->fitness.set_rank(1);
159 front.at(0).push_back(island_pool[i]);
169 std::sort(front.at(0).begin(), front.at(0).end());
172 while (front.at(fi-1).size() > 0) {
173 std::vector<int>& fronti = front.at(fi-1);
175 for (
int i = 0; i < fronti.size(); ++i) {
186 q->fitness.dcounter -= 1;
188 if (q->fitness.dcounter == 0) {
191 q->fitness.set_rank(fi+1);
210 std::vector<int> F = front.at(fronti);
216 const int fsize = F.size();
219 for (
int i = 0; i < fsize; ++i)
220 pop.
individuals.at(F.at(i))->fitness.set_crowding_dist(0.0f);
224 const int limit = pop.
individuals.at(0)->fitness.get_wvalues().size();
227 for (
int m = 0; m < limit; ++m) {
234 pop.
individuals.at(F.at(0))->fitness.crowding_dist = std::numeric_limits<float>::max();
236 pop.
individuals.at(F.at(fsize-1))->fitness.crowding_dist = std::numeric_limits<float>::max();
238 float first_of_front = pop.
individuals.at(F.at(0))->fitness.get_wvalues().at(m);
239 float last_of_front = pop.
individuals.at(F.at(fsize-1))->fitness.get_wvalues().at(m);
240 for (
int i = 1; i < fsize-1; ++i)
242 if (pop.
individuals.at(F.at(i))->fitness.crowding_dist != std::numeric_limits<float>::max())
244 float next_of_front = pop.
individuals.at(F.at(i+1))->fitness.get_wvalues().at(m);
245 float prev_of_front = pop.
individuals.at(F.at(i-1))->fitness.get_wvalues().at(m);
248 pop.
individuals.at(F.at(i))->fitness.crowding_dist +=
249 (next_of_front - prev_of_front) / (last_of_front - first_of_front);