Commit f3be7763 authored by snuverink_j's avatar snuverink_j
Browse files

fix final hypervolume calculation: don't clean population (not needed)

parent 42e6658e
...@@ -149,6 +149,7 @@ void FixedPisaNsga2<CO, MO>::initialize() { ...@@ -149,6 +149,7 @@ void FixedPisaNsga2<CO, MO>::initialize() {
last_clock_ = boost::chrono::system_clock::now(); last_clock_ = boost::chrono::system_clock::now();
run(); run();
// run has ended
bool compHyvol = (objectives_m.size() > (hyper_opt / 2 + 1)); bool compHyvol = (objectives_m.size() > (hyper_opt / 2 + 1));
if (compHyvol) if (compHyvol)
current_hvol_ = current_hvol_ =
...@@ -563,7 +564,8 @@ void FixedPisaNsga2<CO, MO>::runStateMachine() { ...@@ -563,7 +564,8 @@ void FixedPisaNsga2<CO, MO>::runStateMachine() {
dumpPopulationToFile(); dumpPopulationToFile();
dumpPopulationToJSON(); dumpPopulationToJSON();
variator_m->population()->clean_population(); // don't clean population otherwise final hypervolume calculation can't be done
//variator_m->population()->clean_population();
curState_m = VariatorStopped; curState_m = VariatorStopped;
// notify pilot that we have converged // notify pilot that we have converged
...@@ -751,9 +753,9 @@ void FixedPisaNsga2<CO, MO>::dumpPopulationToJSON() { ...@@ -751,9 +753,9 @@ void FixedPisaNsga2<CO, MO>::dumpPopulationToJSON() {
for ( Expressions::Named_t::iterator it = constraints_m.begin(); for ( Expressions::Named_t::iterator it = constraints_m.begin();
it != constraints_m.end(); ++it ) it != constraints_m.end(); ++it )
{ {
std::string s = it->second->toString(); std::string s = it->second->toString();
/// cleanup string to make json reader happy /// cleanup string to make json reader happy
s.erase(std::remove(s.begin(), s.end(), '"'), s.end()); s.erase(std::remove(s.begin(), s.end(), '"'), s.end());
file << "\t\t\"" << s << "\""; file << "\t\t\"" << s << "\"";
......
...@@ -33,12 +33,9 @@ class Population { ...@@ -33,12 +33,9 @@ class Population {
public: public:
Population() { Population() {
last_identity = 0; last_identity = 0;
hypervolume_ = 0.0;
} }
~Population() { ~Population() {}
clean_population();
}
typedef typename Individual_t::genes_t genes_t; typedef typename Individual_t::genes_t genes_t;
typedef boost::shared_ptr<Individual_t> individual; typedef boost::shared_ptr<Individual_t> individual;
...@@ -128,9 +125,9 @@ public: ...@@ -128,9 +125,9 @@ public:
} }
/** /**
* Remove all non-surviving individuals from the population and put ID's * Remove all non-surviving individuals from the population and put IDs
* back in pool of free ID's. * back in pool of free IDs.
* @param surviors to keep for next generation * @param survivors to keep for next generation
*/ */
void keepSurvivors(std::set<unsigned int> survivors) { void keepSurvivors(std::set<unsigned int> survivors) {
...@@ -188,8 +185,7 @@ public: ...@@ -188,8 +185,7 @@ public:
file.flush(); file.flush();
file.close(); file.close();
hypervolume_ = Hypervolume::FromFile(filename.str(), referencePoint); return Hypervolume::FromFile(filename.str(), referencePoint);
return hypervolume_;
} }
...@@ -216,12 +212,12 @@ public: ...@@ -216,12 +212,12 @@ public:
/// iterator end on population container /// iterator end on population container
indItr_t end() { return individuals.end(); } indItr_t end() { return individuals.end(); }
/// Remove (and cleanup) all individuals in the population /* /// Remove (and cleanup) all individuals in the population */
void clean_population() { /* void clean_population() { */
stagingArea.clear(); /* stagingArea.clear(); */
individuals.clear(); /* individuals.clear(); */
} /* } */
private: private:
...@@ -231,16 +227,14 @@ private: ...@@ -231,16 +227,14 @@ private:
/// staging area for individuals probably joining population /// staging area for individuals probably joining population
std::map<unsigned int, individual > stagingArea; std::map<unsigned int, individual > stagingArea;
/// queue to handle free individual ID's /// queue to handle free individual IDs
std::queue<unsigned int> freeids; std::queue<unsigned int> freeids;
/// last used (= next free) ID /// last used (= next free) ID
unsigned int last_identity; unsigned int last_identity;
double hypervolume_;
/** /**
* Manages free individual ID's * Manages free individual IDs
* @return lowest free ID * @return lowest free ID
*/ */
unsigned int getFreeID() { unsigned int getFreeID() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment