-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.hpp
47 lines (38 loc) · 915 Bytes
/
Particle.hpp
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
40
41
42
43
44
45
46
47
#pragma once
#include <memory>
#include <vector>
#include "MathVector.hpp"
#include "Parameters.hpp"
std::vector<double> randVector(DimensionLimits);
struct Particle
{
typedef std::shared_ptr<Particle> ParticlePtr;
typedef std::vector<ParticlePtr> Particles;
int id;
MathVector x;
MathVector v;
MathVector p;
double x_fitness;
double p_fitness;
DimensionLimits dimension;
ParticlePtr best;
Particles neighbours;
double (*func)(MathVector);
Parameters parameters;
Particle(int id, DimensionLimits d, double (*f)(MathVector),
Parameters params):
id(id),dimension(d), func(f), parameters(params)
{
x.randomVector(d);
v.randomVector(d);
p = x;
x_fitness = func(x);
p_fitness = x_fitness;
};
void addSampleNeighbours(Particles);
void updateVelocity();
void updatePosition();
void checkBoundary();
void updateBest();
};
std::ostream &operator<<(std::ostream &out, Particle p);