50 int main(
int argc,
char *argv[]){
53 if(argc >= 11 && strcmp(argv[1],
"pso") == 0){
55 double w, c1, c2, s1, s2, R;
59 for(i=2; i < 19; i+=2){
60 if(strcmp(argv[i],
"-w") == 0) w = atof(argv[i+1]);
61 else if(strcmp(argv[i],
"-c1") == 0) c1 = atof(argv[i+1]);
62 else if(strcmp(argv[i],
"-c2") == 0) c2 = atof(argv[i+1]);
63 else if(strcmp(argv[i],
"-n") == 0) n = atoi(argv[i+1]);
64 else if(strcmp(argv[i],
"-p") == 0) p = atoi(argv[i+1]);
65 else if(strcmp(argv[i],
"-s1") == 0) s1 = atof(argv[i+1]);
66 else if(strcmp(argv[i],
"-s2") == 0) s2 = atof(argv[i+1]);
67 else if(strcmp(argv[i],
"-M") == 0) M = atoi(argv[i+1]);
68 else if(strcmp(argv[i],
"-R") == 0) R = atof(argv[i+1]);
70 cout <<
"[CSMOn] Called search method PSO with parameters: s1=" << s1 <<
", s2=" << s2 <<
", w=" << w
71 <<
", c1=" << c1 <<
", c2=" << c2 <<
", n=" << n <<
", p=" << p <<
", M=" << M <<
", R=" << R << endl;
81 double *bestPos =
new double[n];
85 cout << bestPos[i] <<
", ";
99 cout <<
"Wrong Parameters !" << endl;
100 cout <<
"Options:" << endl;
101 cout <<
" pso -w <w-value> -c1 <c1-value> -c2 <c2-value> -n <n-dimensions> -p <n-particles> -s1 <lower_bound> -s2 <upper-bound> -M <max-evals> -R <relaxation>" << endl;
114 for(
int i=0; i < n; i++){
115 s += x[i] * x[i] - 10 * cos(2 * PI * x[i]);
Convergence Stabilization Modeling operating in Online Mode.
int getBestPos(double *x)
Get the final optimized result (position).
Particle Swarm Optimization.
double fitnessFunction(double *x, int n)
Fitness function implementation.
void run()
Call this method to execute the search.
double getFitness()
Get the final fitness value.
int getNEvals()
Get the actual number of evaluations executed.