Users Guide To The PGAPack Parallel Genetic Algorithm Library
Users Guide To The PGAPack Parallel Genetic Algorithm Library
net/publication/2813201
CITATIONS READS
193 200
1 author:
David Levine
University of Washington Seattle
70 PUBLICATIONS 3,257 CITATIONS
SEE PROFILE
All content following this page was uploaded by David Levine on 28 October 2015.
ANL{95/18
David Levine
Mathematics and Computer Science Division
1
Contents
0 Quick Start 1
I Getting Started 2
1 Introduction 3
2 Installation 4
2.1 Obtaining PGAPack : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4
2.2 Requirements : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4
2.3 Structure of the Distribution Directory : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4
2.4 Installation Instructions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 5
2.5 Installation Examples : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6
2.5.1 Sequential Installation : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6
2.5.2 Parallel Installation : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 6
2.6 Mailing Lists, Web Page, and Bug Reporting : : : : : : : : : : : : : : : : : : : : : : : : : : : 7
3 Examples 8
3.1 Maxbit Problem in C : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 8
3.2 Maxbit Problem in Fortran : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 8
3.3 Specifying Nondefault Values : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 10
3.4 Parallel I/O : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 10
3.5 Compiling, Linking, and Execution : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 12
II Users Guide 14
4 The Structure of PGAPack 15
4.1 Native Data Types : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 15
4.2 Context Variable : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 15
4.3 Levels of Usage Available : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 15
4.4 Function Call{Based Library : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16
4.5 Header File and Symbolic Constants : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16
4.6 Evaluation Function : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16
4.7 Parallelism : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 16
4.8 Implementation : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 17
5 Basic Usage 18
5.1 Required Functions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 18
5.2 Population Replacement : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 19
5.3 Stopping Criteria : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 21
5.4 Initialization : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 21
5.5 Selection: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 22
iii
5.6 Crossover : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 22
5.7 Mutation : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 22
5.8 Restart : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 23
5.9 String Evaluation and Fitness : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 23
5.10 Accessing Allele Values : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 24
5.10.1 Representing an Integer with a Binary String : : : : : : : : : : : : : : : : : : : : : : : 25
5.10.2 Representing a Real Value with a Binary String : : : : : : : : : : : : : : : : : : : : : : 25
5.10.3 Example : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 26
5.11 Report Options : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 27
5.12 Utility Functions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 27
5.12.1 Random Numbers : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 27
5.12.2 Print Functions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 27
5.12.3 Miscellaneous : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 27
5.13 Command-Line Arguments : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 28
6 Explicit Usage 29
6.1 Notation : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 29
6.2 Simple Sequential Example : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 29
6.3 Complex Example : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 30
6.4 Explicit PGAPack Functions : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 32
7 Custom Usage: Native Data Types 33
7.1 Basics : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 33
7.2 Example Problem: C : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 34
7.3 Example Problem: Fortran : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 34
8 Custom Usage: New Data Types 37
8.1 Basics : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 37
8.2 Example Problem : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 37
9 Hill-Climbing and Hybridization 44
10 Parallel Aspects 46
10.1 Basic Usage : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 46
10.2 Explicit Use : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 46
10.3 Example : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 47
10.4 Performance : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 47
11 Fortran Interface 49
12 Debugging Tools 51
III Appendixes 54
A Default Values 55
B Function Bindings 57
C Parallelism Background 64
D Machine Idiosyncrasies 68
E Common Problems 71
Bibliography 73
iv
Chapter 0
Quick Start
If you wish to get started by just typing a few lines and running an example, this section is for you. We assume
you have ftped the compressed tar le pgapack.tar.Z containing the distribution into /home/username. To
build a sequential version of PGAPack for a Sun SparcStation in /usr/local/pga and run a test example,
type
1. uncompress /home/username/pgapack.tar.Z
2. mkdir /usr/local/pga
3. cd /usr/local/pga
4. tar xvf /home/username/pgapack.tar
5. configure -arch sun4
6. make install
7. /usr/local/pga/examples/c/maxbit
To build an optimized (no built-in debugging capabilities), parallel version of PGAPack for an IBM SP
parallel computer, using an MPI implementation with include les in /usr/local/mpi/include and library
in /usr/local/mpi/lib, and run a test example using four processes, type
1. uncompress /home/username/pgapack.tar.Z
2. mkdir /usr/local/pga
3. cd /usr/local/pga
4. tar xvf /home/username/pgapack.tar
5. configure -arch rs6000 \
-mpiinc /usr/local/mpi/include -mpilib /usr/local/mpi/lib/libmpi.a
6. make install
7. mpirun -np 4 /usr/local/pga/examples/c/maxbit
Step 7, the execution step, is completely dependent on the MPI implementation. This example uses the
mpirun script that is distributed with the MPICH implementation 1]. Other MPI implementations may have
other ways to specify the number of processes to use.
More details on the installation process and various options are given in Chapter 2. Chapter 3 (example
problems) and Sections 5.1 (required functions) and 5.9 (string evaluation and tness) should be read next.
1
Part I
Getting Started
2
Chapter 1
Introduction
PGAPack is a parallel genetic algorithm library that is intended to provide most capabilities desired in a
genetic algorithm package, in an integrated, seamless, and portable manner. Key features of PGAPack are
as follows:
Ability to be called from Fortran or C.
Executable on uniprocessors, multiprocessors, multicomputers, and workstation networks.
Binary-, integer-, real-, and character-valued native data types.
Object-oriented data structure neutral design.
Parameterized population replacement.
Multiple choices for selection, crossover, and mutation operators.
Easy integration of hill-climbing heuristics.
Easy-to-use interface for novice and application users.
Multiple levels of access for expert users.
Full extensibility to support custom operators and new data types.
Extensive debugging facilities.
Large set of example problems.
3
Chapter 2
Installation
2.1 Obtaining PGAPack
The complete distribution of PGAPack is available by anonymous ftp from ftp.mcs.anl.gov in the le
pub/pgapack/pgapack.tar.Z. The distribution contains all source code, installation instructions, this users
guide, and a collection of examples in C and Fortran. The current release of PGAPack is 1.0. You can check
which version of PGAPack you have by running any C language PGAPack program with the command-line
option -pgaversion.
2.2 Requirements
To compile PGAPack, you must have an ANSI C compiler that includes a full implementation of the Standard
C library and related header les. If you wish only to build a sequential version of PGAPack this is all that
is required.
To build a parallel version, you must have an implementation of the Message Passing Interface (MPI)
5, 6] for the parallel computer or workstation network you are running on. If you do not have a native
version of MPI for your computer, several machine-independent implementations are available. Most of the
testing and development of PGAPack was done by using the MPICH implementation of MPI which is freely
available 1].
If -mpiinc and -mpilib are specied, a parallel version of PGAPack will be built. If these ags are
not specied, a sequential version of PGAPack will be built.
7. Execute the makele (make install).
8. Add PGAPack's man pages to your man page path. (setenv MANPATH "$MANPATH"":/home/pgapack/man")
9. Execute a test problem
5
/usr/local/pga/examples/c/maxbit in C
/usr/local/pga/examples/fortran/maxbit in Fortran.
If a parallel version of PGAPack was used, the actual commands to execute a parallel program in Step
9 will depend on the particular MPI implementation and parallel computer used. See Appendix D for some
examples.
6. make install
7. mpirun -np 4 /usr/local/pga/examples/c/maxbit
Step 7, the execution step, is completely dependent on the MPI implementation. This example uses the
mpirun script that is distributed with the MPICH implementation 1]. Other MPI implementations may have
other ways to specify the number of processes to use.
6
2.6 Mailing Lists, Web Page, and Bug Reporting
To join the PGAPack mailing list to receive announcements of new versions, enhancements, and bug xes,
send electronic mail to [email protected]. Bug reports should be sent to [email protected].
The World Wide Web page for PGAPack is http://www.mcs.anl.gov/pgapack.html and contains up-to-
date news and a list of bug reports.
When reporting a bug, please include as much information and documentation as possible. Helpful
information would include PGAPack version number (-pgaversion), MPI implementation and version used,
conguration options, type of computer system, problem description, and error message output. It is helpful
if you put a PGAPrintContextVariable call before and after the PGASetUp call. Additionally, if possible,
build a debug version of PGAPack and send \high-level" output from running your program with the trace
facility enabled (Chapter 12).
7
Chapter 3
Examples
This chapter presents some simple PGAPack programs. The problem chosen is the Maxbit problem. The
objective is to maximize the number of 1-bits in a string.
Section 3.1 presents a simple PGAPack program in C whose structure is sucient to solve many prob-
lems. Section 3.2 presents this same program in Fortran. Section 3.3 shows how to change default values
in PGAPack. Section 3.4 contains an example that shows how keyboard input may be read in an MPI
environment. Finally, Section 3.5 shows how to compile, link, and execute a PGAPack program. These and
other examples may be found in the ./examples/c and ./examples/fortran directories.
8
#include "pgapack.h"
double evaluate (PGAContext *ctx, int p, int pop)
stringlen = PGAGetStringLength(ctx)
nbits = 0
for (i=0 i<stringlen i++)
if (PGAGetBinaryAllele(ctx, p, pop, i))
nbits++
return((double) nbits)
}
9
#include "pgapack.h"
double evaluate (PGAContext *ctx, int p, int pop)
10
#include "pgapack.h"
double evaluate (PGAContext *ctx, int p, int pop)
MPI_Init(&argc, &argv)
MPI_Comm_rank(MPI_COMM_WORLD, &myid)
if (myid == 0) { /* Process 0 has a dialog */
printf("String length? ") /* with the user and */
scanf("%d", &len) /* broadcasts the user's */
printf("Max iterations? ") /* parameters to all */
scanf("%d", &maxiter) /* other processes */
}
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD)
MPI_Bcast(&maxiter, 1, MPI_INT, 0, MPI_COMM_WORLD)
MPI_Finalize()
return(0)
}
11
include 'pgapackf.h'
include 'mpif.h'
call MPI_Init(ierror)
call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierror)
c Process 0 has a dialog with the user and broadcasts the user's
c parameters to all other processes
if (myid .eq. 0) then
print *, 'String length?'
read *, len
print *, 'Max iterations?'
read *, maxiter
endif
call MPI_Bcast(len, 1, MPI_INT, 0, MPI_COMM_WORLD, ierror)
call MPI_Bcast(maxiter, 1, MPI_INT, 0, MPI_COMM_WORLD, ierror)
call MPI_Finalize(ierror)
stop
end
MPI Bcast will result in every process in communicator comm receiving a copy of the contents of *buf/buffer.
The other parameters are the number of items (count), the datatype (datatype), which may be one of
MPI DOUBLE, MPI INT, MPI CHAR, MPI UNSIGNED, or MPI LONG the rank of the process with the original copy
(root) the MPI communicator (comm) and, for Fortran, a variable to handle an error return code (ierror).
12
built, the MPI implementation used and the machine you are running on. If a sequential version of PGAPack
was built (i.e., one where the user did not supply a version of MPI), the executable maxbit can be executed
on a uniprocessor Unix system by typing maxbit. If the MPICH implementation of MPI was used, it may be
executed (using four processes) by mpirun maxbit -np 4. Appendix D contains some examples.
13
Part II
Users Guide
14
Chapter 4
The Structure of PGAPack
This chapter provides a general overview of the structure of PGAPack.
15
hill-climbing heuristic. At the third level, the user can customize the genetic algorithm by supplying his or
her own function(s) to provide a particular operator(s) while still using one of the native data types. Finally,
the user can dene his or her own datatype, write the data-structure-specic low-level GA functions for
the datatype (i.e., crossover, mutation, etc.), and have the data-structure-specic functions executed by the
high-level data-structure-neutral PGAPack functions.
The data-structure-specic functions deal directly with native data types. In general, the user never
calls these functions directly.
System calls in PGAPack provide miscellaneous functionality, including debugging, random number
generation, output control, and error reporting.
4.7 Parallelism
PGAPack can be run on both sequential computers (uniprocessors) and parallel computers (multiprocessors,
multicomputers, and workstation networks). The parallel programming model used is message passing, in
particular the single program, single data (SPMD) model. PGAPack version 1.0 supports sequential and
parallel implementations of the global population model (see Chapter 10).
16
4.8 Implementation
PGAPack is written in ANSI C. A set of interface functions allows most user-level PGAPack functions
to be called from Fortran. All message-passing calls follow the Message Passing Interface (MPI) standard
5, 6]. Nonoperative versions of the basic MPI functions used in the examples are supplied if the user
does not provide an MPI implementation for their machine. These routines simply return and provide no
parallel functionality. Their purpose is to allow the PGAPack library to be built in the absence of an MPI
implementation.
Most low-level internal functions in PGAPack are data-structure specic and use addresses and/or osets
of the population data structures. The user-level routines, however, provide the abstractions of data-structure
neutrality and an integer indexing scheme for access to population data structures.
17
Chapter 5
Basic Usage
As the examples in Chapter 3 show, a PGAPack program can be written with just four function calls and
a string evaluation function. This basic usage is discussed further in Section 5.1. Sections 5.3{5.12 explain
options available in PGAPack. Section 5.13 discusses PGAPack command line arguments.
PGACreate allocates space for the context variable, ctx (Section 4.2), and returns its address. argc and
argv are the standard list of arguments to a C program. datatype must be one of PGA DATATYPE BINARY,
,
PGA DATATYPE INTEGER PGA DATATYPE REAL , or PGA DATATYPE CHARACTER to specify strings consisting of
binary-valued, integer-valued, real-valued, or character-valued strings, respectively. len is the length of the
string (i.e., the number of genes). maxormin must be PGA MAXIMIZE or PGA MINIMIZE to indicate whether
the user's problem is maximization or minimization, respectively.
In Fortran the call to PGACreate is
integer ctx
ctx = PGACreate (datatype, len, maxormin)
where datatype, len, and maxormin are the same as for C programs. After the PGACreate call, the user
may optionally set nondefault values. These are then followed by a call to PGASetUp to initialize to default
values all options, parameters, and operators not explicitly specied by the user. For example,
ctx = PGACreate(&argc, argv, datatype, len, maxormin)
PGASetPopSize (ctx, 500)
PGASetFitnessType (ctx, PGA_FITNESS_RANKING)
PGASetCrossoverType (ctx, PGA_CROSSOVER_UNIFORM)
PGASetUniformCrossoverProb (ctx, 0.6)
PGASetUp (ctx)
will change the default values for the population size, the mapping of the user's evaluation to a tness
value, and the crossover type. All PGASet calls should be made after PGACreate has been called, but before
PGASetUp has been called all such calls are optional. Note also that all PGAPack functions other than
PGACreate take the context variable as their rst argument.
The PGARun function executes the genetic algorithm. Its second argument is the name of a user-supplied
evaluation function that returns a double (double precision in Fortran) value that is the user's evaluation
of an individual string. In C the prototype for this function looks like
18
double evaluate (PGAContext *ctx, int p, int pop)
and in Fortran
double precision function evaluate (ctx, p, pop)
integer ctx, p, pop
The user must write the evaluation function, and it must have the calling sequence shown above and discussed
further in Section 5.9. After PGARun terminates, PGADestroy is called to release all memory allocated by
PGAPack. 1
Except for writing an evaluation function (Section 5.9) the information contained in rest of this chapter
is optional|defaults will be set for all other GA parameters. We do note, however, that the defaults used
are the result of informal testing and results reported in the GA literature. They are by no means optimal,
and additional experimentation with other values may well yield better performance on any given problem.
specify that each generation a new population is created consisting of ten strings created via recombi-
nation, and the 190 most t strings from the old population. The 190 strings can also be selected ran-
domly, with or without replacement, by setting the second argument of PGASetPopReplacementType to
PGA POPREPL RANDOM REP or PGA POPREPL RANDOM NOREP, respectively.
By default, the number of new strings created each generation is 10 percent of the population size (an
SSGA population replacement strategy). A GRGA can be implemented by setting PGASetNumReplaceValue
to the population size (the default population size is 100). Setting PGASetNumReplaceValue to one less than
the population size will result in an elitist GRGA, where the most t string is always copied to the new
population (since PGA POPREPL BEST is the default population replacement strategy).
Traditionally, strings created through recombination rst undergo crossover and then mutation. Some
practitioners 3] have argued that these two operators should be separate. By default, PGAPack applies muta-
tion only to strings that did not undergo crossover. This is equivalent to setting PGASetMutationOrCrossoverFlag
(ctx,PGA TRUE). To have strings undergo both crossover and mutation, on should use PGASetMutationAndCrossoverFlag
(ctx,PGA TRUE).
By default, PGAPack allows duplicate strings in the population. Some practitioners advocate not allowing
duplicate strings in the population in order to maintain diversity. The function call PGASetNoDuplicatesFlag
(ctx,PGA TRUE) will not allow duplicate strings in the population: It repeatedly applies the mutation oper-
ator (with an increasing mutation rate) to a duplicate string until it no longer matches any string in the new
population. If the mutation rate exceeds 1.0, however, the duplicate string will be allowed in the population,
and a warning message will be issued.
Figure 5.1 shows the generic population replacement scheme in PGAPack. Both populations and + 1
k k
are of xed size (the value returned by PGAGetPopSize). First, PGAGetPopSize - PGAGetNumReplaceValue
strings are copied over directly from generation . The way the strings are chosen, the most t, or randomly
k
with or without replacement, depends on the value set by PGASetPopReplacementType. The remaining
PGAGetNumReplaceValue strings are created by crossover and mutation.
1 PGADestroy will also call MPI finalize, if MPI was started by PGACreate.
19
PGAGetPopSize() -
PGAGetNumReplaceValue()
PGAGetPopSize()
PGAGetNumReplaceValue()
k k+1
temp
Figure 5.1: Population Replacement
20
5.3 Stopping Criteria
PGAPack terminates when at least one of the stopping rule(s) specied has been met. The three stopping
rules are (1) iteration limit exceeded, (2) population too similar, and (3) no change in the best solution found
in a given number of iterations. The default is to stop when the iteration limit (by default, 1000 iterations)
is reached.
The choice of stopping rule is set by PGASetStoppingRuleType. For example, PGASetStoppingRuleType
(ctx,PGA STOP MAXITER) is the default. Other choices are PGA STOP TOOSIMILAR and PGA STOP NOCHANGE
for population too similar and no change in the best solution found, respectively. PGASetStoppingRuleType
may be called more than once. The dierent stopping rules specied are ored together.
If PGA STOP MAXITER is one of the stopping rules, PGASetMaxGAIterValue(ctx,500) will change the max-
imumiteration limitto 500. If PGA STOP NOCHANGE is one of the stopping rules, PGASetMaxNoChangeValue(ctx,50)
will change from 100 (the default) to 50 the maximum number of iterations in which no change in the
best evaluation is allowed before the GA stops. If PGA STOP TOOSIMILAR is one of the stopping rules,
PGASetMaxSimilarityValue(ctx,99) will change from 95 to 99 the percentage of the population allowed
to have the same evaluation function value before the GA stops.
5.4 Initialization
Strings are either initialized randomly (the default), or set to zero. The choice is specied by setting
the second argument of PGASetRandomInitFlag to either PGA TRUE or PGA FALSE, respectively. Random
initialization depends on the datatype.
If binary-valued strings are used, each gene is set to 1 or 0 with an equal probability. To set the probability
of randomly setting a bit to 1 to 0.3, use PGASetBinaryInitProb(ctx,0.3).
For integer-valued strings, the default is to set the strings to a permutation on a range of integers. The
default range is 0 ; 1], where is the string length. PGASetIntegerInitPermute(ctx, 500, 599) will
L L
set the permutation range to 500 599]. The length of the range must be the same as the string length.
Alternatively, PGASetIntegerInitRange will set each gene to a random value selected uniformly from a
specied range. For example, the code
stringlen = PGAGetStringLength(ctx)
for(i=0i<stringleni++) {
lowi] = 0
highi] = i
}
PGASetIntegerInitRange(ctx, low, high)
will select a value for gene i uniformly randomly from the interval 0,i].
If real-valued strings are used, the alleles are set to a value selected uniformly randomly from a specied
interval. The interval may be specied with either the PGASetRealInitRange or PGASetRealInitPercent
functions. For example, the code
stringlen = PGAGetStringLength(ctx)
for(i=0i<stringleni++) {
lowi] = -10.0
highi] = (double) i
}
PGASetRealInitRange(ctx, low, high)
will select a value for allele i uniformly randomly from the interval ;10 0 i]. This is the default strategy
:
PGASetRealInitPercent species the interval with a median value and percent oset. For example,
stringlen = PGAGetStringLength(ctx)
for(i=1i<=stringleni++) {
mediani] = (double) i
21
percenti] = .5
}
PGASetRealInitPercent(ctx, median, percent)
will select a value for allele i uniformly randomly from the increasing intervals 21 23 ]. Note that if the
i i
If character-valued strings are used, PGASetCharacterInitType(ctx,PGA CINIT UPPER) will set the al-
lele values to uppercase alphabetic characters chosen uniformly randomly. Other options are PGA CINIT LOWER
for lower case letters only (the default) and PGA CINIT MIXED for mixed case letters, respectively.
5.5 Selection
The selection phase allocates reproductive trials to strings on the basis of their tness. PGAPack supports
four selection schemes: proportional selection, stochastic universal selection, binary tournament selection,
and probabilistic binary tournament selection. The choice may be specied by setting the second argument
of PGASetSelectType to one of PGA SELECT PROPORTIONAL, PGA SELECT SUS, PGA SELECT TOURNAMENT, and
PGA SELECT PTOURNAMENT for proportional, stochastic universal, tournament, and probabilistic tournament
selection, respectively. The default is tournament selection. For probabilistic tournament selection, the
default probability that the string that wins the tournament is selected is 0.6. It may be set to 0.8, for
example, with PGASetPTournamentProb(ctx, 0.8).
5.6 Crossover
The crossover operator takes bits from each parent string and combines them to create child strings. The type
of crossover may be specied by setting PGASetCrossoverType to PGA CROSSOVER ONEPT, PGA CROSSOVER TWOPT,
or PGA CROSSOVER UNIFORM for one-point, two-point, or uniform crossover, respectively. The default is two-
point crossover. By default the crossover rate is 0.85. It may be set to 0.6 by PGASetCrossoverProb(ctx,
0.6), for example.
Uniform crossover is parameterized by u , the probability of swapping two parent bit values 8]. By
p
5.7 Mutation
The mutation rate is the probability that a gene will undergo mutation. The mutation rate is independent
of the datatype used. The default mutation rate is the reciprocal of the string length. The function call
PGASetMutationProb(ctx,.001) will set the mutation rate to .001.
The type of mutation depends on the data type. For binary-valued strings, mutation is a bit complement
operation For character-valued strings, mutation replaces one alphabetic character with another chosen
uniformly randomly. The alphabetic characters will be lower, upper, or mixed case depending on how the
strings were initialized.
For integer-valued strings, if the strings were initialized to a permutation and gene is to be mutated,
i
the default mutation operator swaps gene with a randomly selected gene. If the strings were initialized to
i
a random value from a specied range and gene is to be mutated, by default gene will be replaced by a
i i
lected uniformly randomly from the initialization range. If the strings were initialized to a permutation,
the minimum and maximum values of the permutation dene the range. If PGASetMutationType is set to
PGA MUTATION PERMUTE, gene will be swapped with a randomly selected gene. If PGASetMutationType is set
i
to PGA MUTATION CONSTANT, a constant integer value (by default one) will be added (subtracted) to (from) the
existing allele value. The constant value may be set to 34, for example, with PGASetMutationIntegerValue(ctx,34).
Three of the four real-valued mutation operators are of the form , where is the existing
v v p v v
allele value. They vary by how is selected. First, if PGASetMutationType is set to PGA MUTATION CONSTANT,
p
22
p is the constant value 0.01. It may be set to .02, for example, with PGASetMutationRealValue(ctx,.02).
Second, if PGASetMutationType is set to PGA MUTATION UNIFORM, is selected uniformly from the interval
p
PGASetMutationType is set to PGA MUTATION GAUSSIAN, p is selected from a Gaussian distribution (this
is the default real-valued mutation operator) with mean 0 and standard deviation 0.1. To select from p
a Gaussian distribution with mean 0 and standard deviation 0.5 set PGASetMutationRealValue(ctx,.5).
Finally, if PGASetMutationType is set to PGA MUTATION RANGE, gene will be replaced with a value selected
i
5.8 Restart
The restart operator reseeds a population from the best string. It does so by seeding the new population
with the best string and generating the remainder of the population as mutated variants of the best string.
By default the restart operator is not invoked. Setting PGASetRestartFlag(ctx,PGA TRUE) will cause the
restart operator to be invoked. By default PGAPack will restart every 50 iterations. PGASetRestartFrequencyValue
(ctx,100) will restart every 100 iterations instead. When creating the new strings from the best string an
individual allele undergoes mutation with probability 0.5. This can be changed to 0.9 with the function call
PGASetRestartAlleleChangeProb(ctx,0.9).
For binary-valued strings the bits are complemented. For integer- and real-valued strings the amount to
change is set with PGASetMutationIntegerValue and PGASetMutationRealValue, respectively. Character-
valued strings are changed according to the rules in Section 5.7 for mutating character strings.
and in Fortran
double precision function evaluate (ctx, p, pop)
integer ctx, p, pop
The function evaluate will be called by PGARun whenever a string evaluation is required. p is the index
of the string in population pop that will be evaluated. The correct values of p and pop will be passed to the
evaluation function by PGARun. (If PGARun is not used, PGAEvaluate must be. See Chapter 6.) As shown
below, p and pop are used for reading (and sometimes writing) allele values Sample evaluation functions are
shown in Figures 3.1 and 3.2, and online in the ./examples directory.
Traditionally, genetic algorithms assume tness values are nonnegative and monotonically increasing the
more t a string is. The user's evaluation of a string, however, may reect a minimization problem and/or
be negative. Therefore, the user's evaluation value is mapped to a nonnegative and monotonically increasing
tness value. First, all evaluations are mapped to positive values (if any were negative). Next, these values
are translated to a maximization problem (if the direction of optimization specied was minimization).
23
Finally, these values are mapped to a tness value by using the identity (the default), linear ranking, or
linear normalization, The choice of tness mapping may be set with the function PGASetFitnessType. The
second argument must be one of PGA FITNESS RAW, PGA FITNESS RANKING, or PGA FITNESS NORMAL, for the
identity, linear ranking, or linear normalization, respectively.
A linear rank tness function 2, 10] is given by
M in +( M ax ;M in ) rank(;p)1; 1
N
(5 1)
:
where rank(p) is the index of string p in a list sorted in order of decreasing evaluation function value, and
N is the population size. Ranking requires that 1 M ax 2, andM in + M ax = 2. The default value for
M ax is 1.2. It may be set to 1.1 with PGASetMaxFitnessRank(ctx,1.1).
In linear normalization the tness function is given by
K ; (rank(p) C ) (5 2)
:
where and are the constants and , where is the standard deviation of the user's evaluation
K C N
function values after they have been transformed to positive values for a maximization problem.
If the direction of optimization is minimization, the values are remapped for maximization. The function
call PGASetFitnessMinType(ctx,PGA FITNESSMIN CMAX) will remap by subtracting the worst evaluation
value from each evaluation value (this is the default). The worst evaluation value is multiplied by 1.01 before
the subtraction so that the worst string has a nonzero tness. The function call PGASetFitnessCmaxValue(ctx,
1.2) will change the multiplier to 1.2 Alternatively, if PGA FITNESSMIN RECIPROCAL is specied the remap-
ping is done by using the reciprocal of the evaluation function.
will assign to bit the binary value of the ith gene in string p in population pop. To set the ith gene in
string p in population pop to 1, use
PGASetBinaryAllele(ctx, p, pop, i, 1)
will assign to k the integer value of the ith gene in string p in population pop. To set the ith gene in string
p in population pop to 34, use
will assign to x the real value of the ith gene in string p in population pop. To set the ith gene in string p
in population pop to 123.456, use
PGASetRealAllele(ctx, p, pop, i, 1, 123.456)
24
char c
c = PGAGetCharacterAllele (ctx, p, pop, i)
will assign to c the character value of the ith gene in string p in population pop. To set the ith gene in
string p in population pop to \Z", use
PGASetCharacterAllele(ctx, p, pop, i, 1, 'Z')
=
X
N
i;1
k bi2 (5 3)
:
i=1
where is the string length, and i the value of the th bit. For example, to decode the integer k from the
N b i
The function PGAEncodeIntegerAsBinary will encode an integer as a binary string. For example, to encode
the integer 564 as a 12-bit binary string2 in the substring dened by bits 12{23, use
PGAEncodeIntegerAsBinary(ctx,p,pop, 12, 23, 564)
In a BCD representation, two numbers that are contiguous in their decimal representations may be far
from each other in their binary representations. For example, 7 and 8 are consecutive integers, yet their 4-bit
binary representations, 0111 and 1000, dier in the maximum number of bit positions.3 Gray codes dene a
dierent mapping of binary strings to integer values from that given by Eq. (5.3) and may alternatively be
used for representing integer (or real, see below) values in a binary string. The second and third columns in
Table 5.1 show how the integers 0{7 are mapped to Eq. (5.3) and to the binary reected Gray code (the most
commonly used Gray code sequence), respectively. In the binary reected Gray code sequence, the binary
representations of consecutive integers dier by only one bit (a Hamming distance of one).
To decode the integer k from a binary reected Gray code interpretation of the binary string, use
k = PGAGetIntegerFromGrayCode(ctx,p,pop,20,29)
To encode 564 as a 12-bit binary string in the substring dened by bits 12{23 using a Gray code, use
PGAEncodeIntegerAsGaryCode(ctx,p,pop, 12, 23, 564)
= ( ; )( ; ) ( ; )+
x k a U L = b a L
(and generalizing 0 2N ; 1] to ]). For example, to decode the double x from the 20 bits given by the
a b
binary string stored in bit positions 10{29 onto the interval ;10 0 20 0], use : :
x = PGAGetRealFromBinary(ctx,p,pop,10,29,-10.0,20.0)
2 Even though only ten bits are necessary to encode 564, the user may want to allow the GA any value between 0 4095],
hence the twelve bits.
3 Technically, this is known as a Hamming cli
.
25
Table 5.1: Binary and Gray Codes
k Eq. (5.3) Gray code
0 000 000
1 001 001
2 010 011
3 011 010
4 100 110
5 101 111
6 110 101
7 111 100
To encode -18.3 on the interval ;50 0 50 0] using a 20-bit BCD binary string, use
: :
PGAEncodeRealAsBinary(ctx,p,pop,0,19,-50.0,50.0,-18.3)
0 2 10
x
;10 3 10
x
The user wishes to use 10 bits for the binary representation of 1 and 2 , and 20 bits for the binary
x x
representation of 3 (perhaps for higher accuracy), and a Gray code encoding. This may be done as follows.
x
#include "pgapack.h"
double grayfunc (PGAContext *ctx, int p, int pop)
double f (double x1, double x2, double x3)
int main(int argc, char **argv)
{
PGAContext *ctx
ctx = PGACreate (&argc, argv, PGA_DATATYPE_BINARY, 40, PGA_MINIMIZE)
PGASetUp (ctx )
PGARun (ctx, grayfunc )
PGADestroy (ctx )
return
}
In Fortran, the bit indices would be 1{10, 11{20, and 21{40, respectively. The number of bits allocated for
the binary representation determines the accuracy with which the real value can be calculated. Note in this
26
example the function f need not be modied the function grayfunc is used as a \wrapper" to get variable
values out of the GA and return the value calculated by f.
gument is not 0, it will be used to reseed the random number sequence. PGARandomFlip ips a bi-
ased coin. For example, PGARandomFlip(ctx,.7) will return PGA TRUE approximately 70% of the time.
PGARandomInterval(-10,30) will return an integer value generated uniformly on ;10 30]. PGARandomUniform
(ctx,-50.,50.) will return a real value generated uniformlyrandomly on the interval -50,50]. PGARandomGaussian
(ctx,0.,1.) will return a real value generated from a Gaussian distribution with mean zero and standard
deviation one.
5.12.2 Print Functions
PGAPrintPopulation(ctx,stdout,pop) will print the evaluation function value, tness value, and string
for each member of population to
pop stdout . This function may not be called until
after PGASetUp has been
called.
PGAPrintContextVariable(ctx,stdout) will print the value of all elds in the context variable to
.
stdout PGAPrintIndividual(ctx,stdout,p,pop) will print the evaluation function value, tness value,
and string of individual in population to
p pop .
stdout PGAPrintString(ctx,stdout,p,pop) will print the
string of individual in population
p pop to .
stdout PGAPrintVersionNumber(ctx) will print the PGAPack
version number.
5.12.3 Miscellaneous
PGAGetGAIterValue(ctx) will return the current iteration of the GA. PGAGetBestIndex(ctx,pop) (PGAGetWorstIndex)
will return the index of the most (least) t member of population pop.
PGAUpdateOffline(ctx,pop) (PGAUpdateOnline) will update the o!ine (online) analysis based on the
new generation's results. PGAHammingDistance(ctx,pop) returns a double, which is the average Hamming
distance between the binary strings in population pop. The function call
PGAError(ctx, "popindex=", PGA_FATAL, PGA_INT, (void *)&popindex)
will print the message \popindex=-1" (assuming the value of popindex is -1) and then exit PGAPack. If
the third argument had been PGA WARNING instead, execution would have continued. In addition to PGA INT,
valid data types are PGA DOUBLE, PGA CHAR, and PGA VOID.
27
5.13 Command-Line Arguments
PGAPack provides several command-line arguments. These are only available to C programs, although
in some cases both C and Fortran programs can achieve the equivalent functionality with function calls.
For example, PGAUsage(ctx) provides the same functionality as the -pgahelp command line option. See
Chapter 12 for the function call equivalents.
-pgahelp get this message
-pgahelp debug list of debug options
-pgadbg <level> set debug option
-pgadebug <level> set debug option
-pgaversion Print current PGAPack version number, parallel or
sequential, and debug or optimized
28
Chapter 6
Explicit Usage
This chapter discusses how the user may obtain greater control over the steps of the GA by not using the
PGARun command, but instead calling the data-structure-neutral functions directly. One ramication of
this is that the PGARun interface no longer masks some of the dierences between parallel and sequential
execution. The examples in this chapter are written for sequential execution only. Chapter 10 shows how
they may be executed in parallel.
6.1 Notation
To understand the calling sequences of the functions discussed in this chapter, one must know of the existence
of certain data structures and the user interface for accessing them. It is not necessary to know how these
data structures are implemented, since that is hidden by the user interface to PGAPack.
PGAPack maintains two populations: an old one and a new one. The size of each population is the value
returned by PGAGetPopSize. In addition, each population contains two temporary working locations. The
string length is the value specied to PGACreate and returned by PGAGetStringLength.
Formally, string in population is referred to by the 2-tuple (p,pop) and the value of gene in that
p pop i
string by the 3-tuple (i,p,pop). In PGAPack, pop must be one of the two symbolic constants PGA OLDPOP or
PGA NEWPOP to refer to the old or new population, respectively. At the end of each GA iteration, the function
PGAUpdateGeneration makes sure these symbolic constants are remapped to the correct population. The
string index p must be either an integer between 0 and ; 1 (or 1 and in Fortran) or one of the symbolic
P P
constants PGA TEMP1 or PGA TEMP2, to reference one of the two temporary locations, respectively.
29
#include "pgapack.h"
double evaluate (PGAContext *ctx, int p, int pop)
while(!PGADone(ctx, NULL)) {
PGASelect (ctx, PGA_OLDPOP)
PGARunMutationAndCrossover(ctx, PGA_OLDPOP, PGA_NEWPOP)
PGAEvaluate (ctx, PGA_NEWPOP, evaluate, NULL)
PGAFitness (ctx, PGA_NEWPOP)
PGAUpdateGeneration (ctx, NULL)
PGAPrintReport (ctx, stdout, PGA_OLDPOP)
}
PGADestroy(ctx)
return(0)
}
according to the report options specied. Note that the argument to PGAPrintReport is the old popula-
tion, since after PGAUpdateGeneration is called, the newly created population is in PGA OLDPOP. Finally,
PGADestroy releases any memory allocated by PGAPack when execution is complete.
The functions PGADone, PGAUpdateGeneration, and PGAEvaluate take an MPI communicator (see Ap-
pendix C and Chapter 10) as an argument. For sequential execution the value NULL should be specied for
this argument. A parallel, or sequential and parallel, version of this example is given in Section 10.2.
30
#include "pgapack.h"
double evaluate(PGAContext *ctx, int p, int pop)
while(!PGADone(ctx, NULL)) {
PGASelect (ctx, PGA_OLDPOP)
PGASortPop(ctx, PGA_OLDPOP)
n = popsize - numreplace
for ( i=0 i < n i++ ) {
j = PGAGetSortedPopIndex(ctx, i)
PGACopyIndividual(ctx, j, PGA_OLDPOP, i, PGA_NEWPOP)
}
while (n < popsize) {
m1 = PGASelectNextIndex(ctx)
m2 = PGASelectNextIndex(ctx)
if(PGARandomFlip(ctx, probcross)) {
PGACrossover(ctx, m1, m2, PGA_OLDPOP, PGA_TEMP1, PGA_TEMP2, PGA_NEWPOP)
PGAMutate (ctx,PGA_TEMP1,PGA_NEWPOP)
PGAMutate (ctx,PGA_TEMP2,PGA_NEWPOP)
PGACopyIndividual (ctx,PGA_TEMP1,PGA_NEWPOP,n, PGA_NEWPOP)
PGACopyIndividual (ctx,PGA_TEMP2,PGA_NEWPOP,n+1,PGA_NEWPOP)
n += 2
}
else {
PGACopyIndividual (ctx, m1, PGA_OLDPOP, n, PGA_NEWPOP)
PGACopyIndividual (ctx, m2, PGA_OLDPOP, n+1, PGA_NEWPOP)
n += 2
}
}
PGAEvaluate(ctx, PGA_NEWPOP, evaluate, NULL)
PGAFitness (ctx, PGA_NEWPOP)
PGAPrintReport(ctx, stdout, PGA_NEWPOP)
PGAUpdateGeneration(ctx, NULL)
}
PGADestroy(ctx)
return 0
}
31
6.4 Explicit PGAPack Functions
This section briey discusses other functions not shown in the previous examples or discussed in Chapter 5.
Additional information about these and other PGAPack functions is contained in Appendix B (function
bindings) and the ./examples directory.
PGARunMutationAndCrossover and PGARunMutationOrCrossover perform the recombination step. The
former applies mutation to strings that undergo crossover. The latter applies only mutation to strings that
did not undergo crossover.
The restart operator described earlier in Section 5.8 can be invoked explicitly with PGARestart(ctx,
oldpop, newpop), where the best string from population oldpop is used to initialize population newpop.
PGADuplicate(ctx,p,PGA OLDPOP,PGA NEWPOP,20) returns PGA TRUE if string p in population PGA OLDPOP
is a duplicate of any of the rst 20 strings in population PGA NEWPOP. PGAChange(ctx, p, PGA OLDPOP) re-
peatedly applies the mutation operator to string p in population PGA OLDPOP until at least one mutation has
occurred.
In PGAPack three values are associated with each string: (1) the user's evaluation function value, (2)
a Boolean ag to indicate whether the evaluation function value is up to date with respect to the actual
string, and (3) the tness value. If PGARun is not used, the user must manage these values explicitly.
PGAEvaluate(ctx, PGA NEWPOP, evaluate, comm) will execute the user's evaluation function, evaluate,
on each string in population PGA NEWPOP that has changed (for example, from crossover) since its last eval-
uation. PGAEvaluate will set both the evaluation function value and associated Boolean ag automatically.
The argument comm is an MPI communicator. Valid values are NULL for an explicitly sequential example,
or any valid MPI communicator. Depending on the number of processes specied when the program was
invoked, and the value of the comm argument, PGAEvaluate may be run with one or more processes. See
Chapter 10 for further discussion.
PGAFitness will calculate the population tness values from the evaluation function values. It is an error
to call PGAFitness if all the evaluation function values are not up to date.
These same three values may be read also. PGAGetEvaluation(ctx, p, PGA OLDPOP) returns the
evaluation function value. PGAGetEvaluationUpToDateFlag(ctx, p, PGA OLDPOP) returns PGA TRUE or
PGA FALSE to indicate whether the evaluation is up to date with the actual string or not, respectively. If
PGAPack was compiled for debugging,PGAGetEvaluation will print a warning message if the evaluation is
not up to date. PGAGetFitness(ctx, p, PGA OLDPOP) returns the tness value.
At times, (e.g., applying a hill-climbing function) the user may need to explicitly set the evaluation
function value and associated Boolean ag (tness values can be calculated only by calling PGAFitness).
PGASetEvaluation(ctx, p, PGA OLDPOP, 123.4) will set the evaluation function value to 123.4 and the as-
sociated Boolean ag to PGA TRUE. The Boolean ag may be set independently with PGASetEvaluationUpToDateFlag.
For example, PGASetEvaluationUpToDateFlag (ctx, p, PGA OLDPOP, PGA FALSE) sets the status of the
Boolean ag of string p in population PGA OLDPOP to out of date.
PGAMean(ctx, a, n) returns the mean of the n values in array a. PGAStddev(ctx, a, n, mean) returns
the standard deviation of the n values in array a whose mean is mean. PGARank(ctx, p, order, n) returns
an index that is the rank of string p as given by the sorted array order of length n.
PGAGetPrintFrequency(ctx) returns the frequency with which GA statistics are reported. PGAGetWorstIndex
(ctx, PGA OLDPOP) returns the index of the string in population PGA OLDPOP with the worst evaluation func-
tion value. PGAGetBestIndex(ctx, PGA OLDPOP) returns the index of the string in population PGA OLDPOP
with the best evaluation function value.
32
Chapter 7
Custom Usage: Native Data Types
This chapter discusses how PGAPack may be extended by replacing some of the standard PGAPack functions
with user-dened functions for use with one of PGAPack's four native data types. This can be done from
both C and Fortran.
7.1 Basics
In PGAPack, high-level (data-structure-neutral) functions call data-structure-specic functions that corre-
spond to the data type used. The implementation uses function pointers that, by default, are set to the
correct values for the datatype used. The user may change these defaults and set the function pointers
to execute their functions instead. The functions the user can substitute for are initialization, crossover,
mutation, checking for duplicate strings, string printing, termination criteria, and a generic function called
at the end of each GA iteration.
The function call PGASetUserFunction(ctx, PGA USERFUNCTION MUTATION, mymute) will cause PGA-
Pack to execute the function mymute whenever the mutation operator is called. Table 7.1 is a list of
functions that can be customized for use with a native datatype. The rst column describes the func-
tionality, and the second column the symbolic constant for use with PGASetUserFunction. The call-
ing sequence for these functions is xed and must follow the function prototypes in Table 7.2. The les
./examples/templates/uf native.c and ./examples/templates/uf native.f contain template routines
for these functions. A specic example is given below.
Checking the termination criteria requires some discussion. The function PGADone will either check to
see if the standard stopping criteria (see Section 5.3) have been met, or call the user function specied by
PGA USERFUNCTION STOPCOND. If you wish to have the user function check for the standard stopping criteria
in addition to whatever else it does, it should call PGACheckStoppingConditions(ctx). Do not call PGADone
as this will cause an innite loop to occur. Note that in a parallel program PGACheckStoppingConditions
should only be called by the master process (see Chapter 10).
The end of generation function (which is null by default) may be used for gathering statistics about the
GA, displaying custom output, etc. This function is called after all generational computation is complete, but
33
Table 7.2: Calling Sequences for Customizable Functions
Symbolic Constant Return Function Prototype
PGA USERFUNCTION INITSTRING void (PGAContext*, int, int)
PGA USERFUNCTION CROSSOVER void (PGAContext*, int, int, int, int, int, int)
PGA USERFUNCTION MUTATION int (PGAContext*, int, int, double)
PGA USERFUNCTION DUPLICATE int (PGAContext*, int, int, int, int)
PGA USERFUNCTION PRINTSTRING void (PGAContext*, FILE *, int, int)
PGA USERFUNCTION STOPCOND int (PGAContext*)
PGA USERFUNCTION ENDOFGEN void (PGAContext*)
before the population pointers (PGA NEWPOP, PGA OLDPOP) have been switched and the standard PGAPack
output printed. Therefore, be sure to use PGA NEWPOP as the population pointer. There is no mechanism for
suppressing the standard PGAPack generational output.
The optimal solution to this problem, 2 , is achieved by setting each j to . The les for this example,
L x L
34
#include <pgapack.h>
35
include 'pgapackf.h'
include 'mpif.h'
double precision evaluate
integer myMutation
external evaluate, myMutation
integer ctx, i, maxiter, ierror
call MPI_Init(ierror)
ctx = PGACreate (PGA_DATATYPE_INTEGER, 10, PGA_MAXIMIZE)
call PGASetUserFunction (ctx, PGA_USERFUNCTION_MUTATION,
& myMutation)
call PGASetIntegerInitPermute(ctx, 1, 10)
call PGASetUp (ctx)
call PGARun (ctx, evaluate)
call PGADestroy (ctx)
call MPI_Finalize(ierror)
stop
end
36
Chapter 8
Custom Usage: New Data Types
This chapter discusses how PGAPack may be extended by dening a new data type. Dening a new data
type may be done only in C programs.
8.1 Basics
To create a new data type, you must (1) specify PGA DATATYPE USER for the datatype in the PGACreate call
and (2) for each entry in Table 8.1, call PGASetUserFunction to specify the function that will perform the
given operation on the new data type. If the data type is PGA DATATYPE USER, the string length specied
to PGACreate can be whatever the user desires. It will be returned by PGAGetStringLength but is not
otherwise used in the data-structure-neutral functions of PGAPack.
The calling sequences for the functions in Table 8.1 are given in Table 8.2. The le ./examples/templates/uf new.c
contains template routines for these functions.
While PGAPack requires that the user supply all the functions in Table 8.1, your program may not
require the functionality of all of them. For example, the user really does not need to write a function to
pack the strings for message-passing unless a parallel version of PGAPack is being used. In these cases,
we suggest that the user supply a stub function i.e., a function with the correct calling sequence but no
functionality.
37
Table 8.2: Calling Sequences for New Data Type Functions
Symbolic Constant Return Function Prototype
PGA USERFUNCTION CREATESTRING void (PGAContext*, int, int, int)
PGA USERFUNCTION BUILDDATATYPE int (PGAContext*, int, int)
PGA USERFUNCTION MUTATION int (PGAContext*, int, int, double)
PGA USERFUNCTION CROSSOVER void (PGAContext*, int, int, int, int, int, int)
PGA USERFUNCTION PRINTSTRING void (PGAContext*, FILE *, int, int)
PGA USERFUNCTION COPYSTRING int (PGAContext*, int, int, int, int)
PGA USERFUNCTION DUPLICATE int (PGAContext*, int, int, int, int)
#include <pgapack.h>
typedef struct {
double t6] /* ligand translation and rotation */
int sc40] /* ligand sidechain rotations */
} ligand
38
void CreateString(PGAContext *ctx, int p, int pop, int InitFlag) {
int i
ligand *ligand_ptr
PGAIndividual *new
Figure 8.2: Creation and Initialization Function for Structure Data Type
ligand molecule about each of the axes. The ints in the sc array represent side chain rotations (which are
discrete) of the ligand molecule.
Figure 8.2 contains the function CreateString that allocates and initializes the ligand structure. At this
level of usage it is no longer always possible to maintain the (p,pop) abstraction to specify an individual (a
string and associated elds). CreateString works directly with the string pointer that (p,pop) is mapped
to. If InitFlag is true, CreateString will initialize the elds otherwise they are set to 0.
PGAGetIndividual(ctx, p, pop) returns a pointer of type PGAIndividual to the individual (the string
and associated elds) specied by (p,pop). PGAIndividual is a structure, one of the elds of which is chrom,
a void pointer to the string itself. That pointer, new->chrom, is assigned the address of the memory allocated
by the malloc function. As malloc returns a void pointer, no cast is necessary.
The value of InitFlag is passed by PGAPack to the user's string creation routine. It species whether to
randomly initialize the string or set it to zero. By default, PGA OLDPOP (except for PGA TEMP1 and PGA TEMP1
which are set to zero) is randomly initialized, and PGA NEWPOP is set to zero. This choice may be changed
with the PGASetRandomInitFlag function discussed in Section 5.4.)
Figure 8.3 contains the mutation function Mutation for the ligand data type. Each of the 46 genes has
a probability of mr of being changed. If a mutation occurs, Mutation adds or subtracts one tenth to the
existing value of a double, and adds or subtracts one to an int.
Figure 8.4 contains the crossover function Crossover, which implements uniform crossover for the ligand
data type. The lines
parent1 = (ligand *)PGAGetIndividual(ctx, p1, pop1)->chrom
parent2 = (ligand *)PGAGetIndividual(ctx, p2, pop1)->chrom
child1 = (ligand *)PGAGetIndividual(ctx, t1, pop2)->chrom
child2 = (ligand *)PGAGetIndividual(ctx, t2, pop2)->chrom
39
int Mutation(PGAContext *ctx, int p, int pop, double mr) {
ligand *ligand_ptr
int i, count = 0
are worthy of mention. Each implements in one line what the two lines
new = PGAGetIndividual(ctx, p, pop)
string = (ligand *)new->chrom
in Mutation did. Either style is acceptable. PGAGetIndividual returns a pointer whose chrom eld (a void
pointer) is cast to the ligand data type.
Figure 8.5 contains the code for DuplicateString, which checks for duplicate ligand structures. It uses
the ANSI C memcmp function for this purpose.
Figure 8.6 contains the evaluation function for this example. It again uses PGAGetIndividual to map
(p, pop) into a pointer to the string of interest. For user data types, PGAPack does not provide a
PGAGetUserAllele function, so access to the allele values is made directly through the pointer.
Figure 8.7 contains the function BuildDT that builds an MPI datatype for sending strings to other
processors. Consult an MPI manual for further information.
40
void Crossover(PGAContext *ctx, int p1, int p2, int pop1, int t1, int t2,
int pop2) {
int i
ligand *parent1, *parent2, *child1, *child2
double pu
pu = PGAGetUniformCrossoverProb(ctx)
int DuplicateString(PGAContext *ctx, int p1, int pop1, int p2, int pop2) {
void *a, *b
41
double Evaluate(PGAContext *ctx, int p, int pop) {
int i, j
double x6]
int sc40]
PGAIndividual *ind
ligand *lig
42
MPI_Datatype BuildDT(PGAContext *ctx, int p, int pop) {
int counts5]
MPI_Aint displs5]
MPI_Datatype types5]
MPI_Datatype DT_PGAIndividual
PGAIndividual *P
ligand *S
P = PGAGetIndividual(ctx, p, pop)
S = (ligand *)P->chrom
/* Build the MPI datatype. Every user defined function needs these.
* The first two calls are stuff that is internal to PGAPack, but
* the user still must include it. See pgapack.h for details one the
* fields (under PGAIndividual)
*/
MPI_Address(&P->evalfunc, &displs0])
counts0] = 2
types0] = MPI_DOUBLE
43
Chapter 9
Hill-Climbing and Hybridization
Hill-climbing heuristics attempt to improve a solution by moving to a better neighbor solution. Whenever the
neighboring solution is better than the current solution, it replaces the current solution. Genetic algorithms
and hill-climbing heuristics have complementary strong and weak points. GAs are good at nding promising
areas of the search space, but not as good at ne-tuning within those areas. Hill-climbing heuristics, on
the other hand, are good at ne-tuning, but lack a global perspective. Practice has shown that a hybrid
algorithm that combines GAs with hill-climbing heuristics often results in an algorithm that can outperform
either one individually.
There are two general schemes for creating hybrid algorithms. The simplest is to run the genetic algorithm
until it terminates and then apply a hill-climbing heuristic to each (or just the best) string. The second
approach is to integrate a hill-climbing heuristic with the genetic algorithm. Choices to be made in the
second case include how often to apply the hill-climbing heuristic and how many strings in the population
to apply it to.
PGAPack supports hybrid schemes in the following ways:
By passing, the context variable as a parameter to the user's hill-climbing function, the user has access
to solution and parameter values, debug ags, and other information.
The functions PGAGetBinaryAllele, PGAGetIntegerAllele, PGAGetRealAllele, and PGAGetCharacterAllele
allow the user's hill-climbing function to read allele values, and the functions PGASetBinaryAllele,
PGASetIntegerAllele, PGASetRealAllele, and PGASetCharacterAllele allow the user's hill-climbing
function to set allele values explicitly.
The functions PGADecodeRealAsBinary, PGADecodeRealAsGrayCode, PGADecodeIntegerAsBinary,
and PGADecodeIntegerAsGrayCode allow the user's hill-climbing function to read integer or real num-
bers encoded as binary or Gray code strings.
The functions PGAEncodeRealAsBinary, PGAEncodeRealAsGrayCode, PGAEncodeIntegerAsBinary,
and PGAEncodeIntegerAsGrayCode allow the user's hill-climbing function to encode integer or real
numbers as binary or Gray code strings.
The functions PGAGetEvaluation and PGASetEvaluation allow the user's hill-climbing function to get
and set evaluation function values, and PGASetEvaluationUpToDateFlag and PGAGetEvaluationUpToDateFlag
to get and set the ag that indicates whether an evaluation function value is up to date.
One way to run a hybrid GA and use PGARun is to use the PGASetUserFunction discussed in Chapter 7
to specify a user function to be called at the end of each GA iteration. A more exible approach would be
for the user to call the high-level PGAPack functions, and their hillclimber to explicitly specify the steps of
the hybrid GA.
Figure 9.1 is a version of the Maxbit problem given in Section 3.1. It uses the hill-climbing function
hillclimb, which is called after the recombination step. It randomly selects a gene to set to one. Note the
PGASetEvaluationUpToDateFlag call. It sets the ag that indicates the evaluation function is not current
with the string (since the string was changed). It is critical that this ag be set when the user changes a
44
string, since the value of this ag determines whether PGAEvaluate will invoke the user's function evaluation
routine.
#include "pgapack.h"
45
Chapter 10
Parallel Aspects
This chapter assumes familiarity with the background material in Appendix C. It also assumes that a parallel
version of PGAPack was built and that programs are linked with an MPI library (see Section 2.4).
Version 1.0 of PGAPack supports parallel and sequential implementations of the single population global
model (GM). The parallel implementation uses a master/slave algorithm in which one process, the master,
executes all steps of the genetic algorithm except the function evaluations. The function evaluations are
executed by the slave processes1 .
46
The type of algorithm used to execute PGAEvaluate(ctx,pop,f,comm) will depend on the number of
processes in the communicator comm. If it is NULL or contains one process, a sequential implementation will
be used. If more than one process is specied it will execute a master/slave evaluation of the strings in
population pop that require evaluation by applying, f, the user's evaluation function. PGAEvaluate should
be called by all processes in communicator comm.
PGASendIndividual(ctx,p,pop,dest,tag,comm) will send string p in population pop to process dest.
tag is a tag used to identify the message, and comm is an MPI communicator. This function calls MPI Send
to perform the actual message passing. In addition to string p itself, the evaluation function value, tness
function value, and evaluation status ag are also sent.
PGAReceiveIndividual is the complementary function to PGASendIndividual. For example, PGAReceiveIndividual
(ctx,p,pop,source,tag,comm,status) will store in location p in population pop the string and elds of
the individual sent from process source with the MPI tag tag and MPI communicator comm. status is an
MPI status vector.
PGASendReceiveIndividual combines the functionality of PGASendIndividual and PGAReceiveIndividual.
This may be useful in avoiding potential deadlock on some systems. For example, PGASendReceiveIndividual
(ctx,sp,spop,dest,stag,rp,rpop,source, rtag,comm,status). Here, sp is the index of the string in
population spop to send to process dest with tag stag. The string received from process source with tag
rtag is stored in location rp in population rpop. comm and status are the same as dened earlier.
PGABuildDatatype(ctx,p,pop) packs together the string and elds that PGASendIndividual, PGAReceiveIndividual,
and PGASendReceiveIndividual send and receive. The result is of type MPI Datatype.
10.3 Example
Figure 10.1 is a parallel version of the example in Figure 6.1. Since we now have multiple processes executing
the program at the same time, we must coordinate each ones execution. In the example, the master process
(the one with rank 0 as determined by PGAGetRank) executes all functions, and the slave processes execute
only those functions that take a communicator as an argument. Note that this example will execute correctly
even if only one process is in the communicator.
10.4 Performance
The parallel implementation of the GM will produce the same result as the sequential implementation,
usually faster. However, the parallel implementation varies with the number of processes. If two processes
are used, both the master process and the slave process will compute the function evaluations. If more
than two processes are used, the master is responsible for bookkeeping only, and the slaves for executing the
function evaluations. In general, the speedup obtained will vary with the amount of computation associated
with a function evaluation and the computational overhead of distributing and collecting information to and
from the slave processes.
The speedup that can be achieved with the master/slave model is limited by the number of function
evaluations that can be executed in parallel. This number depends on the population size and the number
of new strings created each generation. For example, if the population size is 100 and a 100 new strings
are created each GA generation, then up to 100 processors can be put to eective use to run the slave
processes. However, with the default rule of replacing only 10% of the population each GA generation, only
10 processors can be used eectively.
47
#include "pgapack.h"
double evaluate (PGAContext *ctx, int p, int pop)
48
Chapter 11
Fortran Interface
PGAPack is written entirely in ANSI C. A set of interface functions, also written in C, is designed to be
called by Fortran programs and then call the \real" C routine. This mechanism provides most of PGAPack's
functionality to Fortran programs. The following list contains most major dierences between C and Fortran.
Additional, machine-specic idiosyncrasies are noted in Appendix D.
The Makefiles for the Fortran examples (in ./examples/fortran and ./examples/mgh) are not con-
gured to use the -I mechanism for specifying the include le search path (since not all Fortran compilers
support this). Therefore, you will need to copy or set up a symbolic link to ./include/pgapackf.h
from the directory you are compiling a Fortran program in.
The context variable is declared integer (or integer*8, see Appendix D) in Fortran.
PGACreate takes only three arguments in Fortran (not argc or argv as in C).
The Fortran include le is pgapackf.h and should be included in any Fortran subroutine or function
that calls a PGAPack function, to ensure correct typing and denition of functions and symbolic
constants.
If a C function returns an f int, double, pointerg, the corresponding Fortran function returns an
f integer, double precision, integerg. If the C function is void it is implemented as a Fortran
subroutine.
When supplying function arguments, a C int corresponds to a Fortran integer, and a C double
corresponds to a Fortran double precision. For example, to set the crossover probability to 0.6, use
call PGASetCrossoverProb(ctx, 0.6d0),
or
double precision pc
pc = 0.6
call PGASetCrossoverProb(ctx, pc)
Population member indices are 0 ; 1] in C, and 1 ] in Fortran, where is the population size.
N N N
49
The DEC Alpha and Silicon Graphics Power Challenge, which have 64-bit C pointers and 32-bit Fortran
integers (but not the Cray T3D which has 64-bit Fortran integers), have additional dierences1 . These
arise because a Fortran integer is too small to hold the address returned by the C interface routine.
{ The context variable should be declared integer*8.
{ MPI COMM WORLD should not be passed directly to PGAPack Fortran functions. Instead, PGAGetCommunicator
should be called to return the address into an integer*8 variable. For example
integer pid
integer*8 comm
comm = PGAGetCommunicator(ctx)
:
pid = PGAGetRank(ctx, comm)
{ can and should be passed directly to any MPI routines called directly from
MPI COMM WORLD
Fortran.
{ Calling an MPI routine that returns a communicator is safe. However, passing the returned
communicator to a PGAPack Fortran function will usually fail.
1 More generally, these issues arise whenever the size of a Fortran integer is less than the size of a pointer.
50
Chapter 12
Debugging Tools
PGAPack has a sophisticated built-in trace facility that is useful for debugging. When the facility is invoked,
print statements to stdout allow the programmer to trace the sequence of functions PGAPack executes. Due
to the negative impact on performance this facility is not available by default. Instead, you must explicitly
enable tracing when conguring PGAPack with the -debug ag. See Section 2.4.
The trace facility uses the concept of a debug level. For example, executing the Maxbit example (Fig-
ure 3.1) with a debug level of 12, maxbit -pgadbg 12, will print the output shown in Figure 12.1. The \0:"
is the process rank. This is followed by the name of a PGAPack function and the \action" that caused the
print statement to execute. In this case, the action is entering the function. Note that the rank printed for
a process is always its rank in the MPI COMM WORLD communicator, even if another communicator was set.
Tracing is enabled by specifying one or more debug levels to trace. A list of debug levels is given in
Table 12.1. Not all debug level values are currently used. The values 1{10 are reserved for users as described
below.
C programmers may set the debug level from the command line using either -pgadbg <debug level>
or -pgadebug <debug level>. Several forms of the <debug level> argument are allowed. -pgadbg 12 will
trace entering all high-level functions as shown in Figure 12.1. -pgadbg 12,13 or -pgadbg 12-13 will trace
entering and exiting of all high-level functions. The command line option -pgahelp debug will list the debug
level options and then exit.
Fortran (and C) programmers may access the trace facility via function calls. The function PGASetDebugLevel
may be called to set a debug level. For example, call PGASetDebugLevel(ctx,12) would produce the same
output shown in Figure 12.1. PGAClearDebugLevel(ctx,12) will clear prints associated with debug level
12. PGAPrintDebugOptions(ctx) will print the list of available debug options.
The function PGASetDebugLevelByName will turn on debugging of the named function. For exam-
ple, PGASetDebugLevelByName(ctx,''PGACrossover'') will enable all the trace prints of PGACrossover.
PGAClearDebugLevelByName will disable the tracing of the specied function.
Users can use the trace facility in their own functions (e.g., their evaluation function) in two ways.
First, they can insert PGADebugPrint function calls in their functions using one of the symbolic constants
dened in the header le pgapack.h. These are PGA DEBUG ENTERED, PGA DEBUG EXIT, PGA DEBUG MALLOC,
PGA DEBUG PRINTVAR, PGA DEBUG SEND, and PGA DEBUG RECV for entering a function, exiting a function, al-
locating memory, print a variable's value, and sending or receiving a string, respectively.
For example, PGADebugPrint(ctx, PGA DEBUG ENTERED, "MyFunc", "Entered", PGA VOID, NULL) will
print the line
0: MyFunc : Entered
when the debug level of 12 is specied. PGADebugPrint(ctx, PGA DEBUG PRINTVAR, "MyFunc", "i = ",
PGA INT, (void *) &i) will print the line
0: MyFunc : i = 1
when the debug level of 82 is specied. Users can also use the reserved debug levels of 1{10 to customize the
trace facilities for use in their own functions. For example PGADebugPrint( ctx, 5, "MyFunc", "After
call to MyCleanUp", PGA VOID, NULL) will print the line
51
0: PGACreate : Entered
0: PGASetRandomSeed : Entered
0: PGASetMaxGAIterValue : Entered
0: PGASetUp : Entered
0: PGACreatePop : Entered
0: PGACreateIndividual : Entered
:
:
0: PGACreateIndividual : Entered
0: PGACreatePop : Entered
0: PGACreateIndividual : Entered
:
:
0: PGARun : Entered
0: PGARunSeq : Entered
0: PGAEvaluate : Entered
0: PGAFitness : Entered
0: PGAGetStringLength : Entered
:
:
52
Table 12.1: Debug Levels in PGAPack
0 Trace all debug prints
11 Trace high-level functions
12 Trace all function entries
13 Trace all function exits
20 Trace high-level parallel functions
21 Trace all parallel functions
22 Trace all send calls
23 Trace all receive calls
30 Trace Binary functions
32 Trace Integer functions
34 Trace Real functions
36 Trace Character functions
40 Trace population creation functions
42 Trace select functions
44 Trace mutation functions
46 Trace crossover functions
48 Trace function evaluation functions
50 Trace tness calculation functions
52 Trace duplicate checking functions
54 Trace restart functions
56 Trace reporting functions
58 Trace stopping functions
60 Trace sorting functions
62 Trace random number functions
64 Trace system routines
66 Trace utility functions
80 Trace memory allocations
82 Trace variable print statements
53
Part III
Appendixes
54
Appendix A
Default Values
55
Table A.1: PGAPack Default Values
CONCEPT DEFAULT SET WITH
Population size 100 PGASetPopSize
Copied for population replacement PGA POPREPL BEST PGASetPopReplacementType
Stopping rule PGA STOP MAXITER PGASetStoppingRuleType
Maximum iterations 1000 PGASetMaxGAIterValue
Maximum no change iters 100 PGASetMaxNoChangeValue
Max. population homogeneity before stopping 95 PGASetMaxSimilarityValue
Number of new strings to generate 10 PGASetNumReplaceValue
Apply mutation and crossover PGA FALSE PGASetMutationAndCrossoverFlag
Apply mutation or crossover PGA TRUE PGASetMutationOrCrossoverFlag
Crossover type PGA CROSSOVER TWOPT PGASetCrossoverType
Probability of crossover 0.85 PGASetCrossoverProb
Uniform crossover bias 0.6 PGASetUniformCrossoverProb
Mutation type (Real strings) PGA MUTATION GAUSSIAN PGASetMutationType
Mutation type (Integer strings) PGA MUTATION PERMUTE PGASetMutationType
Mutation type (Character strings) Same as initialization PGASetCharacterInitType
Mutation probability 1/L PGASetMutationProb
Real mutation constant 0.1 PGASetMutationRealValue
Integer mutation constant 1 PGASetMutationIntegerValue
Mutation range bounded PGA TRUE PGASetMutationBoundedFlag
Select type PGA SELECT TOURNAMENT PGASetSelectType
Probabilistic binary tournament parameter 0.6 PGASetPTournamentProb
Use restart operator PGA FALSE PGASetRestartFlag
Restart frequency 50 PGASetRestartFrequencyValue
Restart allele mutation rate 0.5 PGASetRestartAlleleChangeProb
Allow duplicate strings PGA FALSE PGASetNoDuplicatesFlag
Fitness type PGA FITNESS RAW PGASetFitnessType
Fitness type for minimization PGA FITNESSMIN CMAX PGASetFitnessMinType
Multiplier for minimization problems 1.01 PGASetCMaxValue
Parameter MAX in tness by ranking 1.2 PGASetMaxFitnessRank
Frequency of statistics printing 10 PGASetPrintFrequencyValue
Print strings PGA FALSE PGASetPrintOptions
Print o!ine statistics PGA FALSE PGASetPrintOptions
Print online statistics PGA FALSE PGASetPrintOptions
Print best string PGA FALSE PGASetPrintOptions
Print worst string PGA FALSE PGASetPrintOptions
Print Hamming distance PGA FALSE PGASetPrintOptions
Randomly initialize population PGA TRUE PGASetRandomInitFlag
Probability of initializing a bit to one 0.5 PGASetBinaryInitProb
How to initialize real strings Range PGASetrealInitRange
Real initialization range 0 1]
PGASetRealInitRange
How to initialize integer strings Permutation PGASetIntegerInitPermute
Integer initialization range 0 ; 1]
L PGASetIntegerInitPermute
How to initialize character strings PGA CINIT LOWER PGASetCharacterInitFlag
Seed random number with clock PGA TRUE PGASetRandomSeed
Default MPI communicator MPI COMM WORLD PGASetCommunicator
L is the string length
56
Appendix B
Function Bindings
Symbolic Constants
PGAPack denes many symbolic constants that are used as arguments to PGAPack functions. These
constants are the same for both Fortran and C. Below is a list of these constants. These constants are the
same for both Fortran and C.
PGAPack Data Types
{ PGA DATATYPE BINARY
{ PGA DATATYPE INTEGER
{ PGA DATATYPE REAL
{ PGA DATATYPE CHARACTER
{ PGA DATATYPE USER
String Types
{ PGABinary
{ PGAInteger
{ PGAReal
{ PGACharacter
57
{ PGA UNINITIALIZED DOUBLE
Debug Levels
{ PGA DEBUG ENTERED
{ PGA DEBUG EXIT
{ PGA DEBUG MALLOC
{ PGA DEBUG PRINTVAR
{ PGA DEBUG SEND
{ PGA DEBUG RECV
Direction of Optimization
{ PGA MAXIMIZE
{ PGA MINIMIZE
Stopping Criteria
{ PGA STOP MAXITER
{ PGA STOP NOCHANGE
{ PGA STOP TOOSIMILAR
Crossover
{ PGA CROSSOVER ONEPT
{ PGA CROSSOVER TWOPT
{ PGA CROSSOVER UNIFORM
Fitness
{ PGA FITNESS RAW
{ PGA FITNESS NORMAL
{ PGA FITNESS RANKING
Fitness Minimization
{ PGA FITNESSMIN RECIPROCAL
{ PGA FITNESSMIN CMAX
Mutation Type
{ PGA MUTATION CONSTANT
{ PGA MUTATION RANGE
{ PGA MUTATION UNIFORM
{ PGA MUTATION GAUSSIAN
{ PGA MUTATION PERMUTE
58
Population Replacement
{ PGA POPREPL BEST
{ PGA POPREPL RANDOM NOREP
{ PGA POPREPL RANDOM REP
Initialization Options
{ PGA CINIT LOWER
{ PGA CINIT UPPER
{ PGA CINIT MIXED
{ PGA IINIT PERMUTE
{ PGA IINIT RANGE
{ PGA RINIT PERCENT
{ PGA RINIT RANGE
Report Options
{ PGA REPORT ONLINE
{ PGA REPORT OFFLINE
{ PGA REPORT HAMMING
{ PGA REPORT STRING
{ PGA REPORT WORST
{ PGA REPORT AVERAGE
Selection
{ PGA SELECT PROPORTIONAL
{ PGA SELECT SUS
{ PGA SELECT TOURNAMENT
{ PGA SELECT PTOURNAMENT
User Functions
{ PGA USERFUNCTION CREATESTRING
{ PGA USERFUNCTION MUTATION
{ PGA USERFUNCTION CROSSOVER
{ PGA USERFUNCTION PRINTSTRING
{ PGA USERFUNCTION COPYSTRING
{ PGA USERFUNCTION DUPLICATE
{ PGA USERFUNCTION INITSTRING
{ PGA USERFUNCTION BUILDDATATYPE
{ PGA USERFUNCTION STOPCOND
{ PGA USERFUNCTION ENDOFGEN
59
ANSI C Bindings
The use of any PGAPack function requires that the user have #include "pgapack.h" at the top of the le
that references PGAPack functions.
Type Function
MPI Datatype PGABuildDatatype(PGAContext *ctx, int p, int pop)
void PGAChange(PGAContext *ctx, int p, int pop)
int PGACheckStoppingConditions(PGAContext *ctx)
int PGACheckSum(PGAContext *ctx, int p, int pop)
void PGAClearDebugLevel(PGAContext *ctx, int level)
void PGAClearDebugLevelByName(PGAContext *ctx, char *funcname)
void PGACopyIndividual(PGAContext *ctx, int p1, int pop1, int p2, int pop2)
PGAContext* PGACreate(int *argc, char **argv, int datatype, int len, int maxormin)
void PGACrossover(PGAContext *ctx, int p1, int p2, int pop1, int c1, int c2, int pop2)
void PGADebugPrint(PGAContext *ctx, int level, char *funcname,
char *msg, int datatype, void *data)
void PGADestroy(PGAContext *ctx)
int PGADone(PGAContext *ctx, MPI Comm comm)
int PGADuplicate(PGAContext *ctx, int p, int pop1, int pop2, int n)
void PGAEncodeIntegerAsBinary(PGAContext *ctx, int p, int pop, int start, int end, int val)
void PGAEncodeIntegerAsGrayCode(PGAContext *ctx, int p, int pop, int start, int end, int val)
void PGAEncodeRealAsBinary(PGAContext *ctx, int p, int pop,
int start, int end, double low, double high, double val)
void PGAEncodeRealAsGrayCode(PGAContext *ctx, int p, int pop,
int start, int end, double low, double high, double val)
void PGAError(PGAContext *ctx, char *msg, int level, int datatype, void *data)
void PGAEvaluate(PGAContext *ctx, int pop,
double(*f)(PGAContext *, int, int), MPI Comm comm)
void PGAFitness(PGAContext *ctx, int popindex)
int PGAGetBestIndex(PGAContext *ctx, int pop)
int PGAGetBinaryAllele(PGAContext *ctx, int p, int pop, int i)
double PGAGetBinaryInitProb(PGAContext *ctx)
char PGAGetCharacterAllele(PGAContext *ctx, int p, int pop, int i)
MPI Comm PGAGetCommunicator(PGAContext *ctx)
double PGAGetCrossoverProb(PGAContext *ctx)
int PGAGetCrossoverType(PGAContext *ctx)
int PGAGetDataType(PGAContext *ctx)
double PGAGetEvaluation(PGAContext *ctx, int p, int pop)
int PGAGetEvaluationUpToDateFlag(PGAContext *ctx, int p, int pop)
double PGAGetFitness(PGAContext *ctx, int p, int pop)
double PGAGetFitnessCmaxValue(PGAContext *ctx)
int PGAGetFitnessMinType(PGAContext *ctx)
int PGAGetFitnessType(PGAContext *ctx)
int PGAGetGAIterValue(PGAContext *ctx)
int PGAGetIntegerAllele(PGAContext *ctx, int p, int pop, int i)
int PGAGetIntegerFromBinary(PGAContext *ctx, int p, int pop, int start, int end)
int PGAGetIntegerFromGrayCode(PGAContext *ctx, int p, int pop, int start, int end)
int PGAGetIntegerInitType(PGAContext *ctx)
60
Type Function
double PGAGetMaxFitnessRank(PGAContext *ctx)
int PGAGetMaxGAIterValue(PGAContext *ctx)
int PGAGetMaxIntegerInitValue(PGAContext *ctx, int i)
double PGAGetMaxMachineDoubleValue(PGAContext *ctx)
int PGAGetMaxMachineIntValue(PGAContext *ctx)
double PGAGetMaxRealInitValue(PGAContext *ctx, int i)
int PGAGetMinIntegerInitValue(PGAContext *ctx, int i)
double PGAGetMinMachineDoubleValue(PGAContext *ctx)
int PGAGetMinMachineIntValue(PGAContext *ctx)
double PGAGetMinRealInitValue(PGAContext *ctx, int i)
int PGAGetMutationAndCrossoverFlag(PGAContext *ctx)
int PGAGetMutationBoundedFlag(PGAContext *ctx)
int PGAGetMutationIntegerValue(PGAContext *ctx)
int PGAGetMutationOrCrossoverFlag(PGAContext *ctx)
double PGAGetMutationProb(PGAContext *ctx)
double PGAGetMutationRealValue(PGAContext *ctx)
int PGAGetMutationType(PGAContext *ctx)
int PGAGetNoDuplicatesFlag(PGAContext *ctx)
int PGAGetNumProcs(PGAContext *ctx, MPI Comm comm)
int PGAGetNumReplaceValue(PGAContext *ctx)
int PGAGetOptDirFlag(PGAContext *ctx)
double PGAGetPTournamentProb(PGAContext *ctx)
int PGAGetPopReplaceType(PGAContext *ctx)
int PGAGetPopSize(PGAContext *ctx)
int PGAGetPrintFrequencyValue(PGAContext *ctx)
int PGAGetRandomInitFlag(PGAContext *ctx)
int PGAGetRandomSeed(PGAContext *ctx)
int PGAGetRank(PGAContext *ctx, MPI Comm comm)
double PGAGetRealAllele(PGAContext *ctx, int p, int pop, int i)
double PGAGetRealFromBinary(PGAContext *ctx, int p, int pop,
int start, int end, double lower, double upper)
double PGAGetRealFromGrayCode(PGAContext *ctx, int p, int pop,
int start, int end, double lower, double upper)
int PGAGetRealInitType(PGAContext *ctx)
double PGAGetRestartAlleleChangeProb(PGAContext *ctx)
int PGAGetRestartFlag(PGAContext *ctx)
int PGAGetRestartFrequencyValue(PGAContext *ctx)
int PGAGetSelectType(PGAContext *ctx)
int PGAGetSortedPopIndex(PGAContext *ctx, int n)
int PGAGetStoppingRuleType(PGAContext *ctx)
int PGAGetStringLength(PGAContext *ctx)
double PGAGetUniformCrossoverProb(PGAContext *ctx)
int PGAGetWorstIndex(PGAContext *ctx, int pop)
double PGAHammingDistance(PGAContext *ctx, int popindex)
double PGAMean(PGAContext *ctx, double *a, int n)
int PGAMutate(PGAContext *ctx, int p, int pop)
void PGAPrintContextVariable(PGAContext *ctx, FILE *fp)
void PGAPrintIndividual(PGAContext *ctx, FILE *fp, int p, int pop)
void PGAPrintPopulation(PGAContext *ctx, FILE *fp, int pop)
void PGAPrintReport(PGAContext *ctx, FILE *fp, int pop)
void PGAPrintString(PGAContext *ctx, FILE *le, int p, int pop)
void PGAPrintVersionNumber(PGAContext *ctx)
61
Type Function
double PGARandom01(PGAContext *ctx, int newseed)
int PGARandomFlip(PGAContext *ctx, double p)
double PGARandomGaussian(PGAContext *ctx, double mean, double sigma)
int PGARandomInterval(PGAContext *ctx, int start, int end)
double PGARandomUniform(PGAContext *ctx, double start, double end)
int PGARank(PGAContext *ctx, int p, int *order, int n)
void PGAReceiveIndividual(PGAContext *ctx, int p, int pop, int source,
int tag, MPI Comm comm, MPI Status *status)
void PGARestart(PGAContext *ctx, int source pop, int dest pop)
int PGARound(PGAContext *ctx, double x)
void PGARun(PGAContext *ctx, double(*evaluate)(PGAContext *c, int p, int pop))
void PGARunGM(PGAContext *ctx, double(*f)(PGAContext *, int, int), MPI Comm comm)
void PGARunMutationAndCrossover(PGAContext *ctx, int oldpop, int newpop)
void PGARunMutationOrCrossover(PGAContext *ctx, int oldpop, int newpop)
void PGASelect(PGAContext *ctx, int popix)
int PGASelectNextIndex(PGAContext *ctx)
void PGASendIndividual(PGAContext *ctx, int p, int pop, int dest, int tag, MPI Comm comm)
void PGASendReceiveIndividual(PGAContext *ctx, int send p,
int send pop, int dest, int send tag, int recv p, int recv pop,
int source, int recv tag, MPI Comm comm, MPI Status *status)
void PGASetBinaryAllele(PGAContext *ctx, int p, int pop, int i, int val)
void PGASetBinaryInitProb(PGAContext *ctx, double probability)
void PGASetCharacterAllele(PGAContext *ctx, int p, int pop, int i, char value)
void PGASetCharacterInitType(PGAContext *ctx, int value)
void PGASetCommunicator(PGAContext *ctx, MPI Comm comm)
void PGASetCrossoverProb(PGAContext *ctx, double crossover prob)
void PGASetCrossoverType(PGAContext *ctx, int crossover type)
void PGASetDebugLevel(PGAContext *ctx, int level)
void PGASetDebugLevelByName(PGAContext *ctx, char *funcname)
void PGASetEvaluation(PGAContext *ctx, int p, int pop, double val)
void PGASetEvaluationUpToDateFlag(PGAContext *ctx, int p, int pop, int status)
void PGASetFitnessCmaxValue(PGAContext *ctx, double val)
void PGASetFitnessMinType(PGAContext *ctx, int tness type)
void PGASetFitnessType(PGAContext *ctx, int tness type)
void PGASetIntegerAllele(PGAContext *ctx, int p, int pop, int i, int value)
void PGASetIntegerInitPermute(PGAContext *ctx, int min, int max)
void PGASetIntegerInitRange(PGAContext *ctx, int *min, int *max)
void PGASetMaxFitnessRank(PGAContext *ctx, double tness rank max)
void PGASetMaxGAIterValue(PGAContext *ctx, int maxiter)
void PGASetMaxNoChangeValue(PGAContext *ctx, int max no change)
void PGASetMaxSimilarityValue(PGAContext *ctx, int max similarity)
void PGASetMutationAndCrossoverFlag(PGAContext *ctx, int ag)
void PGASetMutationBoundedFlag(PGAContext *ctx, int val)
void PGASetMutationIntegerValue(PGAContext *ctx, int val)
void PGASetMutationOrCrossoverFlag(PGAContext *ctx, int ag)
void PGASetMutationProb(PGAContext *ctx, double mutation prob)
void PGASetMutationRealValue(PGAContext *ctx, double val)
void PGASetMutationType(PGAContext *ctx, int mutation type)
62
Type Function
void PGASetNoDuplicatesFlag(PGAContext *ctx, int no dup)
void PGASetNumReplaceValue(PGAContext *ctx, int pop replace)
void PGASetPTournamentProb(PGAContext *ctx, double ptournament prob)
void PGASetPopReplaceType(PGAContext *ctx, int pop replace)
void PGASetPopSize(PGAContext *ctx, int popsize)
void PGASetPrintFrequencyValue(PGAContext *ctx, int print freq)
void PGASetPrintOptions(PGAContext *ctx, int option)
void PGASetRandomInitFlag(PGAContext *ctx, int RandomBoolean)
void PGASetRandomSeed(PGAContext *ctx, int seed)
void PGASetRealAllele(PGAContext *ctx, int p, int pop, int i, double value)
void PGASetRealInitPercent(PGAContext *ctx, double *median, double *percent)
void PGASetRealInitRange(PGAContext *ctx, double *min, double *max)
void PGASetRestartAlleleChangeProb(PGAContext *ctx, double prob)
void PGASetRestartFlag(PGAContext *ctx, int val)
void PGASetRestartFrequencyValue(PGAContext *ctx, int numiter)
void PGASetSelectType(PGAContext *ctx, int select type)
void PGASetStoppingRuleType(PGAContext *ctx, int stoprule)
void PGASetUniformCrossoverProb(PGAContext *ctx, double uniform cross prob)
void PGASetUp(PGAContext *ctx)
void PGASetUserFunction(PGAContext *ctx, int constant, void *f)
void PGASortPop(PGAContext *ctx, int pop)
double PGAStddev(PGAContext *ctx, double *a, int n, double mean)
void PGAUpdateGeneration(PGAContext *ctx, MPI Comm comm)
void PGAUsage(PGAContext *ctx)
Fortran 77 Bindings
Use the rules dened in Chapter 11 (and the machine-specic idiosyncrasies noted in Appendix D) to
determine the Fortran bindings.
63
Appendix C
Parallelism Background
Parallel Computer Taxonomy
Traditionally, parallel computers are classied according to Flynn's taxonomy 4]. Flynn's classication
distinguishes parallel computers according to the number of instruction streams and data operands being
computed on simultaneously.
Flynn's single-instruction single-data (SISD) model is the traditional sequential computer. A single
program counter fetches instructions from memory. The instructions are executed on scalar operands. There
is no parallelism in this model.
In the single-instruction multiple-data (SIMD) model there is again a single program counter fetching
instructions from memory. However, now the operands of the instructions can be one of two types: either
scalar or array. If the instruction calls for execution involving only scalar operands, it is executed by the
control processor (i.e., the central processing unit fetching instructions from memory). If, on the other hand,
the instruction calls for execution using array operands, it is broadcast to the array of processing elements.
The processing elements are separate computing devices that rely upon the control processor to determine
the instructions they will execute.
In a multiple-instruction multiple-data (MIMD) computer there exist multiple processors each of which
has its own program counter. Processors execute independently of each other according to whatever in-
struction the program counter points to next. MIMD computers are usually further subdivided according to
whether the processors share memory or each has its own memory.
In a shared-memory MIMD computer both the program's instructions and the part of the program's data
to be shared exist within a single shared memory. Additionally, some data may be private to a processor
and not be globally accessible by other processors. The processors execute asynchronously of each other.
Communication and synchronization between the processors are handled by having them each read or write
a shared-memory location.
A distributed-memory MIMD computer consists of multiple \nodes." A node consists of a processor, its
own memory, a network interface, and sometimes a local disk. The program instructions and data reside in
the node's memory. The nodes are connected via some type of network that allows them to communicate
with each other. Parallelism is achieved by having each processor compute simultaneously on the data in its
own memory. Communication and synchronization are handled by passing of messages (a destination node
address and the local data to be sent) over the interconnection network.
64
Message-Passing Programming Model
In the message-passing programmingmodel multiple processes communicate by passing messages|transferring
data from the address space of one process into the address space of another process. When a process needs
data stored in the memory of another process, the data must be sent from the process that \owns" it, to the
memory of the process that needs it.
The message-passing programming model is currently one of the most popular. One reason for the
popularity is portability. Message passing is the natural programming model on distributed-memory MIMD
computers. Each process is naturally mapped to one of the machine's nodes. A similar implementation
is common on a workstation network where one process runs on each workstation. On a shared-memory
MIMD computer multiple processes can emulate message passing by communicating only via logical message
queues|areas of shared memory partitioned by process. On a uniprocessor the multiple processes that
timeshare the physical processor can also emulate the idea of logical message queues for their communication.
One example of the message-passing programming model is the master/slave model. In this model a
master process distributed work (computation to be performed) to the slave processes. The slaves perform
the work and return the result to the master. In many implementations the master plays a bookkeeping role
only and does not perform any computation.
MPI
MPI (Message Passing Interface) is a specication of a message-passing library for parallel computers and
workstation networks|it denes a set of functions and their behavior. The actual implementation of this
interface is left up to vendors and researchers to develop. At the time of this writing several implementations
of MPI, both proprietary and freely available, exist. MPI was designed by a large group of parallel computer
vendors, computer researchers, and application developers as a standard for message passing.
65
Communicators
Almost all MPI functions require a communicator. If MPI routines are called directly, the user must supply
a communicator. Also, if any of PGAPack's parallel routines, other than PGARun, are used, the user must
supply a communicator as well.
A communicator combines the notions of context and group. A context is an extension of the notion of a
\tag" used in many other message-passing systems to identify a message. Contexts dier from tags in that
they are allocated by the system, not the user, and that no wild-card matching among contexts is allowed.
A group contains processes whose rank is an integer between 0
n ; 1. Processes may belong to more
: : : n
and
int len
scanf("%d",&len)
ctx = PGACreate(&argc, argv, PGA_DATATYPE_BINARY, len, PGA_MINIMIZE)
In the rst case, all processes will receive the value of 30 for the string length since it is a constant. In
the second case, however, the value of the string length is determined at run time. Whether one or all
processes execute the scanf function is undened in MPI and depends on the particular parallel computing
environment. In PGAPack we require that all processes have the same values for all elds in the context
variable. Since some of these elds may be set by using values specied at run time, we suggest that your
I/O that reads in PGAPack parameters be done as follows:
#include "pgapack.h"
double evaluate (PGAContext *ctx, int p, int pop)
MPI_Init(&argc, &argv)
MPI_Comm_rank(MPI_COMM_WORLD, &myid)
if (myid == 0) { /* Process 0 has a dialog */
printf("String length? ") /* with the user and */
scanf("%d", &len) /* broadcasts the user's */
}
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD)
66
MPI_Finalize()
return(0)
}
The key point is that only process 0 (as determined by MPI Comm rank) performs I/O and the value of
len is then broadcast (using MPI Bcast) to the other processes.
67
Appendix D
Machine Idiosyncrasies
Data Type Sizes
PGAPack is written entirely in ANSI C. However, because it is callable from Fortran, and no standards exist
for interlanguage communication, problems may arise. These have to do with a lack of consistency in the
size of data types between the two languages.
On all machines we have tested, an integer declaration in Fortran is the same size as an int declaration
in C and everything works properly. For oating-point numbers, however, we have found at least one
inconsistency. The requirement is for the Fortran oating-point number to be the same size as a C double.
On most machines a Fortran double precision declaration is the equivalent size. On the Cray T3D,
however, by default, the Fortran data type double precision is not supported and must be handled as
described below.
Since Fortran does not support pointers, an integer variable is used to hold the address of the context
variable (and possibly MPI communicator addresses as well). Therefore, a Fortran integer must be \large
enough" to hold an address on the machine. For all 32-bit address space machines we have tested this is
the case. On machines with a 64-bit address space, however, this may not be true. In particular, the size
of a Fortran integer on the Silicon Graphics Power Challenge and DEC Alpha (but not the Cray T3D) is
32-bits and is not large enough to hold a machine address. The solution on these machines is to use the
(nonstandard, but supported) Fortran declaration integer*8 for the context variable.
Startup
The MPI standard provides for source code portability. However, the MPI standard does not specify how
an MPI program shall be started or how the number of processes in the computation is specied. These
will vary according to the computer being used and the choice of MPI implementation. The notes below are
from our experiences testing PGAPack on dierent machines.
Silicon Graphics Challenge
The Silicon Graphics Challenge is a 32-bit symmetric multiprocessor. We used MPICH with the ch shmem
device and the ncc C compiler. Several warnings were received
warning(3262): parameter "ctx" declared and never referenced
warning(3141): cast between pointer-to-object and pointer-to-function
but the library was successfully built. To run a parallel PGAPack program, use either
a.out -np nprocs
68
Silicon Graphics Power Challenge
The Silicon Graphics Power Challenge is similar to the Challenge, except that it has a 64-bit address space.
On this machine the size of an integer (int in C and integer in Fortran) is not the same as the size of an
address. Fortran users should use the declaration integer*8 for the context variable (and integer for other
Fortran integer declarations). See also Chapter 11.
We used MPICH with the ch p4 device and the the MIPSpro C compiler (cc). We found a bug in pca,
the Power C Analyzer, and recommend not using it for now. (To do this do not specify the -pca switch to
cc). To run a parallel PGAPack program, use
a.out -np nprocs
or MPICH's mpirun command.
Cray T3D
The Cray T3D has a 64-bit address space. However, the size of an integer on the T3D is the same as the
size of an address, and therefore no special considerations are needed for declaring the context variable in
Fortran.
On the T3D a C double is 64 bits. The Fortran double precision data type, however, is not supported
(by default). One workaround is to declare all oating-point numbers REAL, as these are 64 bits on the T3D.
The other workaround is to use the compiler switch \-dp".
To compile for a Cray T3D, cross compilation is done on a front-end machine (a Cray C90 in our case).
Set Cray's TARGET environment variable so the compiler, linker, etc., will know which architecture to compile
for.
setenv TARGET cray-t3d
An alternative is to use \-T cray-t3d" with cc and \-C cray-t3d" with cf77. Another alternative is to
explicitly use the cross compilers (/mpp/bin/cc and /mpp/bin/cf77) and linker (/mpp/bin/mppldr).
We used the MPI in /usr/local/mpp/lib/libmpi.a. Adding -lmpi in your link step may also nd the
MPI library. If a successful T3D executable was built, the command \le a.out" should say \MPP absolute."
To run a parallel PGAPack program, use
a.out -npes nprocs
where nprocs is a power of two.
Intel Paragon
We used MPICH with the ch nx device and compiled with cc -nx . To run a parallel PGAPack program, use
a.out -sz nprocs
or MPICH's mpirun command.
IBM SP2
We tested the IBM SP2 using both MPICH with the ch eui device, and IBM's research MPI, MPI-F. We
compiled PGAPack with xlc and linked with mpCC. Execution required setting a number of environment
variables. We were successful with the following, but this may vary with the system software installed on
the SP you are using.
setenv MP_HOSTFILE /sphome/hostfile
setenv MP_PROCS np
setenv MP_EUILIB us
setenv MP_INFOLEVEL 0
setenv MP_HOLD_STDIN YES
setenv MP_PULSE 0
a.out
69
Convex Exemplar
We used MPICH with the ch shmem device. Be sure to compile (the Fortran examples) with fort77, not f77.
Also, you must link with /usr/lib/libU77.a last to satisfy iargc and getarg. This must be done manually
in the prototype makeles ./examples/fortran/Makefile.in and ./examples/mgh/Makefile.in before
running configure. To run a parallel PGAPack program using MPICH use the mpirun command.
Sun SparcStation
We used MPICH with the ch p4 device and the GNU C compiler gcc. The instverf test program was run
using 4 processes with:
/usr/local/mpi/bin/mpirun instverf -arch sun4 -np 4
70
Appendix E
Common Problems
When reading input value to be used as parameters in PGASet calls, the PGAset calls themselves may
not be executed until after PGACreate has been called.
In C, when reading input parameters which are of type double, the scanf conversion specication
should be of the form %lf, not %f which is appropriate for floats.
An innite loop can occur if the number of permutations of the bit string is less than the population
size. For example, for a binary-valued string of length four, there are 24 = 16 possibilities. If the
population size is greater than 16, and duplicate strings are not allowed in the population, an innite
loop will occur.
Erroneous results can occur if the name of a user's function conicts with a library function used by
PGAPack. For example, if a program dened its own ceil function, this would conict with the C
math library function of the same name.
All oating point constants and variables used in PGAPack are of type double. Particularly from
Fortran, the user should be careful to make sure that they pass a double precision constant or
variable.
PGACreate removes command line arguments. One consequence is that if PGACreate is called twice in
the same program (unusual, but legal), the second PGACreate call will not receive the command-line
arguments.
If one includes mpi.h (or mpif.h) when it should not be, errors will result, as well as warnings about
redening macros and typedefs. This usually happens when a sequential version of PGAPack is used
(with \fake" MPI stub routines and denitions) and the user's program explicitly includes \real" mpi.h
or mpif.h header les.
If one fails to include mpi.h (or mpif.h) when it should be (such as calling MPI functions directly)
errors may result. Since pgapack.h includes mpi.h this should not happen in C. The Fortran include
le, pgapackf.h, however, does not include mpif.h. The user must explicitly include it in every
subroutine and function that makes MPI calls. Not including mpif.h could result in any of several
dierent errors, including
{ syntax errors when compiling (for example, MPI COMM WORLD being undened)
{ general errors in the computed results
{ the program crashing when it calls the undened subroutine MPI Init
{ general MPI errors such as:
0 - Error in MPI_COMM_RANK : Invalid communicator
0] Aborting program!
71
We have also seen the following error from not including bmpif.h in the main program:
PGACreate: Invalid value of datatype: 0
PGAError: Fatal
If the ch p4 device in MPICH is used to run on workstations one must have a correct processor group
le (procgroup). The error message
(ptera-36%)a.out
p0_18429: p4_error: open error on procgroup file (procgroup): 0
(ptera-37%)
may occur if the processor group le is not specied correctly. See the MPICH users guide for more
details.
A common error with the procgroup le when using the ch p4 device in MPICH is to have an incorrect
path to the executable.
When compiling the examples directory we have seen \multiply dened" error messages. For example:
Making C examples
Compiling classic
ld: /usr/local/mpi/lib/sun4/ch_p4/libmpi.a(initialize.o): _MPI_Initialized: multiply defined
collect2: ld returned 2 exit status
We have seen this error occur when a sequential version of PGAPack was built and the library
(./lib/arch/libpgag.a or ./lib/arch/libpgaO.a) was not deleted before attempting to build a
new, parallel version of PGAPack. The \fake" MPI stub routines are in the sequential library and
have name conicts when a \real" MPI library is referenced. The solution is to delete the old .a le
and rerun make install.
72
Bibliography
1] MPICH World Wide Web home page. Available
by anonymous ftp from ftp.mcs.anl.gov in directory pub/mpi, le mpich.tar.Z, or on the World
Wide Web at http://www.mcs.anl.gov/home/lusk/mpich/index.html, June 1995.
2] J. Baker. Reducing bias and ineciency in the selection algorithm. In J. Grefenstette, editor, Proceedings
of the Second International Conference on Genetic Algorithms and Their Applications, pages 14{21,
Hillsdale, New Jersey, 1987. Lawrence Erlbaum Associates.
3] L. Davis. Handbook of Genetic Algorithms. Van Nostrand Reinhold, New York, 1991.
4] M. Flynn. Some computer organizations and their eectiveness. IEEE Transactions on Computers,
21:948{960, 1972.
5] Message Passing Interface Forum. MPI: A message-passing interface standard. International Journal
of Supercomputing Applications, 8(3/4), 1994.
6] W. Gropp, E. Lusk, and A. Skjellum. USING MPI Portable Parallel Programming with the Message-
Passing Interface. The MIT Press, Cambridge, 1994.
7] J. Holland. Adaption in Natural and Articial Systems. MIT Press, Cambridge, 1992.
8] W. Spears and K. DeJong. On the virtues of parameterized uniform crossover. In R. Belew and
L. Booker, editors, Proceedings of the Fourth International Conference on Genetic Algorithms, pages
230{236, San Mateo, 1991. Morgan Kaufmann.
9] G. Syswerda. Uniform crossover in genetic algorithms. In J. Schaer, editor, Proceedings of the Third
International Conference on Genetic Algorithms, pages 2{9, San Mateo, 1989. Morgan Kaufmann.
10] D. Whitley. The GENITOR algorithm and selection pressure: Why rank-based allocation of reproduc-
tive trials is best. In J. Schaer, editor, Proceedings of the Third International Conference on Genetic
Algorithms, pages 116{121, San Mateo, 1989. Morgan Kaufmann.
11] D. Whitley and J. Kauth. GENITOR: A dierent genetic algorithm. In Rocky Mountain Conference
on Articial Intelligence, pages 118{130, Denver, 1988.
73