Main Page
Namespaces
Classes
Files
File List
File Members
include
pso
pso.h
Go to the documentation of this file.
1
23
#ifndef PSO_H_
24
#define PSO_H_
25
26
#include <iostream>
27
#include <string>
28
#include <
time.h
>
29
#include <stdlib.h>
30
#include <vector>
31
#include <stack>
32
#include <map>
33
#include <math.h>
34
#include <set>
35
#include <queue>
36
#include <algorithm>
37
38
#include <fstream>
39
#include <sstream>
40
41
namespace
pso
{
42
43
class
Coordinate
{
44
public
:
45
float
x
;
46
float
y
;
47
Coordinate
()
48
{
49
x=0.0f;
50
y=.0f;
51
}
52
53
Coordinate
(
float
x,
float
y)
54
{
55
this->x=
x
;
56
this->y=
y
;
57
}
58
};
59
60
class
Particle
{
61
//friend:
62
// std::ostream& operator<<(std::ostream &output,const Particle &right);
63
64
public
:
65
Particle
(
float
x
,
float
y
)
66
{
67
Xmax=30.0f;
68
Xmin=0.0f;
69
Ymax=30.0f;
70
Ymin=0.0f;
71
Vxmax=Xmax-Xmin;
72
Vxmin=0-Vxmax;
73
Vymax=Ymax-Ymin;
74
Vymin=0-Vymax;
75
76
c1=2.0f;
77
c2=2.0f;
78
79
c.x=
x
;
80
c.y=
y
;
81
//p=100.0f;
82
p=pow(c.x-10.0f,2)+pow(c.y-20.0f,2);
83
Vx=(Xmax-Xmin)/8.0
f
;
84
Vy=(Xmax-Xmin)/8.0
f
;
85
86
pBest.x=
x
;
87
pBest.y=
y
;
88
}
89
90
void
setP
()
91
{
92
float
temp=pow(c.x-10.0f,2)+pow(c.y-20.0f,2);
93
if
(temp<p)
94
{
95
p=temp;
96
//pBest.x=c.x;
97
//pBest.y=c.y;
98
pBest=c;
99
}
100
}
101
102
float
getP
()
const
103
{
104
return
p;
105
}
106
107
Coordinate
getPBest
()
const
108
{
109
return
pBest;
110
}
111
112
void
setV
(
Coordinate
gBest,
float
w)
113
{
114
float
r1,r2;
115
r1=rand()/(float)RAND_MAX;
116
r2=rand()/(float)RAND_MAX;
117
Vx=w*Vx+c1*r1*(pBest.x-c.x)+c2*r2*(gBest.
x
-c.x);
118
if
(Vx>Vxmax)
119
Vx=Vxmax;
120
else
if
(Vx<Vxmin)
121
Vx=Vxmin;
122
Vy=w*Vy+c1*r1*(pBest.y-c.y)+c2*r2*(gBest.
y
-c.y);
123
if
(Vy>Vxmax)
124
Vy=Vxmax;
125
else
if
(Vy<Vxmin)
126
Vy=Vxmin;
127
}
128
129
float
getVx
()
const
130
{
131
return
Vx;
132
}
133
134
float
getVy
()
const
135
{
136
return
Vy;
137
}
138
139
void
setCoordinate
()
140
{
141
c.x=c.x+Vx;
142
if
(c.x>Xmax)
143
c.x=Xmax;
144
else
if
(c.x<Xmin)
145
c.x=Xmin;
146
c.y=c.y+Vy;
147
if
(c.y>Ymax)
148
c.y=Ymax;
149
else
if
(c.y<Ymin)
150
c.y=Ymin;
151
}
152
153
float
getX
()
const
154
{
155
return
c.x;
156
}
157
158
float
getY
()
const
159
{
160
return
c.y;
161
}
162
private
:
163
Coordinate
c
;
164
float
p
;
165
Coordinate
pBest
;
166
float
Vx
;
167
float
Vy
;
168
float
Xmax,
Xmin
;
169
float
Ymax,
Ymin
;
170
float
Vxmax,
Vxmin
;
171
float
Vymax,
Vymin
;
172
float
c1,
c2
;
173
};
174
};
175
#endif
pso::Particle::Vy
float Vy
Definition:
pso.h:167
pso::Particle::setCoordinate
void setCoordinate()
Definition:
pso.h:139
pso
Definition:
pso.h:41
pso::Particle::c2
float c2
Definition:
pso.h:172
time.h
f
f
pso::Particle::getVy
float getVy() const
Definition:
pso.h:134
pso::Particle::Vx
float Vx
Definition:
pso.h:166
pso::Particle::setV
void setV(Coordinate gBest, float w)
Definition:
pso.h:112
pso::Particle::getP
float getP() const
Definition:
pso.h:102
pso::Particle::Ymin
float Ymin
Definition:
pso.h:169
pso::Particle::c
Coordinate c
Definition:
pso.h:163
pso::Particle::getPBest
Coordinate getPBest() const
Definition:
pso.h:107
pso::Particle::pBest
Coordinate pBest
Definition:
pso.h:165
pso::Coordinate::y
float y
Definition:
pso.h:46
pso::Coordinate::Coordinate
Coordinate(float x, float y)
Definition:
pso.h:53
pso::Coordinate::Coordinate
Coordinate()
Definition:
pso.h:47
pso::Particle::Vymin
float Vymin
Definition:
pso.h:171
pso::Particle
Definition:
pso.h:60
pso::Coordinate::x
float x
Definition:
pso.h:45
pso::Particle::setP
void setP()
Definition:
pso.h:90
pso::Particle::Particle
Particle(float x, float y)
Definition:
pso.h:65
pso::Particle::getY
float getY() const
Definition:
pso.h:158
pso::Particle::Xmin
float Xmin
Definition:
pso.h:168
pso::Particle::p
float p
Definition:
pso.h:164
pso::Particle::getX
float getX() const
Definition:
pso.h:153
pso::Particle::Vxmin
float Vxmin
Definition:
pso.h:170
pso::Coordinate
Definition:
pso.h:43
pso::Particle::getVx
float getVx() const
Definition:
pso.h:129
pso
Author(s):
autogenerated on Mon Jun 10 2019 14:02:26