-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.h
41 lines (33 loc) · 935 Bytes
/
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
40
41
//
// Created by Madalin on 05/16/20.
//
#ifndef UTILLS
#define UTILLS
#include "Utills.h"
#endif
#include <vector>
#include <random>
#include <ostream>
class Particle{
public:
std::vector<double> position;
std::vector<double> velocity;
std::vector<double> bestPos;
Particle(){
bestPos = std::vector<double>(2);
}
Particle(int dim, double min, double max){
position = Utills::random_vect(dim, min, max);
velocity = std::vector<double>(dim);
bestPos = position;
}
void update_pos(double f(std::vector<double>)){
position = Utills::VecOp(position,velocity, 1); //next_pos = pos + velocity
if(f(bestPos) > f(position))
bestPos = position;
}
friend std::ostream &operator<<(std::ostream &os, const Particle &particle) {
os << "position: " << particle.position[0] << " " << particle.position[1];
return os;
}
};