Various changes and optimizations
This commit is contained in:
parent
373c26caba
commit
36c14fed9e
8 changed files with 366 additions and 145 deletions
|
|
@ -1,6 +1,8 @@
|
|||
#include <eoNSGA_II_Eval.h>
|
||||
|
||||
namespace nsga2 {
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef std::pair<double, unsigned> double_index_pair;
|
||||
|
||||
|
|
@ -15,8 +17,6 @@ namespace nsga2 {
|
|||
|
||||
void assign_worths(const std::vector<detail::FitnessInfo>& front, unsigned rank, std::vector<double>& worths) {
|
||||
|
||||
unsigned i;
|
||||
|
||||
unsigned nObjectives = front[0].fitness.size(); //traits::nObjectives(); //_pop[_cf[0]].fitness().size();
|
||||
|
||||
std::vector<double> niche_distance(front.size());
|
||||
|
|
@ -25,7 +25,7 @@ namespace nsga2 {
|
|||
{
|
||||
|
||||
std::vector<std::pair<double, unsigned> > performance(front.size());
|
||||
for (i =0; i < front.size(); ++i)
|
||||
for (unsigned i =0; i < front.size(); ++i)
|
||||
{
|
||||
performance[i].first = front[i].fitness[o];
|
||||
performance[i].second = i;
|
||||
|
|
@ -35,16 +35,18 @@ namespace nsga2 {
|
|||
|
||||
std::vector<double> nc(front.size(), 0.0);
|
||||
|
||||
for (i = 1; i < front.size()-1; ++i)
|
||||
for (unsigned i = 1; i < front.size()-1; ++i)
|
||||
{ // and yet another level of indirection
|
||||
|
||||
nc[performance[i].second] = performance[i+1].first - performance[i-1].first;
|
||||
|
||||
}
|
||||
|
||||
// set boundary at max_dist + 1 (so it will get chosen over all the others
|
||||
//nc[performance[0].second] += 0;
|
||||
nc[performance.back().second] += std::numeric_limits<double>::infinity(); // best on objective
|
||||
nc[performance.back().second] = std::numeric_limits<double>::infinity(); // best on objective
|
||||
|
||||
for (i = 0; i < nc.size(); ++i)
|
||||
for (unsigned i = 0; i < nc.size(); ++i)
|
||||
{
|
||||
niche_distance[i] += nc[i];
|
||||
}
|
||||
|
|
@ -53,12 +55,12 @@ namespace nsga2 {
|
|||
// now we've got niche_distances, scale them between (0, 1), making sure that infinities get maximum rank
|
||||
|
||||
double max = 0;
|
||||
for (unsigned i = 0; i < niche_distance[i]; ++i) {
|
||||
for (unsigned i = 0; i < niche_distance.size(); ++i) {
|
||||
if (niche_distance[i] != std::numeric_limits<double>::infinity()) {
|
||||
max = std::max(max, niche_distance[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (unsigned i = 0; i < front.size(); ++i) {
|
||||
double dist = niche_distance[i];
|
||||
if (dist == std::numeric_limits<double>::infinity()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue