Skip to content

Instantly share code, notes, and snippets.

@ajw287
Last active June 22, 2019 20:06
Show Gist options
  • Select an option

  • Save ajw287/b66e5097a072ff6989acb7bd1d0c2ba6 to your computer and use it in GitHub Desktop.

Select an option

Save ajw287/b66e5097a072ff6989acb7bd1d0c2ba6 to your computer and use it in GitHub Desktop.
Ex. 2 - check results of nsga2 with bfe
#include <iostream>
#include <pagmo/pagmo.hpp>
#include <pagmo/population.hpp>
// Test nsga2 vs nsga2 w/ bfe
//
// compiles wiht : g++ -O2 -DNDEBUG -std=c++11 -pthread -lpagmo -L /home/andrew/.local/lib/ -I /home/andrew/.local/include/ test2.cpp
//
#include <pagmo/algorithms/nsga2.hpp>
#include <pagmo/problems/dtlz.hpp>
//#include <boost/test/unit_test.hpp>
//#include <boost/test/included/unit_test.hpp> // this work
#include <boost/test/floating_point_comparison.hpp>
using namespace pagmo;
int main()
{
// 1 - Instantiate a pagmo problem constructing it from a UDP
// (user defined problem).
problem prob{dtlz(1, 10, 2)};
nsga2 uda1{nsga2{100}};
uda1.set_verbosity(1u);
uda1.set_seed(23u);
// 2 - Instantiate
algorithm algo1{uda1};
// 3 - Instantiate populations
population pop{prob, 24};
population pop1{prob, 24};
population pop2{prob, 24};
// 4 - Evolve the population
pop1 = algo1.evolve(pop);
// 5 new algorithm that is bfe enabled
nsga2 uda2{nsga2{100}};
uda2.set_verbosity(1u);
uda2.set_seed(23u);
uda2.set_bfe(bfe{}); // This will use the default bfe.
// 6 - Instantiate a pagmo algorithm
algorithm algo2{uda2};
// 7 - Evolve the population
pop2 = algo2.evolve(pop);
uda1.get_log();
uda2.get_log();
std::cout << "data:" << uda1.get_log().size() <<std::endl;
std::cout << "data:" << uda2.get_log().size() <<std::endl;
//BOOST_CHECK(uda1.get_log() == uda2.get_log());
//BOOST_CHECK_EQUAL(pop1.champion_f()[0], pop1.champion_f()[0]);
// 5 - Output the population
std::cout << "The population: \n" << pop <<std::endl;
// optional compare actual populations
std::cout << "The population1: \n" << pop1 <<std::endl;
std::cout << "The population2: \n" << pop1 <<std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment