From: ametama Date: Wed, 17 Dec 2025 23:02:34 +0000 (+0100) Subject: fix(params): remove global params X-Git-Url: https://git.wafflesoft.org/?a=commitdiff_plain;h=e70e6d0631388b4c2da6b3f58a3eaf2514ae29ad;p=cgo.git fix(params): remove global params --- diff --git a/src/swarm.c b/src/swarm.c index 3fe83ff..fbf9280 100644 --- a/src/swarm.c +++ b/src/swarm.c @@ -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];