📄 genal_pop.shell
字号:
# This is a shell script to operate a global search on the basis# of genetic algorithms# Operates on an HP under POSIX (NOT csh)#PATH=$PATH:/usr/local/phasing/Genetic/LBL/bin:/usr/local/phasing/binexport PATHrm genetic.log fitfile elite solutionstouch genetic.logecho >> genetic.logecho " -----------------------------------------------" >> genetic.logecho " GENETIC ALGORITHMS" >> genetic.logecho " Authors: R. Doell, LBL" >> genetic.logecho " E. Landree, C. Collazo, L. D. Marks, NU" >> genetic.logecho " Acta Crystallographica B 53, 916-922 (1997)" >> genetic.logecho " Version 4.0 creation date: 07/08/98" >> genetic.logecho " -----------------------------------------------" >> genetic.logecho >> genetic.logecho " -------------------------------------------------------" >> genetic.logecho " generate random starting population ....." >> genetic.logecho " generate random starting population ....." echo " -------------------------------------------------------" >> genetic.log# execute program 'sconf2.exe' with input file 'control'.# the output file 'population' contains the starting population coded as# 1's and 0's. output file 'bithelp' contains the number of bits to describe# one chromosome. This uses the number of children to start.sconf2.exe# cp prot PROTread word1 word2 < errorif [ $word1 = error ] then echo " genal.shell aborted due to error in 'sconf.exe'" exitfirm errorecho " ..... and calculate fitness for every chromosome" >> genetic.logecho " -------------------------------------------------------" >> genetic.logecho >> genetic.log# translate digital code of population back to 'real' parameters# execute program 'transl.exe' with input 'control' and 'population'# and output 'popw'transl2.exe# get number of parameters from file 'control' grep nparam control > temp read nparam rest < temp rm temp# get number of chromosomes from file 'control' grep nindiv control > temp read nindiv rest < temp rm temp# get number of children from file 'control' grep nchild control > temp read nchild rest < temp rm temp# get tension for cross.f from 'control' grep tension control > temp read tension rest < temp rm temp# =====================================================================# initialize loop over chromosomes# Control file# Number of parameters echo $nparam > sref.control# Number of members for this population echo $nchild >> sref.control# Which population ? echo "0" >> sref.control# Total number of bits read totbits < bithelp echo $totbits >> sref.control# xrefs_pop10 phase.tmpl rn.d single.at junk junk2 < phase.cnt > phase.log# =====================================================================# file 'fitfile' contains all chromosomes with fitness and binary code# Sort, removing duplicates of a given FOM value sort -u -n -o store fitfile mv store fitfile# count total number of investigated chromosomesncount=$nchild# =====================================================================# initialize loop over populations# get number of new children from file 'control' grep nchild control > temp read nchild rest < temp rm temp# get maximum number of populations from file 'control' grep npop control > temp read npop rest < temp rm temp# get number of surviving parents from file 'control' grep nsurv control > temp read nsurv rest < temp rm temp echo $nsurv >> keep.control# make sure nindiv is set to correct value (Chris -- March 24) grep nindiv control > temp read nindiv rest < temp rm temp # initialize solutions and elite files (Chris -- April 10) cp fitfile solutions# touch elite - NO popc=1# echo $popc# calculate average fitness of present population# input files: 'helpfile', 'fitfile'# output file containing value of average fitness: 'helpfile2'while [ "$popc" -lt "$npop" ]do echo $nparam > helpfile echo $nindiv >> helpfile avfit.exe head -1 fitfile > temp read bf rest < temp rm temp echo " --> highest fitness: \c" >> genetic.log echo $bf >> genetic.log echo " --> average fitness of population $popc :\c" >> genetic.log read var1 var2 < helpfile2 echo $var1 >> genetic.log echo " number of chromosomes investigated up to now: $ncount" >> genetic.log echo >> genetic.log echo " --> average fitness of population $popc :\c" echo $var1 stat >> genetic.logecho >> genetic.logecho " ---------------------------------------------------------" >> genetic.logecho " perform crossover and mutation in population $popc ....." >> genetic.logecho " ---------------------------------------------------------" >> genetic.log# crossover: input files: 'bithelp', 'control' and 'fitfile'# output file: 'lpop' (containing new large population) echo $nindiv >> bithelp grep idum control >> bithelp cross.exe $tension# mutation: input files 'bithelp', 'control' and 'lpop'# output: 'mpop' (containing mutated population) mutate.exeecho " ..... and calculate fitness for every child of it" >> genetic.logecho " ---------------------------------------------------------" >> genetic.log# translate digital code of child population back to 'real' parameters# execute program 'ltransl.exe' with input 'control' and 'mpop'# increase counter for total number of investigated chromosomesncount=`expr $ncount + $nchild`# ===================================================================== mv mpop population # translate mutated children to real parameters to go into the file popw# Chris -- March 24rm popwtransl.exe# initialize loop over chromosomes # get number of parameters from file 'control'# To make sure nparam is set correctly (Chris -- March 24) grep nparam control > temp read nparam rest < temp rm temp # let nsurv chromosomes with best fitness 'survive'# cat elite > fitfileif [ -r elite ]thencat elite > fitfilefi# =====================================================================# initialize loop over chromosomes# Control file# Number of parameters echo $nparam > sref.control# Number of members for this population echo $nchild >> sref.control# Which population ? echo $popc >> sref.control# Total number of bits read totbits < bithelp echo $totbits >> sref.control# xrefs_pop10 phase.tmpl rn.d single.at junk junk2 < phase.cnt > phase.log# =====================================================================# create new 'fitfile' from which next parents are chosengrep nindiv control > temp ; read nindiv rest < temp ; rm temp# CHANGED# sort -u -n -o store fitfile# Sort, removing duplicates of a given FOM value sort -u -n -o store fitfile head -$nindiv store > fitfile # update solutions and elite files (Chris -- April 10)# CHANGED# sort -o solutions.tmp -n fitfile solutions# Sort, removing duplicates of a given FOM value sort -u -o solutions.tmp -n fitfile solutions #instead of Keeper.exe grep nsurv control > temp read nsurv rest < temp rm temp# Changed only for every other cycleif [ -r elite ] then rm elite echo "Note: Removing elite " >> genetic.log else uniq solutions.tmp temp2 head -$nsurv temp2 > elitefi grep nsave keep.control > temp read nsave rest < temp rm temp uniq solutions.tmp temp2 head -$nsave temp2 > solutions rm temp2# rm solutions.tmp # end loop over populations popc=`expr $popc + 1`done# =====================================================================# final output# calculate average fitness of final populationecho $nparam > helpfileecho $nindiv >> helpfileavfit.exeecho >> genetic.loghead -1 fitfile | read bf restecho " --> highest fitness in last population: \c" >> genetic.logecho $bf >> genetic.logecho " --> average fitness of (final) population $fpop :\c" >> genetic.logcat helpfile2 >> genetic.logecho " total number of chromosomes investigated: $ncount" >> genetic.logecho >> genetic.logecho " --> average fitness of (final) population $fpop :\c" cat helpfile2 stat >> genetic.log# delete files not needed any more rm helpfile bithelp fitfile rm store popw helpfile2 rm prot helpfile3 lpop rm population random.hold rm solutions.tmp junk* sref.control elite
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -