|
Doxygen
1.9.1
|
Stores the information about a particle swarm. More...
#include <tsgParticleSwarm.hpp>
Public Member Functions | |
| ParticleSwarmState ()=delete | |
| The particle swarm state must be initialized with data that defines number of particles and dimensions. | |
| ParticleSwarmState (const int num_dimensions, const int num_particles) | |
| Constructor for a particle swarm state with the number of particles and dimensions. | |
| ParticleSwarmState (const int num_dimensions, std::vector< double > &&pp, std::vector< double > &&pv) | |
| Constructor for a particle swarm state with the number of dimensions and the number of particles inferred from a set of input particle positions pp and a set of input particle velocities pv. | |
| ParticleSwarmState (const ParticleSwarmState &source)=default | |
| Copy constructor. | |
| ParticleSwarmState (ParticleSwarmState &&source)=default | |
| Move constructor. | |
| ParticleSwarmState & | operator= (ParticleSwarmState &&source)=default |
| Move assignment. | |
| int | getNumDimensions () const |
| Return the number of dimensions. | |
| int | getNumParticles () const |
| Return the number of particles. | |
| void | getParticlePositions (double pp[]) const |
| Return the particle positions. | |
| std::vector< double > | getParticlePositions () const |
| Return the particle positions, vector overload. | |
| void | getParticleVelocities (double pv[]) const |
| Return the particle velocities. | |
| std::vector< double > | getParticleVelocities () const |
| Return the particle velocities, vector overload. | |
| void | getBestParticlePositions (double bpp[]) const |
| Return the best known particle positions. More... | |
| std::vector< double > | getBestParticlePositions () const |
| Return the best known particle positions, vector overload. | |
| void | getBestPosition (double bp[]) const |
| Loads the best known position in the swarm. | |
| std::vector< double > | getBestPosition () const |
| Returns the best knows position in the swarm. | |
| bool | isPositionInitialized () const |
| Returns true if the particle positions have been initialized. | |
| bool | isVelocityInitialized () const |
| Returns true if the particle velocities have been initialized. | |
| bool | isBestPositionInitialized () const |
| Returns true if the best particle positions have been initialized. | |
| bool | isCacheInitialized () const |
| Returns true if the cache has been initialized. | |
| std::vector< bool > | getStateVector () const |
| Return the complete state vector. | |
| void | setParticlePositions (const double pp[]) |
| Set the particle positions, raw-array variant. | |
| void | setParticlePositions (const std::vector< double > &pp) |
| Set the particle positions, vector variant. | |
| void | setParticlePositions (std::vector< double > &&pp) |
| Set the particle positions, with a move. | |
| void | setParticleVelocities (const double pv[]) |
| Set the particle velocities. | |
| void | setParticleVelocities (const std::vector< double > &pv) |
| Sets the best position. | |
| void | setParticleVelocities (std::vector< double > &&pv) |
| Sets the best position, with a move. | |
| void | setBestParticlePositions (const double bpp[]) |
| Set the previously best known particle velocities. | |
| void | setBestParticlePositions (const std::vector< double > &bpp) |
| Sets the best position per particle. | |
| void | setBestParticlePositions (std::vector< double > &&bpp) |
| Sets the best position per particle, allows for a move. | |
| void | clearBestParticles () |
| Clear the previously best known particle velocities. | |
| void | clearCache () |
| Clear the particle swarm cache. | |
| void | initializeParticlesInsideBox (const double box_lower[], const double box_upper[], const std::function< double(void)> get_random01=TasDREAM::tsgCoreUniform01) |
| Randomly initializes all of the particle positions and velocities inside of a box. More... | |
| void | initializeParticlesInsideBox (const std::vector< double > &box_lower, const std::vector< double > &box_upper, const std::function< double(void)> get_random01=TasDREAM::tsgCoreUniform01) |
| Randomly initializes all of the particles, vector API overload. | |
Friends | |
| void | ParticleSwarm (const ObjectiveFunction f, const TasDREAM::DreamDomain inside, const double inertia_weight, const double cognitive_coeff, const double social_coeff, const int num_iterations, ParticleSwarmState &state, const std::function< double(void)> get_random01) |
| Applies the classic particle swarm algorithm to a particle swarm state. More... | |
Stores the information about a particle swarm.
M. R. Bonyadi and Z. Michalewicz, "Particle Swarm Optimization for Single Objective Continuous Space Problems: A Review," in Evolutionary Computation, vol. 25, no. 1, pp. 1-54, March 2017, doi: 10.1162/EVCO_r_00180.
|
inline |
Return the best known particle positions.
The method actually returns positions with one more than the total number of particles, the last num_dimensions entries of this vector contain the best particle position of the entire swarm.
| void TasOptimization::ParticleSwarmState::initializeParticlesInsideBox | ( | const double | box_lower[], |
| const double | box_upper[], | ||
| const std::function< double(void)> | get_random01 = TasDREAM::tsgCoreUniform01 |
||
| ) |
Randomly initializes all of the particle positions and velocities inside of a box.
The i-th component of each particle's position is uniformly sampled from the interval [box_lower[i], box_upper[i]]. The i-th velocity of each particle's velocity is uniformly sampled from the interval [-R, R] where R = abs(box_upper[i] - box_lower[i]). The uniform [0,1] random number generator used in the sampling is specified by get_random01.
|
friend |
Applies the classic particle swarm algorithm to a particle swarm state.
Runs num_iterations of the particle swarm algorithm to a particle swarm state to minimize the function f over the domain inside. The parameters of the algorithm are inertia_weight , cognitive_coeff , and social_coeff. The uniform [0,1] random number generator used by the algorithm is get_random01.
| f | Objective function to be minimized |
| inside | indicates whether a given point is inside or outside of the domain of interest |
| inertia_weight | inertial weight for the particle swarm algorithm |
| cognitive_coeff | cognitive coefficient for the particle swarm algorithm |
| social_coeff | social coefficient for the particle swarm algorithm |
| num_iterations | number of iterations to perform |
| state | holds the state of the particles, e.g., positions and velocities, see TasOptimization::ParticleSwarmState |
| get_random01 | random number generator, defaults to rand() |
| std::runtime_error | if either the positions or the velocities of the state have not been initialized |