#include #include #include "pso.h" double parabola(const double *p, const unsigned int dimensions){ return 10.0 - ((p[0]-25)*(p[0]-25)); } double rosenbrock(const double *p, const unsigned int dimensions){ return -pow(1.0 - p[0],2) - 100*pow(p[1] - pow(p[0],2),2); } int main(int argc, char** argv){ struct swarm s; /* Inverted parabola. */ init_swarm(10,1,2,1,1,1,1,1,¶bola,&s); randomize(-10,10,&s); run(1, 100, 1, 9.999, 1, 0.05, &s); printf("Parabola, best of 10/100 -> [%f] with fitness: %f\n", s.global_best[0],s.evaluate(s.global_best,1)); free_swarm(&s); /* 2D rosenbrock function */ init_swarm(100,2,4,1,1,1,1,1,&rosenbrock,&s); randomize(-10,10,&s); run(1,1000, 1, 0.0, 0, 0.0, &s); printf("Rosenbrock, best of 100/1000 -> [%f,%f] with fitness: %f\n", s.global_best[0],s.global_best[1],s.evaluate(s.global_best,2)); free_swarm(&s); return 0; }