/* * GENESIS Copyright (c) 1986, 1990 by John J. Grefenstette * This program may be freely copied for educational * and research purposes. All other rights reserved. * * file: init.c * * purpose: create an initial population of structures, * and initalize some performance variables. * This is called at the start of each experiment. * * modified: 7 feb 86 * 12 nov 66: pass Length to Pack() * 23 sep 90: handle floating point representation in initfile */ #include "extern.h" Initialize() { FILE *fp, *fopen(); register int i, j; /* loop control */ int status; /* indicates end of file in initfile */ Trace("Initialize entered"); Dtrace("initialize"); if (Totalexperiments > 1) sprintf(Bestfile, "%s.%d", Minfile, Experiment+1); /* prepare for new experiment */ Doneflag = 0; Curr_dump = 0; Bestsize = 0; /* set next mutation location */ if (M_rate < 1.0) Mu_next = ceil (log(Rand()) / log(1.0 - M_rate)); else Mu_next = 1; Trials = Gen = 0; Lost = Conv = 0; Plateau = 0; Spin = 0; Onsum = Offsum = 0.0; for (i=0; i 0 ) Seed = Initseed; for (; i < Popsize; i++) /* initialize remainder randomly */ { for (j = 0; j < Length; j++) { if (Randint(0,1)) Bitstring[j] = '1'; else Bitstring[j] = '0'; } Pack(Bitstring , New[i].Gene , Length); New[i].Needs_evaluation = 1; } Initseed = Seed; Trace("Initialize completed"); } /** end of file **/