aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pso/main.cpp20
-rw-r--r--pso/pso-help.pat1
-rwxr-xr-xpso/pso.cwbin0 -> 146644 bytes
3 files changed, 12 insertions, 9 deletions
diff --git a/pso/main.cpp b/pso/main.cpp
index 1ebc296..1940993 100644
--- a/pso/main.cpp
+++ b/pso/main.cpp
@@ -23,6 +23,7 @@
#include <flext.h>
#include <stdlib.h>
#include <math.h>
+#include <time.h>
// check for appropriate flext version
#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400)
@@ -99,10 +100,11 @@ FLEXT_NEW_3("pso",pso, int,int,int)
pso::pso(int Popsize, int Dimen, int HoodSize)
{
// Say hello
- post("--------------------------------------------\nParticle Swarm Optimizer (PSO)\nCopyright Ben Bogart 2003.\nBased on code by Thomas Grill & Jim Kennedy.\n--------------------------------------------");
-
- // var defines
- int i,j,k;
+ post("--------------------------------------------");
+ post("Particle Swarm Optimizer (PSO)");
+ post("Copyright Ben Bogart 2003.");
+ post("Based on code by Thomas Grill & Jim Kennedy.");
+ post("--------------------------------------------");
// default vars
this->Min = 0;
@@ -126,7 +128,7 @@ pso::pso(int Popsize, int Dimen, int HoodSize)
// define inlets:
// first inlet must always by of type anything (or signal for dsp objects)
- AddInAnything(); // add one inlet for any message
+ AddInAnything("Send 'help' message for details..."); // add one inlet for any message
// define outlets:
AddOutList("Particle positions.");
@@ -252,7 +254,7 @@ void pso::set_pop(int argc,t_atom *argv)
void pso::set_particle(int argc,t_atom *argv)
{
- int i,particle,in,out;
+ int i,particle;
// If the number of arguments matches the number of dimensions plus the index value
if ( argc == this->dimen+1 )
@@ -295,7 +297,7 @@ void pso::set_target(int argc,t_atom *argv)
{
for (i=0; i<dimen; i++)
{
- this->target[i] = GetFloat(argv[i]);
+ this->target[i] = GetAFloat(argv[i]);
}
post("%s: Target Set.", thisName() );
} else {
@@ -428,7 +430,7 @@ void pso::iterate()
void pso::output_positions()
{
- int d,p,atoms;
+ int d,p;
t_atom atom;
t_atom p_atom;
AtomList list;
@@ -440,7 +442,7 @@ void pso::output_positions()
list.Clear();
// start the lists with the index of the particle
- SetFloat(p_atom, (float)p );
+ SetInt(p_atom, p );
list.Append(p_atom);
for (d=0; d< this->dimen; d++)
diff --git a/pso/pso-help.pat b/pso/pso-help.pat
new file mode 100644
index 0000000..fde5d58
--- /dev/null
+++ b/pso/pso-help.pat
@@ -0,0 +1 @@
+max v2; #N vpatcher 179 117 654 711; #P button 147 287 29 0; #P user hslider 105 540 18 128 128 1 0 0; #P user hslider 105 523 18 128 128 1 0 0; #P user hslider 105 506 18 128 128 1 0 0; #P user hslider 105 489 18 128 128 1 0 0; #P user hslider 105 472 18 128 128 1 0 0; #P user hslider 95 162 18 128 128 1 0 0; #P flonum 38 422 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P newex 18 378 50 9 pso 5 1 2; #P comment 72 379 254 196618 5 particles \, 1 dimention \, and neightborhood size 2; #P message 121 226 53 9 target \$1; #P message 134 206 83 9 rand_pop 0 127; #P comment 261 206 146 196618 $1 initialize the population; #P newex 18 443 89 9 route 0 1 2 3 4; #P message 108 246 50 9 reset; #P comment 260 228 95 196618 $2 Set the Target; #P comment 260 249 114 196618 $3 Initialize the PSO; #P message 34 167 50 9 help; #N vpatcher 10 59 400 186; #P message 22 52 80 9 optim_thresh 0; #P outlet 16 77 15 0; #P comment 108 52 214 196618 Smaller systems like smaller thresholds.; #P newex 22 30 50 9 loadbang; #P connect 3 0 2 0; #P connect 0 0 3 0; #P pop; #P newobj 18 138 61 9 patcher init; #P newex 58 402 86 9 print Minimized; #P message 94 321 50 9 1; #P message 147 321 50 9 0; #P newex 95 185 50 9 t b b f b; #P comment 260 321 98 196618 $4 Start iterating; #P comment 259 407 96 196618 $5 Stop iterating; #P comment 243 163 86 196618 <- Start Here; #P comment 14 48 398 196618 A PSO generates a random (or preset) polulation of solutions. These particles accellerate towards the neighbors' and global best solution. As the PSO iterates the population becomes more and more similar to the target. You can specify the number of particles \, dimentions and the size of the neighborhoods. Please note that if you change the target before the PSO has minimized it may not minimize.; #P newex 109 347 50 9 metro 20; #P comment 14 27 291 196617 PSO - Particle Swarm Optimizer - Copyright Ben Bogart 2003; #P connect 1 0 20 0; #P connect 10 0 20 0; #P connect 11 0 20 0; #P connect 14 0 20 0; #P connect 17 0 20 0; #P connect 18 0 20 0; #P connect 20 0 15 0; #P connect 20 1 21 0; #P connect 20 2 9 0; #P connect 6 0 8 0; #P connect 22 0 6 0; #P connect 15 0 23 0; #P connect 15 1 24 0; #P connect 15 2 25 0; #P connect 15 3 26 0; #P connect 15 4 27 0; #P connect 6 1 14 0; #P connect 7 0 1 0; #P connect 8 0 1 0; #P connect 6 2 18 0; #P connect 6 3 17 0; #P connect 20 2 28 0; #P connect 28 0 7 0; #P pop; \ No newline at end of file
diff --git a/pso/pso.cw b/pso/pso.cw
new file mode 100755
index 0000000..b2b969f
--- /dev/null
+++ b/pso/pso.cw
Binary files differ