Ant Colony Simulation Over MPI

peanutunderwearΛογισμικό & κατασκευή λογ/κού

7 Νοε 2013 (πριν από 4 χρόνια)

89 εμφανίσεις











Ant Colony Simulation Over MPI


Adam Cox

CEN 4516


Computer Networks

Florida Gulf Coast University

December 15, 2006
Cox
2
?

1. Introduction



Swarm intelligence is a type of artificial intelligence which focuses on the global behavior of
many simple ag
ents acting within an environment. Some inspiration for creating swarm intelligence
comes from biology. Many creatures have a knack for finding clever solutions to various problems by
acting as a group. Birds fly in cohesive flocks, schools of fish are abl
e to confuse predators, and insects
are excellent at finding the shortest path between their nests and food. Individually, a bird, fish, or
insect is not considered intelligent (that is, they don't have human levels of understanding and
reasoning), but the

interaction of several individuals results in interesting group behaviors. Ant colony
simulation is a form of swarm intelligence research which studies the emergent behavior of ant
-
like
agents.



Ant colony simulation is particularly interesting because e
ach agent doesn't directly interact
with one another to communicate. Instead, they communicate via pheromones placed within their
environment. As agents roam the environment, they detect pheromones placed by other agents and
react accordingly.



For exampl
e, whenever an ant finds food, it will leave a trail of pheromone behind as it travels
back to the colony. The particular pheromone trail left behind sends a message to other ants saying
“this way leads to food.” When another ant encounters the trail, it i
s highly likely that they will decide
to follow it (or else risk starving!). Other types of pheromones used by ants include a “do not enter”
pheromone (commonly used to block trails which no longer lead to food) and an attack pheromone.


1.1 Acronyms and D
efinitions



AI
-

acronym meaning Artificial Intelligence.



Embarrassingly Parallel Problem


a computing problem in which each step can be computed
independently of all other steps.



MPI


acronym meaning Message Passing Interface, a parallel processing

protocol.



Swarm Intelligence


a subset of AI which focuses on the interaction of many simple agents to
create global behaviors.


2. Problem Statement



Ant colony simulations provide the most useful information when running a very large number
of agent
s over a long period of time (or simulated time). However, each additional agent run within a
simulation incurs a higher computational cost. If the number of agents becomes too large, waiting for
global behaviors to emerge can take too long to compute. Thi
s places the simulation manager in the
difficult position of finding a balance between computation time, number of agents to run, and most
interesting global behavior.


3. Solution



This project shall eliminate the trade off between number of agents and c
omputation time by
using a MPI
-
based parallel programming model. By utilizing the processing power of multiple
Cox
3
?

computers, it is possible to simulate a very large number of agents in a relatively short amount of time.
Computing swarm intelligence is an exam
ple of an “embarrassingly parallel” problem because each
agent's logic is independent of every other agent's logic.



The simulation's general flow is displayed visually in figure 3.1 below:
Cox
4
?

F
igure 3.1


Simulation program loop


3.1 Code Modules



The fol
lowing list details the purpose of each code module within the program.




Simulation


the main class of the program. This class manages the initialization and shutdown
of all other modules within the program. Other duties include controlling program flow,
handling messages between the master and slave machines, updating the front end state, and
handling user input.




FrontEnd


graphical interface to the user. The front end provides a visual representation of the
simulation world. The front end also provides

a means for user interaction with the simulation.




Grid


a manager class which tracks and controls all of the nodes in the world space.




Node


a unit of space within the simulation world. The world space consists of several nodes
linked together.




GridO
bject


abstract class from which all simulated objects are derived. Stores data common
Cox
5
?

to all objects and provides a common interface for the management of all objects.




Ant


derived from GridObject. The ant is the primary agent of the simulation. Their
purpose is
to safely search for food and transport it to the colony mounds.




Food


derived from GridObject. The food object represents node locations which contain a
food store. Ants do not move the food object directly.




Mound


derived from GridObject.
The mound object represents node locations which contain
an ant mound. Functions include storing food and spawning new ants.




Pheromone


derived from GridObject. The pheromone object represents node locations which
contain a concentration of pheromone.


3
.2 Pseudocode



