homebrew-core/Formula/pagmo.rb
2020-01-12 11:37:17 +01:00

69 lines
2.1 KiB
Ruby

class Pagmo < Formula
desc "Scientific library for massively parallel optimization"
homepage "https://esa.github.io/pagmo2/"
url "https://github.com/esa/pagmo2/archive/v2.13.0.tar.gz"
sha256 "4431e61cae9f27b692b78b30e2a08362dfd35960c3840dae04ef28af8305e621"
bottle do
cellar :any
sha256 "321b5583177ead7f152ed8346df23a65130f1a7105236599f025b8e8f9999544" => :catalina
sha256 "432171f50d30695eac5e7176e7597ec894dba1e23507438ce961c19887ef5851" => :mojave
sha256 "c93ef996a49ddbf7d67c5c5391d84c83c7e9d7e6c0d0a32d6473e8198a683a5a" => :high_sierra
end
depends_on "cmake" => :build
depends_on "boost"
depends_on "eigen"
depends_on "nlopt"
depends_on "tbb"
def install
ENV.cxx11
system "cmake", ".", "-DPAGMO_WITH_EIGEN3=ON", "-DPAGMO_WITH_NLOPT=ON",
*std_cmake_args
system "make", "install"
end
test do
(testpath/"test.cpp").write <<~EOS
#include <iostream>
#include <pagmo/algorithm.hpp>
#include <pagmo/algorithms/sade.hpp>
#include <pagmo/archipelago.hpp>
#include <pagmo/problem.hpp>
#include <pagmo/problems/schwefel.hpp>
using namespace pagmo;
int main()
{
// 1 - Instantiate a pagmo problem constructing it from a UDP
// (user defined problem).
problem prob{schwefel(30)};
// 2 - Instantiate a pagmo algorithm
algorithm algo{sade(100)};
// 3 - Instantiate an archipelago with 16 islands having each 20 individuals
archipelago archi{16, algo, prob, 20};
// 4 - Run the evolution in parallel on the 16 separate islands 10 times.
archi.evolve(10);
// 5 - Wait for the evolutions to be finished
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] << std::endl;
}
return 0;
}
EOS
system ENV.cxx, "test.cpp", "-I#{include}", "-L#{lib}", "-lpagmo",
"-std=c++11", "-o", "test"
system "./test"
end
end