73 if(strcmp(method,
"pso") == 0){
75 double w, c1, c2, s1, s2, R;
80 if(strcmp(inParam[i].name,
"w") == 0) w = inParam[i].d;
81 else if(strcmp(inParam[i].name,
"c1") == 0) c1 = inParam[i].d;
82 else if(strcmp(inParam[i].name,
"c2") == 0) c2 = inParam[i].d;
83 else if(strcmp(inParam[i].name,
"n") == 0) n = inParam[i].i;
84 else if(strcmp(inParam[i].name,
"p") == 0) p = inParam[i].i;
85 else if(strcmp(inParam[i].name,
"s1") == 0) s1 = inParam[i].d;
86 else if(strcmp(inParam[i].name,
"s2") == 0) s2 = inParam[i].d;
87 else if(strcmp(inParam[i].name,
"M") == 0) M = inParam[i].i;
88 else if(strcmp(inParam[i].name,
"R") == 0) R = inParam[i].d;
90 cout <<
"[CSMOn] Called search method PSO with parameters: s1=" << s1 <<
", s2=" << s2 <<
", w=" << w
91 <<
", c1=" << c1 <<
", c2=" << c2 <<
", n=" << n <<
", p=" << p <<
", M=" << M <<
", R=" << R << endl;
94 PSO *pso =
new PSO(fitnessFunction, s1, s2, p, n, w, c1, c2);
101 double *bestPos =
new double[n];
103 for(i=0; i < n; i++){
104 outPos[i] = bestPos[i];
110 for(i=0; i < 2; i++){
111 if(strcmp(outParam[i].name,
"nEvals") == 0) outParam[i].i = evals;
112 else if(strcmp(outParam[i].name,
"fit") == 0) outParam[i].d = fit;
121 else printf(
"Search method %s not supported yet.", method);
struct _Param Param
Contains a parameter received from / sent to the Python caller.
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.
Contains a parameter received from / sent to the Python caller.
double getFitness()
Get the final fitness value.
void search(char *method, Param *inParam, Param *outParam, double *outPos, callback_t fitnessFunction)
The wrapper function for Python calls.
int getNEvals()
Get the actual number of evaluations executed.