From c57cc49df455b4f76b3d73a11ea99cd0a815e6d1 Mon Sep 17 00:00:00 2001 From: Ernesto Casablanca Date: Wed, 12 Nov 2025 14:01:54 +0000 Subject: [PATCH 1/4] build: add bazel support --- BUILD.bazel | 14 ++++++++++++++ MODULE.bazel | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 BUILD.bazel create mode 100644 MODULE.bazel diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000..37f6a80 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,14 @@ +"""psocpp library for Bazel""" + +load("@rules_cc//cc:defs.bzl", "cc_library") + +licenses(["notice"]) # MIT + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "psocpp", + hdrs = glob(["include/*.h"]), + includes = ["include"], + deps = ["@eigen"], +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..d4dfd65 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,6 @@ +"""psocpp module""" + +module(name = "psocpp") + +bazel_dep(name = "rules_cc", version = "0.2.14") +bazel_dep(name = "eigen", version = "5.0.1") From 8899b80014d92b8c38b9e473691673cb1e76004e Mon Sep 17 00:00:00 2001 From: Ernesto Casablanca Date: Wed, 12 Nov 2025 14:03:00 +0000 Subject: [PATCH 2/4] feat: allow for objective functor initialization in the ParticleSwarmOptimization constructor --- include/psocpp.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/psocpp.h b/include/psocpp.h index 37e9a4f..3d3c707 100644 --- a/include/psocpp.h +++ b/include/psocpp.h @@ -473,8 +473,9 @@ namespace pso public: - ParticleSwarmOptimization() - : objective_(), callback_(), weightStrategy_(), threads_(1), + template + ParticleSwarmOptimization(Args&&... args) + : objective_(std::forward(args)...), callback_(), weightStrategy_(), threads_(1), maxIt_(0), xeps_(static_cast(1e-6)), feps_(static_cast(1e-6)), phip_(static_cast(2.0)), phig_(static_cast(2.0)), maxVel_(static_cast(0.0)), From 3b5c223d1bd0f4549da809d6e72c5bc765260a3b Mon Sep 17 00:00:00 2001 From: Ernesto Casablanca Date: Thu, 13 Nov 2025 12:14:57 +0000 Subject: [PATCH 3/4] feat: add the ability of setting the rng function dice_. Useful for controlling the randomness, e.g., wanting to use a specific seed. --- include/psocpp.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/psocpp.h b/include/psocpp.h index 3d3c707..3743d14 100644 --- a/include/psocpp.h +++ b/include/psocpp.h @@ -578,6 +578,11 @@ namespace pso weightStrategy_ = weightStrategy; } + void setDice(const std::function &dice) + { + dice_ = dice; + } + /** Perform minimization with the given bounds and number of particels. * * The swarm of particles will be drawn uniform randomly within the From f5e4e1eb12604bcc8504456887693337b3c4b8e8 Mon Sep 17 00:00:00 2001 From: Ernesto Casablanca Date: Fri, 14 Nov 2025 14:19:21 +0000 Subject: [PATCH 4/4] feat: add the ability of specifying only the random number generator --- include/psocpp.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/psocpp.h b/include/psocpp.h index 3743d14..270c926 100644 --- a/include/psocpp.h +++ b/include/psocpp.h @@ -583,6 +583,13 @@ namespace pso dice_ = dice; } + template + void setGen(RandomEngine gen) + { + std::uniform_real_distribution distrib(0.0, 1.0); + dice_ = std::bind(distrib, std::forward(gen)); + } + /** Perform minimization with the given bounds and number of particels. * * The swarm of particles will be drawn uniform randomly within the