Multimodality Generator for Evolutionary Algorithms
/************************************************************
; *
; William M. Spears *
; Navy Center for Applied Research in AI *
; Naval Research Laboratory *
; *
; The software below is the property of the Department of *
; the Navy. Permission is hereby granted to copy all or *
; any part of the program below for free distribution, *
; however, this header is required on all copies. *
; *
; File: multimodal.c *
; Code to create multimodal problems. *
;************************************************************/
/* This code is for generating multimodal fitness landscapes. Bit
string representations are assumed. The idea is to generate a
set of n random l-bit strings, which represent the locations of
the peaks in the space. The fitness of an arbitrary bit string
(a GA individual) is the number of bits the string has in common
with the nearest peak. This code is written to be used for my
GA code called GAC, but should be simple enough to modify. */
/* If you find any bugs or problems with this generator, please let
me know at wspears arobase cs.uwyo.edu. */
#define MAX_BITS 200 /* The maximum length of individuals */
#define MAX_PEAKS 100 /* The maximum number of peaks */
int length; /* The length of individuals */
int peaks; /* The number of peaks */
int landscape[MAX_PEAKS][MAX_BITS]; /* Holds the location of the peaks */
/* Create n random peaks using bit strings of length l. Call this
before calling the GA. You will need to call srandom() with
some seed value, before calling this function. */
void initialization()
{
int i, j;
for(i = 1; i <= peaks; i++) {
for(j = 1; j <= length; j++) {
landscape[i][j] = random()&01;
}
}
}
/* This is the evaluation function. In GAC individuals are
stored in a 2D array c[][]. This code evaluates the ith
individual c[i][]. */
double myeval (i)
int i;
{
int j, k;
double score, temp;
temp = 0.0;
for (j = 1; j <= peaks; j++) {
score = 0.0;
for (k = 1; k <= length; k++) {
if (c[i][k] == landscape[j][k]) score++;
}
if (score > temp) temp = score;
}
return(temp/(double)length);
}
For more information, please contact
William M. Spears.
Last modified: 07/29/99