-
Notifications
You must be signed in to change notification settings - Fork 0
/
Particle.h
39 lines (29 loc) · 1.03 KB
/
Particle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef CONCURRENT_PSO_PARTICLE_H
#define CONCURRENT_PSO_PARTICLE_H
#include <vector>
#include "SwarmParams.h"
#include "Bounds.h"
#include "ObjectiveFunction.h"
class Particle {
public:
Particle(const std::vector<double> &position, const std::vector<double> &velocity);
void update(std::vector<double> bestSwarmPosition, const Bounds &bounds, ObjectiveFunction *function, const SwarmParams ¶ms);
std::vector<double> getPosition() const {
return position;
};
private:
std::vector<double> position;
std::vector<double> velocity;
std::vector<double> bestPosition;
void updateVelocity(const std::vector<double> &bestSwarmPosition, const SwarmParams ¶ms);
void updatePosition(const Bounds &bounds);
void updateBestPosition(ObjectiveFunction *objectiveFunction);
static double constrict(double value, double min, double max) {
if (value < min)
return min;
if (value > max)
return max;
return value;
}
};
#endif //CONCURRENT_PSO_PARTICLE_H