Header-Only C++ Library for the Estimation of N-Dimensional Pareto Frontiers
master | |||
Current |
Language Standard: | C++20 |
Build System: | build2 |
Operating System: |
Linux Windows MacOS |
Dependencies: |
lyrahgames-xstd
lyrahgames-gnuplot-pipe doctest |
#include <chrono>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <random>
//
#include <lyrahgames/gnuplot_pipe.hpp>
//
#include <lyrahgames/pareto/pareto.hpp>
#include <lyrahgames/pareto/gallery/gallery.hpp>
using namespace std;
using namespace lyrahgames;
using namespace lyrahgames::pareto;
using real = float;
int main() {
mt19937 rng{random_device{}()};
using clock = chrono::high_resolution_clock;
const auto start = clock::now();
// Choose problem, estimate the Pareto frontier, and cast it to a usable
// output format in one step.
const auto pareto_front = nsga2::optimization<frontier<real>>(
gallery::zdt3<real>, rng, {.iterations = 1000, .population = 1000});
const auto end = clock::now();
const auto time = chrono::duration<double>(end - start).count();
cout << setw(20) << "time = " << setw(20) << time << " s\n";
// Store the data into a file for plotting.
fstream file{"zdt3.dat", ios::out};
for (size_t i = 0; i < pareto_front.sample_count(); ++i) {
for (auto y : pareto_front.objectives(i))
file << setw(20) << y << ' ';
file << '\n';
}
file << flush;
// Plot the data.
gnuplot_pipe yplot{};
yplot << "plot 'zdt3.dat' u 1:2 w p lt rgb '#ff3333' pt 13\n";
}
git clone --recurse-submodules https://github.com/lyrahgames/pareto.git lyrahgames-pareto
cd lyrahgames-pareto
bdep init -C @gcc cc config.cxx=g++ \
config.cxx.poptions=-DNDEBUG \
config.cxx.coptions="-O3 -march=native"
b test
Add this repository to the repositories.manifest
file of your build2 package.
:
role: prerequisite
location: https://github.com/lyrahgames/pareto.git
Add the following entry to the manifest
file with a possible version dependency.
depends: lyrahgames-pareto
Add these entries to your buildfile
.
import libs = lyrahgames-pareto%lib{lyrahgames-pareto}
exe{your-executable}: {hxx cxx}{**} $libs
The standard installation process will only install the header-only library with some additional description, library, and package files.
bpkg -d build2-packages cc \
config.install.root=/usr/local \
config.install.sudo=sudo
Get the latest package release and build it.
bpkg build https://github.com/lyrahgames/pareto.git
Install the built package.
bpkg install lyrahgames-pareto
For uninstalling, do the following.
bpkg uninstall lyrahgames-pareto
If your package uses an explicit depends: lyrahgames-pareto
make sure to initialize this dependency as a system dependency when creating a new configuration.
bdep init -C @build cc config.cxx=g++ "config.cxx.coptions=-O3" -- "?sys:lyrahgames-pareto/*"
- Self-Adaptive Parent to Mean-Centric Recombination for Real-Parameter Optimization
- Simulated Binary Crossover for Continuous Search Space
- Real-Coded Genetic Algorithms: Crossovers and Mutations
- Test Functions for Optimization
- https://github.com/philippwirth/nsga2
- https://github.com/OscarPudding/NSGA2_python