• pagmo并行全局多目标优化算法库的安装编译与使用


    Pagmo库

    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需要两个依赖库boostoneTBB, 可分别参考以下两篇文章进行安装:
    (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)
    
    • 1

    测试使用

    依次安装完成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';
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    然后新建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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    之后编译运行即可

  • 相关阅读:
    C++ 类和对象【上篇】(类的定义+类对象模型+this指针)
    CHAPTER 8: DESIGN A URL SHORTENER
    项目管理的核心是什么?
    Vue create 之后的空架子完善
    SpringBoot集成Kafka+Kafka优化问题
    英特尔OpenVINO工程师认证答案及解析(初级✔/中级/高级)
    沉思篇-剖析Jetpack的ViewModel
    Gin,Gorm实现Web计算器
    高阶数据结构学习之图
    【数据结构】快速排序
  • 原文地址:https://blog.csdn.net/weixin_43325228/article/details/128129515