144 Agent-Based Modeling and Simulation with Swarm
boids within the field
of view
FIGURE 6.8: Each bo id has its own field of view .
// the number of ‘‘boid’’ in the field of sight is substituted
// in ‘‘Num’’ in the lines above these.
gX /= Num;
gY /= Num;
// coordinates of the center of gravity are obtained in (gX, gY).
// in the lines above,
// the coordinates of the closest boid are obtained in (minDx,
minDy).
Bug nearestBug =
(Bug)world.getObjectAtX$Y((minDX+worldXSize)%worldXSize,
(minDY+worldYSize)%worldYSize);
// the closest boid is kept in nearestBug.
//direction of center of gravity is obtained in this variable
float gVX = 0.0f, gVY = 0.0f;
float tmp = (float)Math.sqrt((float)((gX-xPos)*(gX-xPos)+(gY-
yPos)*(gY-yPos)));
gVX = (float)( gX - xPos ) / tmp;
gVY = (float)( gY - yPos ) / tmp;
// (xPos, yPos) shows the current position of boid.
float sVX = 0.0f, sVY = 0.0f; // obtains its own velocity vector
sVX = (float)Math.cos( direction );
sVY = (float)Math.sin( direction );
Particle S warm Simulation 145
float nVX = 0.0f, nVY = 0.0f;
// obtains the velocity vector of the closest boid
nVX = (float)Math.cos( nearestBug.direction );
nVY = (float)Math.sin( nearestBug.direction );
float fVX, fVY; // obtains the new directional vector
fVY = gravityWeight * gVY + sVY + nearWeight * nVY;
newDirection = Vector2Direction( fVX, fVY );
float dX = (float)(minDX - xPos);
float dY = (float)(minDY - yPos);
// from the current position,
// obtains the directional vector towards the closest boid
float inner = dX * fVX + dY * fVY; // used to determine the
proximity
float nearestDist = (float)Math.sqrt( dX * dX + dY * dY );
// obtains the new speed ‘‘new speed’
// by changing the current speed ‘‘speed’’
if( inner > 0 ){ // If the closest boid was in front of self
if( nearestDist > optDistance ){
newSpeed = speed * accel; // speed up
else{
newSpeed= speed / accel; // speed down
}
}else{ // if the closest boid was behind
if( nearestDist > optDistance ){
newSpeed= speed / accel; // speed down
}else{
newSpeed = speed * accel; //speed up
}
}
}
After that, the following lines obtain the new coordinates (newX, newY) of the
boid.
newX = xPos + (int)( newSpeed * Math.cos( newDirection ) );
newY = yPos + (int)( newSpeed * Math.sin( newDirection ) );
Note that the behavior of the “boid” group slightly differs by changing
gravityWeight and nearWeight to various values. Apar t from this, the ex-
tended versions of boid” are also provided as follows:
Two types of tribes/races of boid are introduced.
Obstacles are placed in the map.
146 Agent-Based Modeling and Simulation with Swarm
6.3 Swarm Chemistry
Swarm Chemistry is a system designed by Sayama [104] to model and
simulate the behavior of groups of, for example, fish and ants.
Agents in Swa rm Chemistry move in two-dimensional spac e according to
simple r ules based on a number of parameters. The position vector X
i
and
velocity vector V
i
at the next step of the agents in the population are deter-
mined from the current position ve c tor X
i
and velocity vector V
i
according
to the following process.
1. Find agents near an agent X
i
with Euclidean distance les s than r.
2. If there are no agents nearby, a random value of [0.5, 0.5] is added to
the x and y components of the acceleration A
i
of X
i
.
3. If there is at least one agent nearby, the acceleration A
i
of X
i
is updated
using the following equation. Here,
¯
X
i
is the average position and
¯
V
i
is
the average velocity of nearby agents.
A
i
= c
1
(X
i
¯
X
i
) + c
2
(V
i
¯
V
i
) + c
3
Σ
N
j=1
(X
i
X
j
)/|X
i
X
j
|
2
(6.3)
In addition, a random value of [0.5, 0.5] is a dded to the x and y com-
ponents of A
i
with a probability c
4
.
4. Add A
i
to V
i
.
5. If |V
i
| > v
m
, multiply V
i
by a constant value such that the absolute
value becomes v
m
.
6. Up date V
i
using the equation:
V
i
c
5
(v
n
/|V
i
| · V
i
) + (1 c
5
)V
i
(6.4)
7. Perform the above procedure on all agents.
8. Substitute the velocity V
i
of each agent with V
i
to update the velocity.
9. Add V
i
to the positions of each agent X
i
to obtain the positions at the
next step X
i
.
There are eight control parameters in the update process: r, v
n
, v
m
, c
1
, c
2
, c
3
,
c
4
, c
5
. Using multiple populations with different parameters results in interac-
tions between populations, and complex behavior can be observed.
The populations shown in Fig. 6 .9 are an example of behavior arising from
this system, where a swarm group rotates around another swarm group. The
control parameters are
Particle S warm Simulation 147
FIGURE 6.9: Behavior in Swarm C hemistry (1).
FIGURE 6.10:
Behavior in Swarm Chemistry (2).
60*{73.03, 0.61, 5, 0.75, 0.17, 28.81, 0.32, 0.37}
140*{93.28, 5.15, 10.71, 0.64, 0.58, 96.71, 0.07, 0.41}
Where 60 and 140 are the number of boids in ea ch population.
Figure 6.10 shows a behavior where the large swarm group is reflected at
the walls and is sometimes attracted to the small swarm group. The control
parameters are
164*{52.86, 9.69, 13.19, 0.93, 0.5, 23.84, 0.3, 0.85}
36*{73.31, 0.76, 3.47, 0.35, 0.32, 7.47, 0.09, 0.22}
Figure 6.11 is a screenshot of a system where the control parameters are
adjusted through interactive evolutionary computation (IEC) to obtain a sys-
tem that behaves according user prefere nce s. This system is a Java applet that
is op e nly available online.
1
1
http://www.iba.t.u-tokyo.ac.jp/~akio/swarm_chemistry.html
148 Agent-Based Modeling and Simulation with Swarm
FIGURE 6.11: A snapshot of Swarm Chemistry.
A user observes the behavior of two s ystems to the right and left, a nd
chooses the system that he likes. Repeating this pairwise co mparison optimizes
the parameter to what the user likes. When a system very close to what the
user wants app e ars, the user can fine-tune it by clicking the “Local Search
Mode” button at the top.
6.4 PSO: particle swarm optimization
This section introduces the optimization method “particle swarm optimiza-
tion” (PSO), which differs slightly from GA and GP. PSO is an algorithm from
the field o f Swarm Intelligence. It was first described by Kennedy and Ebe rhart
as an alternative to GA in 1995 [71]. The alg orithm for PSO was conceived
on the basis of observations of certain socia l behavior in lower-class anima ls
or inse c ts. In contrast to the c oncept of modifying genetic codes using genetic
operations as used in GA, in PSO the moving individuals (called particles”)
are considered where the next movement of an individual is determined by the
motion of the individual itself and that of the surrounding individuals. It has
been established that PSO has capabilities equal to those of GA for function
optimization problems. There have been s e veral comparative studies on PSO
and standard GA (see [3, 35, 51, 73]).
Below we describe the orig ins of PSO, o utline the procedure, compare its
search efficiency with that of GA, and provide some examples of its applica-
tion.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.233.222