home *** CD-ROM | disk | FTP | other *** search
- /* tsetup.c 19-8-91 Artificial Life simulator setup routines */
- /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
-
- #include "license.h"
-
- #ifndef lint
- static char sccsid[] = "@(#)tsetup.c 2.15 10/6/91";
- #endif
-
- #include "tierra.h"
- #include "extern.h"
-
- I8s GetAVar(data)
- I8s data[85];
- {
- if(!strncmp(data,"alive",5))
- { sscanf(data,"alive = %ld", &alive); return 1; }
- if(!strncmp(data,"BrkupSiz",8))
- { sscanf(data,"BrkupSiz = %ld", &BrkupSiz); return 1; }
- if(!strncmp(data,"CellsSize",9))
- { sscanf(data,"CellsSize = %ld", &CellsSize); return 1; }
- if(!strncmp(data,"debug",5))
- { sscanf(data,"debug = %ld", &debug); return 1; }
- if(!strncmp(data,"DiskOut",7))
- { sscanf(data,"DiskOut = %ld", &DiskOut); return 1; }
- if(!strncmp(data,"DistFreq",8))
- { sscanf(data,"DistFreq = %f", &DistFreq); return 1; }
- if(!strncmp(data,"DistProp",8))
- { sscanf(data,"DistProp = %f", &DistProp); return 1; }
- if(!strncmp(data,"DivSameSiz",10))
- { sscanf(data,"DivSameSiz = %ld", &DivSameSiz); return 1; }
- if(!strncmp(data,"DivSameGen",10))
- { sscanf(data,"DivSameGen = %ld", &DivSameGen); return 1; }
- if(!strncmp(data,"DropDead",8))
- { sscanf(data,"DropDead = %ld", &DropDead); return 1; }
- if(!strncmp(data,"GeneBnker",9))
- { sscanf(data,"GeneBnker = %ld", &GeneBnker); return 1; }
- if(!strncmp(data,"GenebankPath",12))
- { sscanf(data,"GenebankPath = %s", GenebankPath); return 1; }
- if(!strncmp(data,"GenPerBkgMut",12))
- { sscanf(data,"GenPerBkgMut = %f", &GenPerBkgMut); return 1; }
- if(!strncmp(data,"GenPerFlaw",10))
- { sscanf(data,"GenPerFlaw = %f", &GenPerFlaw); return 1; }
- if(!strncmp(data,"GenPerMovMut",12))
- { sscanf(data,"GenPerMovMut = %f", &GenPerMovMut); return 1; }
- if(!strncmp(data,"hangup",6))
- { sscanf(data,"hangup = %ld", &hangup); return 1; }
- if(!strncmp(data,"MaxFreeBlocks",13))
- { sscanf(data,"MaxFreeBlocks = %ld", &MaxFreeBlocks); return 1; }
- if(!strncmp(data,"MaxMalMult",10))
- { sscanf(data,"MaxMalMult = %f", &MaxMalMult); return 1; }
- if(!strncmp(data,"MinCellSize",11))
- { sscanf(data,"MinCellSize = %ld", &MinCellSize); return 1; }
- if(!strncmp(data,"MinTemplSize ",12))
- { sscanf(data,"MinTemplSize = %ld", &MinTemplSize); return 1; }
- if(!strncmp(data,"MovPropThrDiv",13))
- { sscanf(data,"MovPropThrDiv = %f", &MovPropThrDiv); return 1; }
- if(!strncmp(data,"new_soup",8))
- { sscanf(data,"new_soup = %ld", &new_soup); return 1; }
- if(!strncmp(data,"NumCells",8))
- { sscanf(data,"NumCells = %ld", &NumCells); return 1; }
- if(!strncmp(data,"OutPath",7))
- { sscanf(data,"OutPath = %s", OutPath); return 1; }
- if(!strncmp(data,"PhotonPow",9))
- { sscanf(data,"PhotonPow = %f", &PhotonPow); return 1; }
- if(!strncmp(data,"PhotonWidth",11))
- { sscanf(data,"PhotonWidth = %ld", &PhotonWidth); return 1; }
- if(!strncmp(data,"PhotonWord",10))
- { sscanf(data,"PhotonWord = %s", PhotonWord); return 1; }
- if(!strncmp(data,"RamBankSiz",10))
- { sscanf(data,"RamBankSiz = %ld", &RamBankSiz); return 1; }
- if(!strncmp(data,"SaveFreq",8))
- { sscanf(data,"SaveFreq = %ld", &SaveFreq); return 1; }
- if(!strncmp(data,"SavThrMem",9))
- { sscanf(data,"SavThrMem = %f", &SavThrMem); return 1; }
- if(!strncmp(data,"SavThrPop",9))
- { sscanf(data,"SavThrPop = %f", &SavThrPop); return 1; }
- if(!strncmp(data,"SearchLimit",11))
- { sscanf(data,"SearchLimit = %f", &SearchLimit); return 1; }
- if(!strncmp(data,"seed",4))
- { sscanf(data,"seed = %ld", &seed); return 1; }
- if(!strncmp(data,"SizDepSlice",11))
- { sscanf(data,"SizDepSlice = %ld", &SizDepSlice); return 1; }
- if(!strncmp(data,"SlicePow",8))
- { sscanf(data,"SlicePow = %lf", &SlicePow); return 1; }
- if(!strncmp(data,"SliceSize",9))
- { sscanf(data,"SliceSize = %ld", &SliceSize); return 1; }
- if(!strncmp(data,"SliceStyle",10))
- { sscanf(data,"SliceStyle = %ld", &SliceStyle); return 1; }
- if(!strncmp(data,"SlicFixFrac",11))
- { sscanf(data,"SlicFixFrac = %f", &SlicFixFrac); return 1; }
- if(!strncmp(data,"SlicRanFrac",11))
- { sscanf(data,"SlicRanFrac = %f", &SlicRanFrac); return 1; }
- if(!strncmp(data,"SoupSize",8))
- { sscanf(data,"SoupSize = %ld", &SoupSize); return 1; }
- if(!strncmp(data,"WatchExe",8))
- { sscanf(data,"WatchExe = %ld", &WatchExe); return 1; }
- if(!strncmp(data,"WatchMov",8))
- { sscanf(data,"WatchMov = %ld", &WatchMov); return 1; }
- if(!strncmp(data,"WatchTem",8))
- { sscanf(data,"WatchTem = %ld", &WatchTem); return 1; }
- return 0;
- }
-
- void GetSoup()
- { FILE *inf;
- I8s data[85];
- I32s i;
-
- sprintf(mes[0],"Using instruction set (INST) = %d",INST);
- FEMessage(1);
-
- #ifdef __TURBOC__
- timezone = (I32s) 5L * 60L * 60L;
- #endif
- inf = fopen(soup_fn,"r");
- if(inf == NULL)
- { sprintf(mes[0],"GetSoup: file %s not opened, exiting", soup_fn);
- if (!hangup)
- FEMessage(1);
- else
- { sprintf(mes[1],"system being saved to disk");
- FEMessage(2);
- }
- while(hangup) ;
- exit(0);
- }
- fgets(data,84,inf); sscanf(data,"tierra core:"); /* file header line */
- fgets(data,84,inf); /* blank line */
- fgets(data,84,inf);
- while(strlen(data) > 3)
- { if(!GetAVar(data))
- { sprintf(mes[0],"bad soup_in line: %s", data);
- FEMessage(1);
- }
- fgets(data,84,inf);
- }
- if(new_soup)
- { GenInList = (I8s **) thcalloc((I32u) NumCells, (I32u) sizeof(I8s *));
- GenInBuf = (I8s *) thcalloc((I32u) NumCells * 13,(I32u) sizeof(I8s));
- for(i = 0; i < NumCells; i++)
- { fgets(data,84,inf);
- GenInList[i] = GenInBuf + (i * 13);
- sscanf(data,"%s", GenInList[i]);
- }
- }
- FEStartup(); /* still a dummy function */
-
- /* allocate arrays */
- if(NumCells > CellsSize - 2) CellsSize = NumCells + 22L;
- sprintf(mes[0],"sizeof(Instruction) = %ld", (I32s) sizeof(Instruction));
- sprintf(mes[1],"sizeof(struct cell) = %ld", (I32s) sizeof(struct cell));
- sprintf(mes[2],"sizeof(struct mem_fr) = %ld",(I32s)sizeof(struct mem_fr));
- FEMessage(3);
- #ifdef __TURBOC__
- sprintf(mes[0],"coreleft = %lu", (I32u) coreleft());
- FEMessage(1);
- #endif
- soup = (HpInst) thcalloc((I32u ) SoupSize, (I32u) sizeof(Instruction));
- sprintf(mes[0]," %ld bytes allocated for soup",
- SoupSize * sizeof(Instruction));
- cells = (Pcells) thcalloc((I32u ) CellsSize, (I32u) sizeof(struct cell));
- sprintf(mes[1]," %ld bytes allocated for cells",
- CellsSize * sizeof(struct cell));
- FreeMem = (struct mem_fr Hp)
- thcalloc((I32u ) MaxFreeBlocks, (I32u) sizeof(struct mem_fr));
- sprintf(mes[2]," %ld bytes allocated for mem_fr",
- MaxFreeBlocks * sizeof(struct mem_fr));
- FEMessage(3);
- #ifdef __TURBOC__
- sprintf(mes[0],"coreleft = %lu tsetup (soup, cells, FreeMem)",
- (I32u) coreleft());
- FEMessage(1);
- #endif
- if(!soup || !cells || !FreeMem)
- { sprintf(mes[0],"Tierra setup malloc error, exiting");
- if (!hangup)
- FEMessage(1);
- else
- { sprintf(mes[1],"system being saved to disk");
- FEMessage(2);
- }
- while(hangup) ;
- exit(0);
- }
- else
- { sprintf(mes[0],"tsetup: arrays allocated without error");
- FEMessage(1);
- }
- #ifdef unix
- SLASH = 47;
- #endif
- #if __TURBOC__ || OS2_MC
- SLASH = 92;
- #endif
- TotFlaw = TotMovMut = TotMut = extr = isolate = fragment = 0;
- Disturb.m = Disturb.i = DistNext.m = DistNext.i = 0L;
- if(DivSameGen) DivSameSiz = 1;
- ONE = 1;
- if(GeneBnker) GetGenFileList();
- else WatchExe = WatchMov = WatchTem = 0;
- if(new_soup) GetNewSoup();
- else GetOldSoup(inf);
- if(GeneBnker) StupGenLists();
- sprintf(mes[0],"tsetup: soup gotten");
- FEMessage(1);
- if(SliceStyle == 1)
- { PhotonSize = (I32s) strlen(PhotonWord);
- PhotonTranslate(PhotonInst,PhotonWord);
- slicer = SlicerPhoton;
- }
- else if(SliceStyle == 0) slicer = SlicerQueue;
- else if(SliceStyle == 2) slicer = RanSlicerQueue;
- if(new_soup)
- { thfree(GenInList); thfree(GenInBuf); }
- fclose(inf);
- }
-
- void StupGenLists()
- { I32s i, j, onum, newgen;
- Pcells ce;
- I8s gfile[80];
- FILE *afp;
- head_t head;
- indx_t *indx;
- Pgl tgl, tglt;
- Psl tsl;
- struct gl_index glia, glib;
-
- for(i = 2; i < CellsSize; i++)
- { ce = cells + i;
- if(ce->ld)
- { newgen = 0;
- IsNewSize(i,&ce->d.gli);
- tsl = sl + ce->d.gli.si;
- ce->d.gli.gi = Lbl2Int(ce->d.gen.label);
- if(ce->d.gli.gi >= tsl->a_num)
- { onum = tsl->a_num;
- tsl->a_num = ce->d.gli.gi + 4;
- tsl->g = (Pgl) threalloc((I8s Hp) tsl->g,
- sizeof(struct g_list) * tsl->a_num);
- for(j = onum; j < tsl->a_num; j++)
- InitGList(tsl->g + j, ce->d.gli.si, j, tsl->size);
- }
- tgl = tsl->g + ce->d.gli.gi;
- if(strcmp(ce->d.gen.label,tgl->gen.label) || tgl->genome == NULL)
- /* if new genotype */
- { /* read genotype from disk and put in rambank at tgl */
- if(strcmp(ce->d.gen.label,tgl->gen.label))
- { tsl->num++; newgen = 1; }
- if (IsBit(tgl->bits,0))
- #ifdef IBM3090
- sprintf(gfile,"%04ld.gen.d", tsl->size);
- else
- sprintf(gfile,"%04ld.tmp.d", tsl->size);
- #else
- sprintf(gfile,"%s%04ld.gen", GenebankPath, tsl->size);
- else
- sprintf(gfile,"%s%04ld.tmp", GenebankPath, tsl->size);
- #endif
- if (!(afp = fopen(gfile,"rb")))
- { fprintf(stderr,"file %s not opened\n", gfile);
- exit(9);
- }
- head = read_head(afp);
- if(strncmp(head.magic,"tie",3) || head.magic[3] - '0' != INST)
- { fprintf(stderr,"IsInGenBank: bad magic number");
- exit(10);
- }
- indx = read_indx(afp,&head);
- if ((j = find_gen(indx,ce->d.gen.label,head.n)) == head.n)
- fprintf(stderr,"%s not in archive\n", ce->d.gen.label);
- else
- { glia = tgl->a; glib = tgl->b;
- tglt = get_gen(afp, &head, &indx[j], j);
- *tgl = *tglt;
- thfree(tglt);
- tgl->a = glia; tgl->b = glib;
- }
- if(newgen)
- AddTopGenQueue(&ce->d.gli);
- thfree(indx);
- fclose(afp);
- }
- tgl->pop++;
- }
- }
- for(i = 0; i < siz_sl; i++)
- { tsl = sl + i;
- for(j = 0; j < tsl->a_num; j++)
- { tgl = tsl->g + j;
- if(!strcmp(tgl->gen.label,"---"))
- Int2Lbl(j,tgl->gen.label);
- }
- }
- }
-
- void GetNewSoup()
- { I32s i, k, ci, cs, spaces = 0;
- Ind l;
- HpInst si;
- Pcells ce;
-
- sprintf(mes[0],"beginning of GetNewSoup");
- FEMessage(1);
- if(!seed) seed = (I32s) time(NULL);
- tsrand(seed);
- sprintf(mes[0],"seed = %ld", seed);
- FEMessage(1);
- reaped = InstExe.i = InstExe.m = ExtractCount = CountMovMut =
- CountMutRate = CountFlaw = RateMovMut = RateMut = RateFlaw = 0L;
- FreeBlocks = FirstOutDisk = 1L;
- Generations = 0.;
- FreeMemCurrent = SoupSize;
- /* initialize soup array */
- for(l = 0; l < SoupSize; l++)
- { for (k = 0; k < PLOIDY; k++)
- { soup[l][k].inst = 0;
- soup[l][k].read = 0;
- soup[l][k].write = 0;
- soup[l][k].exec = 0;
- }
- }
- sprintf(mes[0],"init of soup complete");
- FEMessage(1);
- /* initialize FreeMem array */
- SoupBot = 0; SoupTop = 1;
- FreeMem->p = 0; FreeMem->s = 0;
- FreeMem->n = 2; FreeMem->o = (I8s ) 1;
- (FreeMem + 1)->p = SoupSize; (FreeMem + 1)->s = (I32s) 0;
- (FreeMem + 1)->n = 1; (FreeMem + 1)->o = (I8s ) 1;
- (FreeMem + 2)->p = 0; (FreeMem + 2)->s = SoupSize;
- (FreeMem + 2)->n = 1; (FreeMem + 2)->o = (I8s ) 1;
- for(i = 3; i < MaxFreeBlocks; i++)
- { (FreeMem + i)->p = 0;
- (FreeMem + i)->n = 0;
- (FreeMem + i)->s = 0;
- (FreeMem + i)->o = (I8s ) 0;
- }
- /* initialize cells array */
- for(i = 0; i < CellsSize; i++) InitCell(i);
- cells->ld = (cells + 1)->ld = 1;
- si = soup; ce = cells + 2; ci = 2;
- ThisSlice = BottomReap = TopReap = 2;
-
- /* read in the cell genotypes */
- for (i = 0; i < NumCells; i++)
- { if (!strncmp("space", GenInList[i], 5))
- { sscanf(GenInList[i], "%*s%ld", &cs);
- sprintf(mes[0],"skipping %ld instructions", cs);
- FEMessage(1);
- spaces++;
- }
- else
- { sscanf(GenInList[i], "%4ld", &cs);
- sprintf(mes[0],
- "GetNewSoup: about to read %ld instructions of cell %ld",cs,i);
- FEMessage(1);
- ReadACreature(GenInList[i], ce, ci, si);
- ce++; ci++;
- }
- si += cs;
- }
- NumCells -= spaces;
- plan();
- }
-
- void ReadACreature(crit, ce, ci, si)
- I8s *crit;
- I32s ci;
- Pcells ce;
- HpInst si;
- {
- I32s cs, j, k;
- Pgl g;
- char cpath[256], gen[4];
- FILE *fp;
- head_t head;
- indx_t *indx;
- short n;
-
- sscanf(crit, "%4ld%3s", &cs, gen);
- sprintf(cpath, "%s%04ld.gen", GenebankPath, cs);
- if (!(fp = open_ar(cpath, cs, INST, 0)))
- { perror("ReadACreature");
- exit(7);
- }
- head = read_head(fp);
- indx = read_indx(fp, &head);
- n = find_gen(indx, gen, head.n);
- g = get_gen(fp, &head, &indx[n], n);
- fclose(fp);
- thfree(indx);
- ce->c.ip = ce->mm.p = MemAlloc(&cs);
- ce->d.gen.size = ce->mm.s = cs;
- ce->d.gen = g->gen;
- ce->d.parent = g->parent;
- ce->ld = 1;
- if (ci == 2)
- { ce->q.p_reap = 0;
- ce->q.n_reap = 1;
- cells->q.n_reap = 2;
- (cells + 1)->q.p_reap = 2;
- }
- else {
- EntBotSlicer(ci);
- EntBotReaper(ci);
- }
- OutDisk('b',ce);
- for (j = 0; j < cs; j++)
- { for (k = 0; k < PLOIDY; k++)
- { si[0][k] = g->genome[j][k];
- }
- si++;
- }
- if(g->comments) thfree(g->comments);
- if(g->genome) thfree(g->genome);
- thfree(g);
- }
-
- void GetOldSoup(inf)
- FILE *inf;
- {
- I8s data[85];
- FILE *inc;
-
- fgets(data,84,inf); sscanf(data,"AverageSize = %ld", &AverageSize);
- fgets(data,84,inf); sscanf(data,"BottomReap = %ld", &BottomReap);
- fgets(data,84,inf); sscanf(data,"BrkupCou = %ld", &BrkupCou);
- fgets(data,84,inf); sscanf(data,"BrkupCum = %ld", &BrkupCum);
- fgets(data,84,inf); sscanf(data,"comsoc = %ld", &comsoc);
- fgets(data,84,inf); sscanf(data,"CountFlaw = %ld", &CountFlaw);
- fgets(data,84,inf); sscanf(data,"CountMovMut = %ld", &CountMovMut);
- fgets(data,84,inf); sscanf(data,"CountMutRate = %ld", &CountMutRate);
- fgets(data,84,inf); sscanf(data,"debug_switch = %ld", &debug_switch);
- fgets(data,84,inf); sscanf(data,"DistNext.m = %ld\n", &DistNext.m);
- fgets(data,84,inf); sscanf(data,"DistNext.i = %ld\n", &DistNext.i);
- fgets(data,84,inf); sscanf(data,"Disturb.m = %ld\n", &Disturb.m);
- fgets(data,84,inf); sscanf(data,"Disturb.i = %ld\n", &Disturb.i);
- fgets(data,84,inf); sscanf(data,"extr = %ld", &extr);
- fgets(data,84,inf); sscanf(data,"ExtractCount = %ld", &ExtractCount);
- fgets(data,84,inf); sscanf(data,"FirstOutDisk = %ld", &FirstOutDisk);
- fgets(data,84,inf); sscanf(data,"fragment = %ld", &fragment);
- fgets(data,84,inf); sscanf(data,"FreeBlocks = %ld", &FreeBlocks);
- fgets(data,84,inf); sscanf(data,"FreeMemCurrent = %ld",&FreeMemCurrent);
- fgets(data,84,inf); sscanf(data,"Generations = %lf",&Generations);
- fgets(data,84,inf); sscanf(data,"InstExe.i = %ld", &InstExe.i);
- fgets(data,84,inf); sscanf(data,"InstExe.m = %ld", &InstExe.m);
- fgets(data,84,inf); sscanf(data,"isolate = %ld", &isolate);
- fgets(data,84,inf); sscanf(data,"LastDiv.i = %ld", &LastDiv.i);
- fgets(data,84,inf); sscanf(data,"LastDiv.m = %ld", &LastDiv.m);
- fgets(data,84,inf); sscanf(data,"RandIx1 = %ld", &RandIx1);
- fgets(data,84,inf); sscanf(data,"RandIx2 = %ld", &RandIx2);
- fgets(data,84,inf); sscanf(data,"RandIx3 = %ld", &RandIx3);
- fgets(data,84,inf); sscanf(data,"RateFlaw = %ld", &RateFlaw);
- fgets(data,84,inf); sscanf(data,"RateMovMut = %ld", &RateMovMut);
- fgets(data,84,inf); sscanf(data,"RateMut = %ld", &RateMut);
- fgets(data,84,inf); sscanf(data,"reaped = %ld", &reaped);
- fgets(data,84,inf); sscanf(data,"runflag = %ld", &runflag);
- fgets(data,84,inf); sscanf(data,"Search_limit = %ld", &Search_limit);
- fgets(data,84,inf); sscanf(data,"SoupBot = %ld", &SoupBot);
- fgets(data,84,inf); sscanf(data,"SoupTop = %ld", &SoupTop);
- fgets(data,84,inf); sscanf(data,"ThisSlice = %ld", &ThisSlice);
- fgets(data,84,inf); sscanf(data,"TimeBirth = %ld", &TimeBirth);
- fgets(data,84,inf); sscanf(data,"TimeDeath = %ld", &TimeDeath);
- fgets(data,84,inf); sscanf(data,"TimePop = %lf", &TimePop);
- fgets(data,84,inf); sscanf(data,"TopReap = %ld", &TopReap);
- fgets(data,84,inf); sscanf(data,"TotFlaw = %ld", &TotFlaw);
- fgets(data,84,inf); sscanf(data,"TotMovMut = %ld", &TotMovMut);
- fgets(data,84,inf); sscanf(data,"TotMut = %ld", &TotMut);
- #ifdef IBM3090
- strcpy(data,"core_out.io.d");
- #else
- strcpy(data,"core_out");
- #endif
- inc = fopen(data,"rb");
- if (inc == NULL)
- { sprintf(mes[0],"GetOldSoup 1: file %s not opened, exiting", data);
- if (!hangup)
- FEMessage(1);
- else
- { sprintf(mes[1],"system being saved to disk");
- FEMessage(2);
- }
- while(hangup) ;
- exit(0);
- }
- if (DiskOut) fread(&lo, sizeof(struct LastOut), 1, inc);
- fread(&is, sizeof(struct inst), 1, inc);
- fread(TrandArray, sizeof(double), 98, inc);
- tfread((I8s Hp)FreeMem,(I32s)sizeof(struct mem_fr),MaxFreeBlocks,inc);
- tfread((I8s Hp) soup, (I32s) sizeof(Instruction), SoupSize, inc);
- tfread((I8s Hp) cells, (I32s) sizeof(struct cell), CellsSize, inc);
- fclose(inc);
- if (DiskOut) {
- #ifdef IBM3090
- if(BrkupSiz) sprintf(data,"break.%ld.d", BrkupCou);
- else sprintf(data,"tierra.run");
- #else
- if(BrkupSiz) sprintf(data,"%sbreak.%ld", OutPath, BrkupCou);
- else sprintf(data,"%stierra.run", OutPath);
- #endif
- oufr = fopen(data,"a");
- if(oufr == NULL)
- { sprintf(mes[0],"GetOldSoup 2: file %s not opened, exiting");
- if (!hangup)
- FEMessage(1);
- else
- { sprintf(mes[1],"system being saved to disk");
- FEMessage(2);
- }
- while(hangup) ;
- exit(0);
- }
- }
- }
-
- void WriteSoup(close_disk)
- I8s close_disk;
- {
- FILE *ouf;
- I32s i, j, TNumGen = 0, TNumSiz = 0;
- long int tp;
- I8s comd[120], path[99], tpath[99];
- Psl tsl;
- Pgl tgl;
- struct SizList *tgi;
-
- FILE *fp, *tf;
- head_t head, thead;
- indx_t *indx, *tindx;
-
- if (DiskOut && close_disk) fclose(oufr);
- if (GeneBnker) {
- tgi = (struct SizList *) thcalloc(NumSizl, sizeof(struct SizList));
- for (i=0; i < NumSizl; i++) { /* make list of sizes, record their */
- tsl = sl + i; /* position in the size list. */
- (tgi + i)->size = tsl->size;
- (tgi + i)->pos = i; /* records the position in the size list */
- if (tsl->num_s) (tgi + i)->dir = 1;
- for (j = 0; j < tsl->a_num; j++) {
- tgl = tsl->g + j;
- if (tgl->pop || IsBit(tgl->bits,0)) (tgi + i)->ext++;
- }
- if ((tgi + i)->ext) TNumSiz++;
- TNumGen += (tgi + i)->ext;
- } /* then sort the list by size */
- qsort((void *) tgi, NumSizl, sizeof(struct SizList), slcmp);
-
- for (i = 0; i < NumSizl; i++) {
- tsl = sl + (tgi + i)->pos; /* position in sl of the ith size */
- if ((tgi + i)->ext) {
- sprintf(path,"%s%04ld.gen", GenebankPath, tsl->size);
- sprintf(tpath,"%s%04ld.tmp", GenebankPath, tsl->size);
- fp = open_ar(path, tsl->size, INST, !(tgi + i)->dir);
- tf = open_ar(tpath, tsl->size, INST, 1);
- head = read_head(fp);
- thead = read_head(tf);
- indx = read_indx(fp, &head);
- tindx = read_indx(tf, &thead);
- for (j=0; j<tsl->a_num; j++) {
- /* for each genotype of this size */
- tgl = tsl->g + j;
- if (IsBit(tgl->bits,0) || tgl->pop) {
- /* if this genotype has been saved to disk */
- /* or has a residual population */
- SetBit(&tgl->bits, 1, 1);
- if (IsBit(tgl->bits,0))
- add_gen(fp, &head, &indx, tgl);
- else add_gen(tf, &thead, &tindx, tgl);
- }
- }
- fclose(fp);
- fclose(tf);
- if (!head.n) unlink(path);
- if (!thead.n) unlink(tpath);
- thfree(indx);
- thfree(tindx);
- }
- }
- thfree(tgi);
- }
- new_soup = 0;
- if(alive <= InstExe.m) alive = InstExe.m + 5;
- #ifdef IBM3090
- sprintf(comd,"soup_out.io.d");
- #else
- sprintf(comd,"soup_out");
- #endif
- ouf = fopen(comd,"w");
- if(ouf == NULL)
- { sprintf(mes[0],"WriteSoup 2: file %s not opened, exiting", comd);
- if (!hangup)
- FEMessage(1);
- else
- { sprintf(mes[1],"system being saved to disk");
- FEMessage(2);
- }
- while(hangup) ;
- exit(0);
- }
- fprintf(ouf,"tierra core: %s\n", ctime(&tp));
- fprintf(ouf,"alive = %ld\n", alive);
- fprintf(ouf,"BrkupSiz = %ld\n", BrkupSiz);
- fprintf(ouf,"CellsSize = %ld\n", CellsSize);
- fprintf(ouf,"debug = %ld\n", debug);
- fprintf(ouf,"DiskOut = %ld\n", DiskOut);
- fprintf(ouf,"DistFreq = %f\n", DistFreq);
- fprintf(ouf,"DistProp = %f\n", DistProp);
- fprintf(ouf,"DivSameSiz = %ld\n", DivSameSiz);
- fprintf(ouf,"DivSameGen = %ld\n", DivSameGen);
- fprintf(ouf,"DropDead = %ld\n", DropDead);
- fprintf(ouf,"GeneBnker = %ld\n", GeneBnker);
- fprintf(ouf,"GenebankPath = %s\n", GenebankPath);
- fprintf(ouf,"GenPerBkgMut = %f\n", GenPerBkgMut);
- fprintf(ouf,"GenPerFlaw = %f\n", GenPerFlaw);
- fprintf(ouf,"GenPerMovMut = %f\n", GenPerMovMut);
- fprintf(ouf,"hangup = %ld\n", hangup);
- fprintf(ouf,"MaxFreeBlocks = %ld\n", MaxFreeBlocks);
- fprintf(ouf,"MaxMalMult = %g\n", MaxMalMult);
- fprintf(ouf,"MinCellSize = %ld\n", MinCellSize);
- fprintf(ouf,"MinTemplSize = %ld\n", MinTemplSize);
- fprintf(ouf,"MovPropThrDiv = %g\n", MovPropThrDiv);
- fprintf(ouf,"new_soup = %ld\n", new_soup);
- fprintf(ouf,"NumCells = %ld\n", NumCells);
- fprintf(ouf,"OutPath = %s\n", OutPath);
- fprintf(ouf,"PhotonPow = %g\n", PhotonPow);
- fprintf(ouf,"PhotonWidth = %ld\n", PhotonWidth);
- fprintf(ouf,"PhotonWord = %s\n", PhotonWord);
- fprintf(ouf,"RamBankSiz = %ld\n", RamBankSiz);
- fprintf(ouf,"SaveFreq = %ld\n", SaveFreq);
- fprintf(ouf,"SavThrMem = %g\n", SavThrMem);
- fprintf(ouf,"SavThrPop = %g\n", SavThrPop);
- fprintf(ouf,"SearchLimit = %g\n", SearchLimit);
- fprintf(ouf,"seed = %ld\n", seed);
- fprintf(ouf,"SizDepSlice = %ld\n", SizDepSlice);
- fprintf(ouf,"SlicePow = %g\n", SlicePow);
- fprintf(ouf,"SliceSize = %ld\n", SliceSize);
- fprintf(ouf,"SliceStyle = %ld\n", SliceStyle);
- fprintf(ouf,"SlicFixFrac = %g\n", SlicFixFrac);
- fprintf(ouf,"SlicRanFrac = %g\n", SlicRanFrac);
- fprintf(ouf,"SoupSize = %ld\n", SoupSize);
- fprintf(ouf,"WatchExe = %ld\n", WatchExe);
- fprintf(ouf,"WatchMov = %ld\n", WatchMov);
- fprintf(ouf,"WatchTem = %ld\n", WatchTem);
- fprintf(ouf,"\n");
- /* end soup_in variables */
- fprintf(ouf,"AverageSize = %ld\n", AverageSize);
- fprintf(ouf,"BottomReap = %ld\n", BottomReap);
- fprintf(ouf,"BrkupCou = %ld\n", BrkupCou);
- fprintf(ouf,"BrkupCum = %ld\n", BrkupCum);
- fprintf(ouf,"comsoc = %ld\n", comsoc);
- fprintf(ouf,"CountFlaw = %ld\n", CountFlaw);
- fprintf(ouf,"CountMovMut = %ld\n", CountMovMut);
- fprintf(ouf,"CountMutRate = %ld\n", CountMutRate);
- fprintf(ouf,"debug_switch = %ld\n", debug_switch);
- fprintf(ouf,"DistNext.m = %ld\n", DistNext.m);
- fprintf(ouf,"DistNext.i = %ld\n", DistNext.i);
- fprintf(ouf,"Disturb.m = %ld\n", Disturb.m);
- fprintf(ouf,"Disturb.i = %ld\n", Disturb.i);
- fprintf(ouf,"extr = %ld\n", extr);
- fprintf(ouf,"ExtractCount = %ld\n", ExtractCount);
- fprintf(ouf,"FirstOutDisk = %ld\n", FirstOutDisk);
- fprintf(ouf,"fragment = %ld\n", fragment);
- fprintf(ouf,"FreeBlocks = %ld\n", FreeBlocks);
- fprintf(ouf,"FreeMemCurrent = %ld\n", FreeMemCurrent);
- fprintf(ouf,"Generations = %lf\n", Generations);
- fprintf(ouf,"InstExe.i = %ld\n", InstExe.i);
- fprintf(ouf,"InstExe.m = %ld\n", InstExe.m);
- fprintf(ouf,"isolate = %ld\n", isolate);
- fprintf(ouf,"LastDiv.i = %ld\n", LastDiv.i);
- fprintf(ouf,"LastDiv.m = %ld\n", LastDiv.m);
- fprintf(ouf,"RandIx1 = %ld\n", RandIx1);
- fprintf(ouf,"RandIx2 = %ld\n", RandIx2);
- fprintf(ouf,"RandIx3 = %ld\n", RandIx3);
- fprintf(ouf,"RateFlaw = %ld\n", RateFlaw);
- fprintf(ouf,"RateMovMut = %ld\n", RateMovMut);
- fprintf(ouf,"RateMut = %ld\n", RateMut);
- fprintf(ouf,"reaped = %ld\n", reaped);
- fprintf(ouf,"runflag = %ld\n", runflag);
- fprintf(ouf,"Search_limit = %ld\n", Search_limit);
- fprintf(ouf,"SoupBot = %ld\n", SoupBot);
- fprintf(ouf,"SoupTop = %ld\n", SoupTop);
- fprintf(ouf,"ThisSlice = %ld\n", ThisSlice);
- fprintf(ouf,"TimeBirth = %ld\n", TimeBirth);
- fprintf(ouf,"TimeDeath = %ld\n", TimeDeath);
- fprintf(ouf,"TimePop = %lf\n", TimePop);
- fprintf(ouf,"TopReap = %ld\n", TopReap);
- fprintf(ouf,"TotFlaw = %ld\n", TotFlaw);
- fprintf(ouf,"TotMovMut = %ld\n", TotMovMut);
- fprintf(ouf,"TotMut = %ld\n", TotMut);
- fclose(ouf);
- #ifdef IBM3090
- strcpy(comd,"core_out.io.d");
- #else
- strcpy(comd,"core_out");
- #endif
- ouf = fopen(comd,"wb");
- if (ouf == NULL)
- { sprintf(mes[0],"WriteSoup 3: file %s not opened, exiting", comd);
- if (!hangup)
- FEMessage(1);
- else
- { sprintf(mes[1],"system being saved to disk");
- FEMessage(2);
- }
- while(hangup) ;
- exit(0);
- }
- if (DiskOut) fwrite(&lo, sizeof(struct LastOut), 1, ouf);
- fwrite(&is, sizeof(struct inst), 1, ouf);
- fwrite(TrandArray, sizeof(double), 98, ouf);
- tfwrite((I8s Hp) FreeMem, (I32s) sizeof(struct mem_fr),
- MaxFreeBlocks, ouf);
- tfwrite((I8s Hp) soup, (I32s) sizeof(Instruction), SoupSize, ouf);
- tfwrite((I8s Hp) cells, (I32s) sizeof(struct cell), CellsSize, ouf);
- fclose(ouf);
- }
-
- I16s glcmp(gl1, gl2)
- const void *gl1, *gl2;
- { Pgl g1 = gl1, g2 = gl2;
-
- return strcmp(g1->gen.label, g2->gen.label);
- }
-
- I16s slcmp(sl1, sl2)
- const void *sl1, *sl2;
- { struct SizList *s1 = sl1, *s2 = sl2;
-
- if (s1->size == s2->size) return 0;
- if (s1->size < s2->size) return -1;
- if (s1->size > s2->size) return 1;
- return 0;
- }
-
- void InitCell(ci)
- I32s ci;
- {
- I16s i;
- Pcells ce = cells + ci;
-
- ce->d.gen.size = 0L;
- ce->d.gen.label[0] = ce->d.gen.label[1] = ce->d.gen.label[2] = 45;
- ce->d.gen.label[3] = 0; /* "---" */
- ce->d.fecundity = ce->d.flags = ce->d.mov_daught = ce->d.inst =
- ce->d.mut = ce->d.flaw = 0L;
- ce->d.d1.inst = ce->d.d1.flags = ce->d.d1.mov_daught = 0L;
- ce->d.d1.BreedTrue = (I8s) 0;
- ce->d.parent.size = 0L;
- ce->d.parent.label[0] = ce->d.parent.label[1] = ce->d.parent.label[2] =45;
- ce->d.parent.label[3] = 0; /* "---" */
- ce->d.gli.si = ce->d.gli.gi = 0L;
- ce->d.ib = (I16s) 0; /* instruction bank */
- ce->d.ni = (I32s) -1; /* index to daughter cell */
- ce->d.is = (I8s) 0; /* cpu is active */
- ce->d.dm = (I8s) 0; /* daughter or mother */
- ce->d.ploidy = (I8s) 1; /* how many tracks */
- ce->q.n_time=ce->q.p_time=ce->q.n_reap=ce->q.p_reap = ci;
- ce->mm.s = ce->md.s = 0L;
- ce->mm.p = ce->md.p = (Ind) 0;
- for (i = 0; i < NUM_REGS; i++) ce->c.re[i] = 0L;
- ce->c.sp = (I16s) STACK_SIZE - 1;
- for (i = 0; i < STACK_SIZE; i++) ce->c.st[i] = 0L;
- ce->c.ip = (Reg) 0;
- ce->c.fl = ce->c.tr = (I8s) 0;
- ce->ld = (I8s) 0;
- }
-
-