The following functions describe the general program flow for the simulation. The first function
is written from the perspective of the master machine, and the second function is written from the
perspective of a slave machine.



General pr
ogram flow (Master):



Initialize MPI



MPI_Receive ready message from all slaves



Initialize simulation world



Initialize front end



Begin program loop




Build queue of objects to be simulated




While simulation queue is not empty





Pop object from

queue





Find a ready slave





MPI_Send popped object id to available slave for processing





MPI_Receive results of object logic from slave





Update object state in world




Update world state in front end



Shutdown front end



Shutdown simulation



Shutdown MPI



General program flow (Slave):



Initialize MPI



MPI_Send ready message to master



Begin program loop




MPI_Receive object id for processing




MPI_Send busy message to master




Process object logic




MPI_Send results to master




MPI_
Send ready message to master



Shutdown MPI


Cox
6
?

This final function describes the general ant logic.



If ant has food



If travel stack is empty




Deposit food at mound



Else




Deposit pheromone at current location




Pop next node from travel stack




Mo
ve to popped node


Else



Scan current node for food



If food is found




Take food



Else




Add current node to travel stack




Scan surrounding nodes for food and pheromones




If food is found





Move to node id containing food




Else if pheromone i
s found





Move to node id containing most attractive pheromone




Else





Move to node id with fewest instances in travel stack


4. Implementation



The MPI implementation used for this project is MPICH2, available from the Argonne National
Laboratory
[1
]
. MPICH2 has been programmed to conform to the MPI
-
2 standard and is downloaded as
source code. MPICH2 was compiled using GCC version 4.0.3. The simulation source code is written in
C++ and is also compiled with GCC version 4.0.3 through the Anjuta IDE
[9]
. The Linux operating
systems was used exclusively for the development. Unix/Linux is also the target platform for the final
software program.


The simulation's graphical front end requires that the primary machine in the computing cluster
be loaded with e
quipped with an X Windows implementation as well as an OpenGL capable video
card.



Although Linux is used exclusively for this project, it is possible to view the simulation front
end in Windows. To do this, one must install an X server and a SSH client
which allows X11
forwarding on the Windows machine. The recommended solution is to use PuTTY
[2]

for SSH and
Xming
[3]

for the X server.


4.1 Compiling MPICH2



The following steps detail how to compile and install MPICH2 in Linux with the BASH shell:


1.

Downl
oad and unzip the MPICH2
[1]

source code. This will create a folder with the MPICH2
files inside (referred to as $UNZIPPEDPATH)

1.

tar
-
xfz mpich2.tar.gz

Cox
7
?

2.

If necessary, download and install the Python
[7]

programming language onto each machine in
the cluster. MP
ICH2 requires version 2.2 or higher.

3.

If necessary, download a C compiler
[8]

onto the machine where MPICH2 will be compiled.

4.

Create a directory for the compiled MPICH2 installation (referred to as $INSTALLPATH)

1.

mkdir $INSTALLPATH

5.

Make $INSTALLPATH sharable
with other computers in the cluster

1.

chmod 777

6.

Create a directory for the build process (referred to as $BUILDPATH)

1.

mkdir $BUILDPATH

7.

Configure MPICH2

1.

cd $BUILDPATH $UNZIPPEDPATH/configure
-
prefix=$INSTALLPATH 2>&1 tee
configure.log

8.

Build MPICH2

1.

make 2>&1 te
e make.log

9.

Install MPICH2

1.

make install 2>&1 tee install.log

10.

Create a file called “.mpd.conf” in the home directory of the user which will be running MPI.

11.

Add the following text to .mpd.conf. Use only alphanumeric characters. Substitute a unique
secret word

in place of the “whatever_you_want” placeholder.

1.

secretword=whatever_you_want

12.

Make the .mpd.conf file readable and writable for only the user

1.

chmod 600

13.

Copy .mpd.conf into the home directory of each slave machine in the cluster


4.2 Running the Simulation

from the Unix/Linux Command Line



Since FGCU uses password protected SSH connections, we must fake an MPI cluster. To do
this, each machine is added to the MPI ring manually. The following steps use the BASH shell syntax
and assume the same path name var
iables described in section 4.1.


