Skip to content

C++ Library Implementing Multi-Objective Optimization Methods

License

Notifications You must be signed in to change notification settings

lyrahgames/pareto

Repository files navigation

Lyrahgames' Multi-Objective Optimization Package

Header-Only C++ Library for the Estimation of N-Dimensional Pareto Frontiers

Development Status

master
Current

Requirements

Language Standard: C++20
Build System: build2
Operating System: Linux
Windows
MacOS
Dependencies: lyrahgames-xstd
lyrahgames-gnuplot-pipe
doctest

Getting Started

#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";
}

Clone, Build, and Test

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

Usage with build2

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

Installation

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/*"

Usage and Examples

Background

Additional Information

References

About

C++ Library Implementing Multi-Objective Optimization Methods

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published