fix(params): remove global params
authorametama <ametama@wafflesoft.org>
Wed, 17 Dec 2025 23:02:34 +0000 (00:02 +0100)
committerametama <ametama@wafflesoft.org>
Wed, 17 Dec 2025 23:02:34 +0000 (00:02 +0100)
src/swarm.c

index 3fe83ffd924a1cbc00b75305e45ce013bd4869e6..fbf92808b36a2f8a1b59f2f016583745366d2281 100644 (file)
@@ -3,10 +3,6 @@
 #include "swarm.h"
 #include "vector.h"
 
-double c = 2.05;
-double s = 2.05;
-double w = 0.8;
-
 double rands() {
   return (double) rand() / RAND_MAX;
 }
@@ -41,7 +37,7 @@ void swarm_velocity_update(swarm *sw) {
   for (int p = 0; p < sw->params.particlec; p++) {
     particle *pt = &sw->particles[p];
     for (int d = 0; d < sw->params.dim; d++)
-      pt->velocity[d] = w * pt->velocity[d] + c * rands() * (pt->best.x[d] - pt->current.x[d]) + s * rands() * (sw->global_best->current.x[d] - pt->current.x[d]);
+      pt->velocity[d] = sw->params.w * pt->velocity[d] + sw->params.c * rands() * (pt->best.x[d] - pt->current.x[d]) + sw->params.s * rands() * (sw->global_best->current.x[d] - pt->current.x[d]);
   }
   for (int p = 0; p < sw->params.particlec; p++) {
     particle *pt = &sw->particles[p];