1.

Put the MPICH2 binaries in your path

1.

export PATH=$INSTALLPATH/bin:$PATH

2.

Start the master MPI daemon

1.

mpd &

3.

Discover the host name and port of the MPI connection. The switch uses the letter L, not the
number one.

1.

mpdtrace
-
l

4.

The output should look similar to this: satnet.fgcu.edu_33030. The output is formatted as
hostname_portnumber. Therefore, the host name of this MPI connection is satnet.fgcu.edu, and
the port number is 33030.

5.

Add a slave to the MPI cluster, substituting

the values obtained from step 4 for host_name and
port_number

1.

mpd
-
n
-
h host_name
-
p port_number &

6.

Repeat step 5 as many times as desired

7.

Run the simulation

1.

mpiexec ./ants


4.3 Running the Simulation from Windows with PuTTY and Xming


Cox
8
?


To run the simulati
on in Windows, one must follow these steps:


1.

Download PuTTY
[2]

2.

Download Xming from the Sourceforge
[3]

link

3.

Run the Xming installation file

4.

Install Xming with the default options

5.

Start Xming. One can ensure that Xming is running by the Xming icon located in

the Windows
system tray.

6.

Run PuTTY (refer to figure 4.3.1 for this step)

1.

Click Connection
-
> SSH
-
> X11

2.

Check the “Enable X11 forwarding” box

3.

Type “localhost:0” into the “X display location” text box

7.

Log into the remote master machine and run the program
as detailed in section 4.2


F
igure 4.3.1


PuTTY setup


4.4 Simulation Results



The simulation front end can run in two separate windows: a command line window and an
OpenGL window. If the simulation executable is run from a graphical desktop environmen
t on a
Unix/Linux system, the command line window will not be displayed. If the program is run from the
command line on a Unix/Linux system, the command shell will remain open while the simulation
opens a separate OpenGL window. On a Windows system, both t
he command line window and
OpenGL window are created when running the simulation executable.



The command line window, also called the event window, informs the user of events happening
in the simulation world as they happen in real time. A screenshot of
the event window is shown below
in figure 4.4.1.

Cox
9
?


F
igure 4.4.1


The event window



The OpenGL window graphically displays the results of the simulation as a colored grid. Each
color on the grid represents a different entity. White cells represent the loc
ation of ants, blue cells
represent the location of ant mounds, yellow cells represent locations of food, and red cells represent
the ants' pheromone trails. Empty cells are black. As a pheromone trail becomes more intense, it will be
drawn using a brighte
r shade of red. This provides a visual cue to the user as to which paths are
preferred by the ants at any given time. A screenshot of the OpenGL window is provided below in
figure 4.4.2.


Cox
10
?

F
igure 4.4.2


The OpenGL window


5. Conclusion



This project prov
ides a new approach to modern ant colony simulation by using MPI. By
running agent logic over multiple CPUs, it is possible to simulate millions of agents within a relatively
short time frame.


6. References



1. MPICH2 Homepage


Argonne National Laborato
ry



http://www
-
unix.mcs.anl.gov/mpi/mpich2/



2. PuTTY Homepage



http://www.chiark.greenend.org.uk/~sgtatham/putty



3. Xming Homepa
ge & Sourceforge download link



http://www.straightrunning.com/XmingNotes/



http://sourceforge.net/projects/xming



4. “Emergent Intelligence”
-

Danilo Benzatti
-

Artificial Intelligence Depot



http://ai
-
depot.com/CollectiveIntelligence/Ant.html



5. “Ant Colony Optimization”


Wikipedia
-

Wikimedia Foundation


November 9, 2006



http://en.wikipedia.org/wiki/Ant_colony_optimization



6. “Ant”


Wikipedia
-

Wikimedia Foundation


November 15, 2006



http://en.wikiped
ia.org/wiki/Ant

Cox
11
?



7. Python Programming Language Homepage


Python Software Foundation


2006



http://www.python.org



8. GNU Compiler Collection (GCC)


Free Software Foundation


November 19, 2006



http://gcc.gnu.org



9. Anjuta IDE Homepage


Naba Kumar


May 15, 2006



http://anjuta.sourceforge.net