28 ext::shared_ptr<Intensity> intensity,
29 ext::shared_ptr<RandomWalk> randomWalk,
34 : mutation_(mutation), crossover_(crossover), M_(M), Mde_(Mde), Mfa_(M_ - Mde_),
35 intensity_(
std::move(intensity)), randomWalk_(
std::move(randomWalk)),
36 generator_(seed), distribution_(Mfa_, Mde > 0 ? M_ - 1 : M_),
39 "Differential Evolution subpopulation cannot be larger than total population");
56 for (
Size i = 0; i <
M_; i++) {
58 x_.emplace_back(
N_, 0.0);
59 xI_.emplace_back(
N_, 0.0);
60 xRW_.emplace_back(
N_, 0.0);
62 for (
Size j = 0; j <
N_; j++) {
64 x[j] =
lX_[j] + bounds[j] * sample[j];
80 Size iterationStat = 0;
89 Size indexR1, indexR2;
94 Size bestPosition = 0;
95 for (
Size i = 1; i <
M_; i++) {
96 if (
values_[i].first < bestValue) {
101 Array bestX =
x_[bestPosition];
108 if (iteration > maxIteration || iterationStat > maxIStationary)
123 xBest =
x_[indexBest];
127 }
while(indexR1 == indexBest);
130 }
while(indexR2 == indexBest || indexR2 == indexR1);
137 for (
Size j = 0; j <
N_; j++) {
140 z[j] = xBest[j] +
mutation_*(xR1[j] - xR2[j]);
148 else if (z[j] >
uX_[j]) {
153 if (val <
values_[index].first) {
158 if (val < bestValue) {
183 for (
Size j = 0; j <
N_; j++) {
185 z[j] = x[j] + xI[j] + xRW[j];
190 else if (z[j] >
uX_[j]) {
201 if (val < bestValue) {
210 if (iteration > maxIteration)
223 Array& xI = (*xI_)[(*values_)[0].second];
224 for (
Size j = 0; j <
N_; j++) {
230 Size index = (*values_)[i].second;
231 const Array& x = (*x_)[index];
232 Array& xI = (*xI_)[index];
233 for (
Size j = 0; j <
N_; j++) {
236 Real valueX = (*values_)[i].first;
237 for (
Size k = 0; k < i - 1; k++){
238 const Array&
y = (*x_)[(*values_)[k].second];
239 Real valueY = (*values_)[k].first;
241 xI += intensity*(
y - x);
1-D array used in linear algebra.
Size size() const
dimension of the array
Array lowerBound(const Array ¶ms) const
Array upperBound(const Array ¶ms) const
Criteria to end optimization process:
Size maxIterations() const
Size maxStationaryStateIterations() const
virtual Real intensityImpl(Real valueX, Real valueY, Real distance)=0
Real distance(const Array &x, const Array &y) const
void findBrightest()
find brightest firefly for each firefly
std::vector< std::pair< Real, Size > > values_
std::uniform_int_distribution< QuantLib::Size > distribution_
ext::shared_ptr< Intensity > intensity_
void startState(Problem &P, const EndCriteria &endCriteria)
MersenneTwisterUniformRng rng_
std::vector< Array > xRW_
FireflyAlgorithm(Size M, ext::shared_ptr< Intensity > intensity, ext::shared_ptr< RandomWalk > randomWalk, Size Mde=0, Real mutationFactor=1.0, Real crossoverFactor=0.5, unsigned long seed=SeedGenerator::instance().get())
EndCriteria::Type minimize(Problem &P, const EndCriteria &endCriteria) override
minimize the optimization problem P
ext::shared_ptr< RandomWalk > randomWalk_
Constrained optimization problem.
const Array & currentValue() const
current value of the local minimum
Constraint & constraint() const
Constraint.
Real value(const Array &x)
call cost function computation and increment evaluation counter
void setFunctionValue(Real functionValue)
void setCurrentValue(const Array ¤tValue)
Sobol low-discrepancy sequence generator.
const SobolRsg::sample_type & nextSequence() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Implementation based on: Yang, Xin-She (2009) Firefly Algorithm, Levy Flights and Global Optimization...
std::size_t Size
size of a container
Sobol low-discrepancy sequence generator.
std::vector< Real > value_type