Skip to content

Conversation

@TendTo
Copy link

@TendTo TendTo commented Nov 12, 2025

This small does two main things:

  • It adds Bazel support, so that other projects using Bazel wanting to use this library as a dependency can do so with ease.
  • It changes the ParticleSwarmOptimization constructor slightly, so that the objective functor can be constructed on the fly
  • Add a setDice method for customizing the random generator

Feel free to make any additional changes or adjustments!

Example of integrating this library in a bazel project

# MODULE.bazel

# ...

bazel_dep(name = "psocpp", version = "0.1.0")
git_override(
    module_name = "psocpp",
    commit = "commit hash or tag",
    remote = "https://github.com/Rookfighter/pso-cpp",
)

and then, in a build file

# BUILD.bazel

cc_binary(
    name = "my lib",
    srcs = ["my_main.cpp"],
    deps = ["@psocpp"],
)

Example of the new constructor

class Objective {
 public:
  Objective(const Eigen::VectorXd& offset) : offset_{offset} {}

  template <class Derived>
  double operator()(const Eigen::MatrixBase<Derived>& x) const {
    return (x.colwise() + offset_).sum();
  }

 private:
  const Eigen::VectorXd& offset_;
};

int main() {
  pso::ParticleSwarmOptimization<double, Objective2> optimiser{Eigen::VectorXd::Zero(2)};
 // ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant