I need to realize such algorith in practice. Can anybody refere to any worksble example as its difficult to find acceptable code despite a lot of swarm intelligence links.
http://www.cplusplus.com/forum/general/96872/--is such code there appropriate for such things. What technology to use. As I have code in one copybook on Interactiev graphic programming (5*2 p.) but there is structure of points (particles). But as i konw the C++ needs some link to graphical shell (openGL etc.). Anyway can i launch such code as it is without external shell--includes, classes:
for example how to link this code for parttyicles for swarm with different velocities that is moving in some area (boundary ) where is central point:
typedefpoint4vec4;
typedefstructparticle
{
intcolor;
point4position;
vec4velocity;
floatmass;
}particle;
intnum_particles;
for(inti=0;i<num_particles;i++)
{
particles[i].mass=1.0;
particles[i].color=i%NUM_COLORS;
for(intj=0;j<3;j++)
{
particles[i].position[j]=2.0*((float)rand()/RAND_MAX)-1.0;
particles[i].velocity[j]=speed*2.0*((float)
rand()/RAND_MAX)-1.0;
}
particles[i].position[3]=1.0;
particles[i].velocity[3]=0.0;
}
voiddisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
for(i=0;i<num_particles;i++)
{
point_colors[i+24]=colors[particles[i].color];
points[i+24]=particles[i].position;
}
glBindBuffer(GL_ARRAY_BUFFER,buffers[0]);
glBufferData(GL_ARRAY_BUFFER,sizeof(points),+sizeof(colors)NULL,
GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,0,sizeofpoints,points);
glBufferSubData(GL_ARRAY_BUFFER,sizeof(points),sizeof(colors),colors);
glDrawArrays(GL_POINTS,24,num_particles);
glutSwapBuffers();
}
floatlast_time,present_time;
voididle(void)
{
inti,j;
floatdt;
present_time=glutGet(GLUT_ELAPSED_TIME);/*inmilliseconds*/
dt=0.001*(present_time-last_time);/*inseconds*/
for(i=0;i<num_particles;i++)
{
for(j=0;j<3;j++)
{
particles[i].position[j]+=dt*particles[i].velocity[j];
particles[i].velocity[j]+=dt*forces(i,j)/particles[i].mass;
}
collision(i);
}
last_time=present_time;
glutPostRedisplay();
}
floatcoef;/*coefficientofrestitution*/
voidcollision(intn)
{
inti;
for(i=0;i<3;i++)
{
if(particles[n].position[i]>=1.0)
{
particles[n].velocity[i]=-coef*particles[n].velocity[i];
particles[n].position[i]=1.0-coef*
(particles[n].position[i]-1.0);
}
if(particles[n].position[i]<=-1.0)
{
particles[n].velocity[i]=-coef*particles[n].velocity[i];
particles[n].position[i]=-1.0-coef*
(particles[n].position[i]+1.0);
}
}
}
boolgravity=TRUE;
floatforces(inti,intj)
{
if(!gravity)return(0.0);
elseif(j==1)return(-1.0);
elsereturn(0.0);
}
So it only the particles but swarm should have some apalication of rand() function to its velocities. Despite modulus should have be constant(?), In swarm there are such notions as fitness (do not know what it means), best position etc. Teacher told there should be central insect but wjhat like its movement should be. And first ofll all tried to create this insects: with the predefined insect or only define after? The main what should be movement. To create the particlec(with random in direction) speeds (but there are should be x?y?z parts of it) with constant modulus according to colour. After getting its speeds the insects should move in one direction? (as I need to use affine transformations). When insect go out of boundary then the speed should change (how in what direction--randomly in another--no obligatory to 180 degrees ). I tried to use Opengl but net even now any cues for that technology. And glVertex have just three components (x,y ,z). CAn I include glVertex to particle structure? So how conncet the abovementioned code for the theory of swarm as its structure(particle) should have x, y, z coordinates(for position and velocity)? I could not use mass field and gravitation force from abovementioned code. Please help.