Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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")
17 changes: 15 additions & 2 deletions include/psocpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ namespace pso

public:

ParticleSwarmOptimization()
: objective_(), callback_(), weightStrategy_(), threads_(1),
template<typename... Args>
ParticleSwarmOptimization(Args&&... args)
: objective_(std::forward<Args>(args)...), callback_(), weightStrategy_(), threads_(1),
maxIt_(0), xeps_(static_cast<Scalar>(1e-6)),
feps_(static_cast<Scalar>(1e-6)), phip_(static_cast<Scalar>(2.0)),
phig_(static_cast<Scalar>(2.0)), maxVel_(static_cast<Scalar>(0.0)),
Expand Down Expand Up @@ -577,6 +578,18 @@ namespace pso
weightStrategy_ = weightStrategy;
}

void setDice(const std::function<Scalar()> &dice)
{
dice_ = dice;
}

template <class RandomEngine>
void setGen(RandomEngine gen)
{
std::uniform_real_distribution<Scalar> distrib(0.0, 1.0);
dice_ = std::bind(distrib, std::forward<RandomEngine>(gen));
}

/** Perform minimization with the given bounds and number of particels.
*
* The swarm of particles will be drawn uniform randomly within the
Expand Down