pagmo是一个综合的全局优化算法库,由欧空局开发,使用C++编写,可实现大规模并行计算。pagmo官网的介绍如下
pagmo is a C++ scientific library for massively parallel optimization. It is built around the idea of providing a unified interface to optimization algorithms and problems, and to make their deployment in massively parallel environments easy.
Efficient implementations of bio-inspired and evolutionary algorithms are sided to state-of-the-art optimization algorithms (Simplex Methods, SQP methods, interior points methods, …) and can be easily mixed (also with your newly-invented algorithms) to build a super-algorithm exploiting algorithmic cooperation via the asynchronous, generalized island model.
pagmo can be used to solve constrained, unconstrained, single objective, multiple objective, continuous and integer optimization problems, stochastic and deterministic problems, as well as to perform research on novel algorithms and paradigms and easily compare them to state-of-the-art implementations of established ones.
Pagmo需要两个依赖库boost和oneTBB, 可分别参考以下两篇文章进行安装:
(1)在Ubuntu上安装Boost的五种方法
(2)Intel TBB库+CMake+Ubuntu配置流程
安装完成依赖项之后,再参考installation说明完成pagmo的安装。如果掌握CMake的使用方法,那么安装过程比较简单。唯一需要注意的是CMake的版本号,pagmo官方要求的版本号需要在3.8以上,但是事实上只需要大于3.0即可正常配置与编译。
打开pagmo软件包中的CMakeLists.txt文件,将第2行做如下修改
cmake_minimum_required(VERSION 3.0)
依次安装完成boost,oneTBB,pagmo之后,就可以开始测试与使用了
首先新建一个main.cpp文件
#include
#include
#include
#include
#include
#include
using namespace pagmo;
int main()
{
// 1 - Instantiate a pagmo problem constructing it from a UDP
// (i.e., a user-defined problem, in this case the 30-dimensional
// generalised Schwefel test function).
problem prob{schwefel(30)};
// 2 - Instantiate a pagmo algorithm (self-adaptive differential
// evolution, 100 generations).
algorithm algo{sade(1000)};
// 3 - Instantiate an archipelago with 16 islands having each 20 individuals.
archipelago archi{4u, algo, prob, 200u};
// 4 - Run the evolution in parallel on the 16 separate islands 10 times.
archi.evolve(10);
// 5 - Wait for the evolutions to finish.
archi.wait_check();
// 6 - Print the fitness of the best solution in each island.
for (const auto &isl : archi) {
std::cout << isl.get_population().champion_f()[0] << '\n';
}
}
然后新建CMakeLists.txt文件
cmake_minimum_required(VERSION 3.16)
project(getting_started)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} main.cpp)
add_definitions("-pthread")
target_link_libraries(${PROJECT_NAME} pagmo boost_serialization tbb)
之后编译运行即可