Commit 9f8f6442 authored by kraus's avatar kraus
Browse files

Merge branch 'master' of gitlab.psi.ch:OPAL/src

parents ff4c659d 8e45602d
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include "Comm/Splitter/SplitStrategy.h" #include "Comm/Splitter/SplitStrategy.h"
typedef std::vector<int> coordinates_t; typedef std::vector<int> coordinates_t;
...@@ -52,12 +49,12 @@ public: ...@@ -52,12 +49,12 @@ public:
} }
// 3. Compute centroids of partition and assign master // 3. Compute centroids of partition and assign master
foreach(region_t & region, regions_) { for(region_t & region : regions_) {
computeCentroid(region); computeCentroid(region);
} }
// 4. Create communicator groups // 4. Create communicator groups
foreach(region_t & region, regions_) { for(region_t & region : regions_) {
bool is_worker = false; bool is_worker = false;
coordinates_t iter = region.origin; coordinates_t iter = region.origin;
...@@ -107,7 +104,7 @@ protected: ...@@ -107,7 +104,7 @@ protected:
int split_in_direction = 0; int split_in_direction = 0;
int max_ext_dir = 0; int max_ext_dir = 0;
foreach(region_t region, regions_) { for(region_t region : regions_) {
for(int dim = 0; dim < topology_.getNumDimensions(); dim++) { for(int dim = 0; dim < topology_.getNumDimensions(); dim++) {
if(region.extensions[dim] > max_ext_dir) { if(region.extensions[dim] > max_ext_dir) {
split_in_direction = dim; split_in_direction = dim;
......
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#include "Comm/Splitter/SplitStrategy.h" #include "Comm/Splitter/SplitStrategy.h"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include <boost/random/mersenne_twister.hpp> #include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp> #include <boost/random/uniform_int_distribution.hpp>
...@@ -41,7 +38,7 @@ public: ...@@ -41,7 +38,7 @@ public:
int num_assigned_masters = 0; int num_assigned_masters = 0;
// assign workers uniform at random to each master // assign workers uniform at random to each master
foreach(int master_pid, master_pids) { for(int master_pid : master_pids) {
if(master_pid == rank_) role_ = Role_t.POLLER; if(master_pid == rank_) role_ = Role_t.POLLER;
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "Expression/Parser/skipper.hpp" #include "Expression/Parser/skipper.hpp"
#include "Expression/Parser/function.hpp" #include "Expression/Parser/function.hpp"
#include <boost/foreach.hpp>
#include <boost/function.hpp> #include <boost/function.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/variant/get.hpp> #include <boost/variant/get.hpp>
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include "boost/variant/get.hpp" #include "boost/variant/get.hpp"
#include "boost/variant/variant.hpp" #include "boost/variant/variant.hpp"
#include "boost/smart_ptr.hpp" #include "boost/smart_ptr.hpp"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include "Util/Types.h" #include "Util/Types.h"
#include "Util/OptPilotException.h" #include "Util/OptPilotException.h"
...@@ -43,7 +41,7 @@ struct FromFile { ...@@ -43,7 +41,7 @@ struct FromFile {
return boost::make_tuple(0.0, false); return boost::make_tuple(0.0, false);
} }
foreach(double obj_value, values_) for(double obj_value : values_)
sum += obj_value; sum += obj_value;
return boost::make_tuple(sum, is_valid); return boost::make_tuple(sum, is_valid);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
=============================================================================*/ =============================================================================*/
#include "evaluator.hpp" #include "evaluator.hpp"
#include <boost/foreach.hpp>
#include <boost/variant/apply_visitor.hpp> #include <boost/variant/apply_visitor.hpp>
namespace client { namespace code_gen { namespace client { namespace code_gen {
...@@ -101,8 +100,7 @@ namespace client { namespace code_gen { ...@@ -101,8 +100,7 @@ namespace client { namespace code_gen {
bool StackEvaluator::operator()(ast::function_call const& x) { bool StackEvaluator::operator()(ast::function_call const& x) {
BOOST_FOREACH(ast::function_call_argument const& arg, x.args) { for(ast::function_call_argument const& arg : x.args) {
if (!boost::apply_visitor(*this, arg)) if (!boost::apply_visitor(*this, arg))
return false; return false;
} }
...@@ -135,7 +133,7 @@ namespace client { namespace code_gen { ...@@ -135,7 +133,7 @@ namespace client { namespace code_gen {
if (!boost::apply_visitor(*this, x.first)) if (!boost::apply_visitor(*this, x.first))
return false; return false;
BOOST_FOREACH(ast::operation const& oper, x.rest) { for(ast::operation const& oper : x.rest) {
if (!(*this)(oper)) if (!(*this)(oper))
return false; return false;
} }
......
...@@ -60,8 +60,7 @@ namespace client { namespace code_gen ...@@ -60,8 +60,7 @@ namespace client { namespace code_gen
bool operator()(ast::function_call const& x) { bool operator()(ast::function_call const& x) {
functions_.insert(x.function_name.name); functions_.insert(x.function_name.name);
BOOST_FOREACH(ast::function_call_argument const& arg, x.args) { for(ast::function_call_argument const& arg: x.args) {
if (!boost::apply_visitor(*this, arg)) if (!boost::apply_visitor(*this, arg))
return false; return false;
//if (!(*this)(arg)) //if (!(*this)(arg))
...@@ -75,7 +74,7 @@ namespace client { namespace code_gen ...@@ -75,7 +74,7 @@ namespace client { namespace code_gen
if (!boost::apply_visitor(*this, x.first)) if (!boost::apply_visitor(*this, x.first))
return false; return false;
BOOST_FOREACH(ast::operation const& oper, x.rest) { for(ast::operation const& oper: x.rest) {
if (!(*this)(oper)) if (!(*this)(oper))
return false; return false;
} }
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
#include "boost/variant/get.hpp" #include "boost/variant/get.hpp"
#include "boost/variant/variant.hpp" #include "boost/variant/variant.hpp"
#include "boost/smart_ptr.hpp" #include "boost/smart_ptr.hpp"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include "Util/Types.h" #include "Util/Types.h"
#include "Util/SDDSReader.h" #include "Util/SDDSReader.h"
...@@ -58,7 +56,7 @@ struct SumErrSq { ...@@ -58,7 +56,7 @@ struct SumErrSq {
double sum = 0; double sum = 0;
foreach(Measurement measurement, measurements_) { for(Measurement measurement : measurements_) {
double sim_value = 0.0; double sim_value = 0.0;
try { try {
sim_stats->getInterpolatedValue( sim_stats->getInterpolatedValue(
......
...@@ -61,11 +61,13 @@ public: ...@@ -61,11 +61,13 @@ public:
* @param[in] dim number of objectives * @param[in] dim number of objectives
* @param[in] comms available to the optimizer * @param[in] comms available to the optimizer
* @param[in] args the user passed on the command line * @param[in] args the user passed on the command line
* @param[in] hypervolRef hypervolume reference point
*/ */
FixedPisaNsga2(Expressions::Named_t objectives, FixedPisaNsga2(Expressions::Named_t objectives,
Expressions::Named_t constraints, Expressions::Named_t constraints,
DVarContainer_t dvars, size_t dim, Comm::Bundle_t comms, DVarContainer_t dvars, size_t dim, Comm::Bundle_t comms,
CmdArguments_t args); CmdArguments_t args,
std::vector<double> hypervolRef);
~FixedPisaNsga2(); ~FixedPisaNsga2();
...@@ -175,7 +177,7 @@ private: ...@@ -175,7 +177,7 @@ private:
DVarContainer_t dvars_m; DVarContainer_t dvars_m;
/// command line arguments specified by the user /// command line arguments specified by the user
CmdArguments_t args_; CmdArguments_t args_m;
/// size of initial population /// size of initial population
size_t alpha_m; size_t alpha_m;
...@@ -205,6 +207,9 @@ private: ...@@ -205,6 +207,9 @@ private:
double conv_hvol_progress_; double conv_hvol_progress_;
double hvol_progress_; double hvol_progress_;
/// hypervolume reference point
std::vector<double> hvol_ref_m;
/// file header for result files contains this parameter description /// file header for result files contains this parameter description
std::string file_param_descr_; std::string file_param_descr_;
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "boost/algorithm/string.hpp" #include "boost/algorithm/string.hpp"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_iarchive.hpp>
...@@ -32,15 +30,17 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2( ...@@ -32,15 +30,17 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2(
Expressions::Named_t constraints, Expressions::Named_t constraints,
DVarContainer_t dvars, DVarContainer_t dvars,
size_t dim, Comm::Bundle_t comms, size_t dim, Comm::Bundle_t comms,
CmdArguments_t args) CmdArguments_t args,
std::vector<double> hypervolRef)
: Optimizer(comms.opt) : Optimizer(comms.opt)
, statistics_(new Statistics<size_t>("individuals")) , statistics_(new Statistics<size_t>("individuals"))
, comms_(comms) , comms_(comms)
, objectives_m(objectives) , objectives_m(objectives)
, constraints_m(constraints) , constraints_m(constraints)
, dvars_m(dvars) , dvars_m(dvars)
, args_(args) , args_m(args)
, dim_m(dim) , dim_m(dim)
, hvol_ref_m(hypervolRef)
{ {
my_local_pid_ = 0; my_local_pid_ = 0;
MPI_Comm_rank(comms_.opt, &my_local_pid_); MPI_Comm_rank(comms_.opt, &my_local_pid_);
...@@ -48,10 +48,10 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2( ...@@ -48,10 +48,10 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2(
//FIXME: proper rand gen initialization (use boost?!) //FIXME: proper rand gen initialization (use boost?!)
srand(time(NULL) + comms_.island_id); srand(time(NULL) + comms_.island_id);
dump_freq_ = args->getArg<int>("dump-freq", 1, false); dump_freq_ = args->getArg<int>("dump-freq", 1, false);
maxGenerations_m = args->getArg<int>("maxGenerations", true); maxGenerations_m = args->getArg<int>("maxGenerations", true);
resultFile_m = args->getArg<std::string>("outfile", "-th_generation.dat", false); resultFile_m = args->getArg<std::string>("outfile", "-th_generation.dat", false);
resultDir_m = args->getArg<std::string>("outdir", "generations", false); resultDir_m = args->getArg<std::string>("outdir", "generations", false);
// create output directory if it does not exists // create output directory if it does not exists
struct stat dirInfo; struct stat dirInfo;
...@@ -86,7 +86,7 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2( ...@@ -86,7 +86,7 @@ FixedPisaNsga2<CO, MO>::FixedPisaNsga2(
DVarContainer_t::iterator itr; DVarContainer_t::iterator itr;
std::vector<std::string> dNames; std::vector<std::string> dNames;
for(itr = dvars_m.begin(); itr != dvars_m.end(); itr++) { for(itr = dvars_m.begin(); itr != dvars_m.end(); itr++) {
std::string dName = boost::get<VAR_NAME>(itr->second); std::string dName = boost::get<VAR_NAME>(itr->second);
file_param_descr_ += '%' + dName + ','; file_param_descr_ += '%' + dName + ',';
...@@ -144,13 +144,14 @@ void FixedPisaNsga2<CO, MO>::initialize() { ...@@ -144,13 +144,14 @@ void FixedPisaNsga2<CO, MO>::initialize() {
// start poll loop // start poll loop
run_clock_start_ = boost::chrono::system_clock::now(); run_clock_start_ = boost::chrono::system_clock::now();
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_ =
variator_m->population()->computeHypervolume(comms_.island_id); variator_m->population()->computeHypervolume(comms_.island_id, hvol_ref_m);
boost::chrono::duration<double> total = boost::chrono::duration<double> total =
boost::chrono::system_clock::now() - run_clock_start_; boost::chrono::system_clock::now() - run_clock_start_;
...@@ -206,7 +207,7 @@ bool FixedPisaNsga2<CO, MO>::onMessage(MPI_Status status, size_t length) { ...@@ -206,7 +207,7 @@ bool FixedPisaNsga2<CO, MO>::onMessage(MPI_Status status, size_t length) {
delete[] buffer; delete[] buffer;
std::set<unsigned int> new_state_ids; std::set<unsigned int> new_state_ids;
foreach(individual ind, new_states) { for (individual ind : new_states) {
// only insert individual if not already in population // only insert individual if not already in population
if(variator_m->population()->isRepresentedInPopulation(ind.genes)) if(variator_m->population()->isRepresentedInPopulation(ind.genes))
...@@ -262,9 +263,8 @@ bool FixedPisaNsga2<CO, MO>::onMessage(MPI_Status status, size_t length) { ...@@ -262,9 +263,8 @@ bool FixedPisaNsga2<CO, MO>::onMessage(MPI_Status status, size_t length) {
ind->objectives.clear(); ind->objectives.clear();
//XXX: check order of genes //XXX: check order of genes
reqVarContainer_t::iterator itr; reqVarContainer_t::iterator itr = res.begin();
std::map<std::string, double> vars; for(; itr != res.end(); ++itr) {
for(itr = res.begin(); itr != res.end(); itr++) {
// mark invalid if expression could not be evaluated or constraint does not hold // mark invalid if expression could not be evaluated or constraint does not hold
if(!itr->second.is_valid || (itr->second.value.size() > 1 && !itr->second.value[0])) { if(!itr->second.is_valid || (itr->second.value.size() > 1 && !itr->second.value[0])) {
std::ostringstream dump; std::ostringstream dump;
...@@ -321,7 +321,7 @@ void FixedPisaNsga2<CO, MO>::postPoll() { ...@@ -321,7 +321,7 @@ void FixedPisaNsga2<CO, MO>::postPoll() {
bool compHyvol = (objectives_m.size() > (hyper_opt / 2 + 1)); bool compHyvol = (objectives_m.size() > (hyper_opt / 2 + 1));
if (compHyvol) { if (compHyvol) {
double hvol = double hvol =
variator_m->population()->computeHypervolume(comms_.island_id); variator_m->population()->computeHypervolume(comms_.island_id, hvol_ref_m);
hvol_progress_ = fabs(current_hvol_ - hvol) / current_hvol_; hvol_progress_ = fabs(current_hvol_ - hvol) / current_hvol_;
current_hvol_ = hvol; current_hvol_ = hvol;
} }
...@@ -337,7 +337,7 @@ void FixedPisaNsga2<CO, MO>::postPoll() { ...@@ -337,7 +337,7 @@ void FixedPisaNsga2<CO, MO>::postPoll() {
stats << "dt = " << dt.count() << "s, total = " << total.count() stats << "dt = " << dt.count() << "s, total = " << total.count()
<< "s" << std::endl; << "s" << std::endl;
if (compHyvol) if (compHyvol)
stats << "Hypervolume = " << current_hvol_ << std::endl; stats << "Hypervolume = " << current_hvol_ << std::endl;
stats << "__________________________________________" << std::endl; stats << "__________________________________________" << std::endl;
progress_->log(stats); progress_->log(stats);
...@@ -370,7 +370,7 @@ void FixedPisaNsga2<CO, MO>::exchangeSolutionStates() { ...@@ -370,7 +370,7 @@ void FixedPisaNsga2<CO, MO>::exchangeSolutionStates() {
typedef typename FixedPisaNsga2::Individual_t individual; typedef typename FixedPisaNsga2::Individual_t individual;
size_t num_masters = args_->getArg<size_t>("num-masters", 1, false); size_t num_masters = args_m->getArg<size_t>("num-masters", 1, false);
if(num_masters <= 1 || if(num_masters <= 1 ||
exchangeSolStateFreq_m == 0 || exchangeSolStateFreq_m == 0 ||
...@@ -562,7 +562,8 @@ void FixedPisaNsga2<CO, MO>::runStateMachine() { ...@@ -562,7 +562,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
...@@ -660,7 +661,7 @@ template< template <class> class CO, template <class> class MO > ...@@ -660,7 +661,7 @@ template< template <class> class CO, template <class> class MO >
void FixedPisaNsga2<CO, MO>::dumpPopulationToFile() { void FixedPisaNsga2<CO, MO>::dumpPopulationToFile() {
// only dump old data format if the user requests it // only dump old data format if the user requests it
if(! args_->getArg<bool>("dump-dat", false, false)) return; if(! args_m->getArg<bool>("dump-dat", false, false)) return;
typedef typename FixedPisaNsga2::Individual_t individual; typedef typename FixedPisaNsga2::Individual_t individual;
boost::shared_ptr<individual> temp; boost::shared_ptr<individual> temp;
...@@ -750,9 +751,9 @@ void FixedPisaNsga2<CO, MO>::dumpPopulationToJSON() { ...@@ -750,9 +751,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 << "\"";
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include <fstream> #include <fstream>
#include "boost/smart_ptr.hpp" #include "boost/smart_ptr.hpp"
#include "boost/foreach.hpp"
#define foreach BOOST_FOREACH
#include "extlib/wfgHypervolume/hypervolume.h" #include "extlib/wfgHypervolume/hypervolume.h"
...@@ -33,12 +31,9 @@ class Population { ...@@ -33,12 +31,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;
...@@ -119,7 +114,7 @@ public: ...@@ -119,7 +114,7 @@ public:
void commit_individuals(std::set<unsigned int> ids) { void commit_individuals(std::set<unsigned int> ids) {
foreach(unsigned int id, ids) { for (unsigned int id : ids) {
//std::cout << "--+ committing id = " << id << "\xd"; //std::cout << "--+ committing id = " << id << "\xd";
individual ind = get_staging(id); individual ind = get_staging(id);
individuals.insert(ind_t(id, ind)); individuals.insert(ind_t(id, ind));
...@@ -128,9 +123,9 @@ public: ...@@ -128,9 +123,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) {
...@@ -153,7 +148,7 @@ public: ...@@ -153,7 +148,7 @@ public:
//XXX: currently O(n): add a fast look-up table? //XXX: currently O(n): add a fast look-up table?
bool isRepresentedInPopulation(genes_t ind_genes) { bool isRepresentedInPopulation(genes_t ind_genes) {
foreach(ind_t ind, individuals) { for(ind_t ind : individuals) {
if( ind_genes == ind.second->genes ) if( ind_genes == ind.second->genes )
return true; return true;
} }
...@@ -162,7 +157,9 @@ public: ...@@ -162,7 +157,9 @@ public:
} }
double computeHypervolume(size_t island_id) { double computeHypervolume(size_t island_id, const std::vector<double>& referencePoint) {
// protection check
if (individuals.empty() == true) return -1;
std::ofstream file; std::ofstream file;
std::ostringstream filename; std::ostringstream filename;
...@@ -186,8 +183,7 @@ public: ...@@ -186,8 +183,7 @@ public:
file.flush(); file.flush();
file.close(); file.close();
hypervolume_ = Hypervolume::FromFile(filename.str()); return Hypervolume::FromFile(filename.str(), referencePoint);
return hypervolume_;
} }
...@@ -214,12 +210,12 @@ public: ...@@ -214,12 +210,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:
...@@ -229,16 +225,14 @@ private: ...@@ -229,16 +225,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;