fitness() function is
fitness.c. You are passed a pointer to
Individual structure (petrol.h) that has the
following fields:
int *chrom; int chromLen; double fitness;
The chrom field is the encoded individual of the
population of a length defined by chromLen.
Once the fitness function has been implemented both
petrol and petrolslave need to be remade.
In order to do this though, you need to make sure your shell
environment has both PVM_ROOT and PVM_ARCH
defined. Here is an example .cshrc fragment that shows
how to set them:
if ( -d ~/pvm3 ) then
setenv PVM_ROOT ~/pvm3
endif
set pvm = ( )
if ( $?PVM_ROOT ) then
if ( -x $PVM_ROOT/lib/pvmgetarch ) then
setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
set pvm = ( $PVM_ROOT/lib/$PVM_ARCH $PVM_ROOT/bin/$PVM_ARCH )
endif
endif
...
set path = ( ~/bin $pvm /bin /usr/bin /usr/local/bin /usr/X11R6/bin )
...
In order for this to work you need to create a pvm3
directory in your home directory with symbolic links from that
directory to the installed PVM location:
cd mkdir pvm3 cd pvm3 ln -s ~pvm/lib . ln -s ~pvm/include . ln -s ~pvm/man . mkdir bin
Another thing to add to your .cshrc could be the
following environment setting to allow you to read the PVM
man-pages:
setenv MANPATH /usr/man:/usr/local/man:/usr/X11R6/man:$PVM_ROOT/man
At this point you should test your .cshrc by restarting
your current shell and execute echo $PVM_ROOT $PVM_ARCH
$path.
Back in the petrol directory, you need to
do a make install. This will build all the objects for
petrol and petrolslave (all suffixed with
$PVM_ARCH.o), link, and install them into
~/pvm3/bin/$PVM_ARCH. For each architecture, you need to
build binaries on those machines (i.e., on the DEC stations, build
petrol, on the Linux boxes, build petrol, etc.).
Once all the binaries have been built, PVM needs to be started and the
host machines need to be added to the virtual machine. There are two
ways to add hosts. The first is to start PVM and enter the hosts by
using the add command:
% pvm
pvm> add dws007
1 successful
HOST DTID
dws007 80000
pvm> conf
2 hosts, 1 data format
HOST DTID ARCH SPEED
batman 40000 LINUX 1000
dws007 80000 PMAX 1000
pvm>
The other way is to create a file with each line containing a name of a host and start PVM with the name of the file as the command line argument.
Finally, execute petrol from your shell (not
in pvm). This will start a petrolslave on each
of the hosts in your virtual machine and start a run of how every many
generations specified.
IMPORTANT NOTE: If for some reason you stop petrol in the
middle of a run, you need to cleanup the petrolslave
processes by hand. To do this, in the pvm console, do a
ps -a and kill each of the
DTID numbers listed. Or, if you halt the
machine, it will kill them for you.
petrol [-b int] [-c float] [-g int] [-l int] [-m float]
[-n] [-o string] [-p int] [-s int] [-v]
-b PVM block size (default 10)
-c Probability of crossover (default 0.66)
-g Number of generations (default 500)
-l Chromosome length (default 100)
-m Probability of mutation (default 0.001)
-n Minimize (default FALSE)
-o Output to a file (default stdout)
-p Population size (default 100)
-s Random seed (default current time)
-v Print extra information (verbose)
petrol.hPopulation and Individual structures are
defined in this file, along with all the functions and their
parameters.
petrol.cmain() where
PopulationRun() is called.
population.cPopulation functions are here.
PopulationRun() is the main loop of petrol.
PopulationGeneration() is where the selection and
crossover takes place.
report.cReportInitial() is called before the first generation,
ReportGeneration() is called after every new generation,
and ReportDone() is called after all the generations have
been created. These three functions are called from
PopulationRun() in population.c.
petrolslave.c and pvmfitness.cPVMFitness() spawns off the petrolslave
processes, sends the Individual structures, and fills in
the resulting fitness values. All petrolslave does is
respond to work requests and runs fitness() on the remote
machines.
utils.h and utils.cpetrol.