Skip to content
Snippets Groups Projects
Commit 903d04b9 authored by Caron Olivier's avatar Caron Olivier
Browse files

nsga-2 first version

parent b3abf807
Branches
No related tags found
No related merge requests found
......@@ -16,8 +16,8 @@ add_executable(NWFSP nwfsp.cpp)
add_executable(TSP tspMonoObjective.cpp)
add_executable(bTSP tspBiObjective.cpp)
add_executable(TSPTIMEWINDOW tspTimeWindow.cpp)
add_executable(archiveBiObjectiveTSP archiveBiObjectiveTSP.cpp
../src/opt/manySolutions/geneticAlgorithm/NSGA2_Solution.h)
add_executable(archiveBiObjectiveTSP archiveBiObjectiveTSP.cpp)
add_executable(tspNSGA2BiObjective tspNSGA2BiObjective.cpp)
add_executable(tspGreedy tspGreedy.cpp)
#add_executable(TSPTIMEWINDOW2 tspTimeWindow2.cpp)
......
......@@ -34,6 +34,7 @@ Authors: Olivier Caron and additional contributors (see Authors)
#include "opt/manySolutions/geneticAlgorithm/selection/TournamentSelection.h"
#include <vector>
#include <cassert>
namespace opt::manySolutions::geneticAlgorithm {
/**
......@@ -103,6 +104,7 @@ namespace opt::manySolutions::geneticAlgorithm {
this->replacement->operator()(sol, this->mutation->getOffspring());
this->criterion->update();
this->checkpoint->operator()(sol);
}
}
......
......@@ -46,14 +46,12 @@ namespace opt::manySolutions::geneticAlgorithm {
* simple constructor from a given initial solution
**/
NSGA2_Solution(SOL &_ind) : ind(_ind), rank(0), crowdingDistance(0.0), n(0) {
S.clear();
// S.clear();
}
/**
* default empty constructor
**/
NSGA2_Solution() : ind(NULL) ,rank(0),crowdingDistance(0.0), n(0) { S.clear() ;}
NSGA2_Solution(int sol_size) : ind(sol_size) , rank(0), crowdingDistance(0.0), n(0) {}
NSGA2_Solution() = default ;
/**
* default destructor
......@@ -429,11 +427,11 @@ namespace opt::manySolutions::geneticAlgorithm {
protected:
SOL ind;
unsigned long long int rank; // the calculated rank
double crowdingDistance;
unsigned long long int rank =0; // the calculated rank
double crowdingDistance = 0;
// the following properties are set during the fast-non-dominated-sort procedure
std::vector<unsigned long long int> S; // the set of individual index (from a population) that the current individual dominates
unsigned long long int n; // the domination counter of the current individual
unsigned long long int n=0; // the domination counter of the current individual
};
}
#endif //MH_BUILDER_NSGA2_SOLUTION_H
......@@ -62,6 +62,7 @@ namespace opt::manySolutions::geneticAlgorithm::replacement {
std::vector<std::vector<unsigned long long int>> F =
NSGA2_Population<NSGA2SOL>::fastNonDominatedSort(R);
_parent_pop.resize(0);// Pt = {}
unsigned long long int i = 0;
while ((_parent_pop.size() + F[i].size()) <= N) { // until the parent population is filled
NSGA2_Population<NSGA2SOL>::crowdingDistanceAssignment(R,F[i]); // calculate the crowding-distance in F_i
......@@ -77,7 +78,8 @@ namespace opt::manySolutions::geneticAlgorithm::replacement {
return ( (R[ind1].getRank() < R[ind1].getRank()) or
( (R[ind1].getRank()==R[ind1].getRank()) and (R[ind1].getCrowdingDistance() > R[ind2].getCrowdingDistance())));
});
for (unsigned long long int ind=0; ind < (N - _parent_pop.size()); ind++) {
auto reste = N - _parent_pop.size() ;
for (unsigned long long int ind=1; ind <= reste; ind++) {
eval(R[F[i][ind]]);
_parent_pop.push_back(R[F[i][ind]]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment