Evolving a population#
Solving an optimization problem using an optimization algorithm is, in pagmo,
described as evolving a population. In the scientific literature, an
interesting
discussion has developed over the past decades on whether evolution is or not
a form of
optimization. In pagmo we take the opposite standpoint and we regard
optimization,
of all types, as a form of evolution. Regardless on whether you will
be using an SQP,
an interior point optimizer or an evolutionary strategy solver, in pagmo you
will always have to call a method called evolve()
to improve over your
initial solutions,
i.e., your population.
After following the installation guide, you will be able to compile and run C++ pagmo programs. The following example shows the use with no multithreading of an algorithmic evolution:
1#include <iostream>
2
3#include <pagmo/algorithm.hpp>
4#include <pagmo/algorithms/nsga2.hpp>
5#include <pagmo/population.hpp>
6#include <pagmo/problem.hpp>
7#include <pagmo/problems/dtlz.hpp>
8
9using namespace pagmo;
10
11int main()
12{
13 // 1 - Instantiate a pagmo problem constructing it from a UDP
14 // (user defined problem).
15 problem prob{dtlz(1, 10, 2)};
16
17 // 2 - Instantiate a pagmo algorithm
18 algorithm algo{nsga2(100)};
19
20 // 3 - Instantiate a population
21 population pop{prob, 24};
22
23 // 4 - Evolve the population
24 pop = algo.evolve(pop);
25
26 // 5 - Output the population
27 std::cout << "The population: \n" << pop;
28}
Place it into a nsga2.cpp
text file and compile it (for example) with:
$ g++ -O2 -DNDEBUG -std=c++17 nsga2.cpp -ltbb -lboost_serialization