## GARANT MACROS: opt - optimization of rasonance assignments ## ## The macro assumes that the expected peaks and coherences were generated and ## the measured peaks were loaded. Two parameters are needed: the size of the ## population to use for the optimization and the name of the macro to be used ## for saving the best assignment found so far. parameter sizePop savemacro var genGap t temp maxscore i j t1 t2 oldavg increment nrParents nrLocIt set increment= 0.5 # increment for optimization schedule set nrParents= 30 # number of assignments to select for recombination; orig = 30 set nrLocIt = 40000 # number of iterations for local optimization; prov. 15000 eval genGap = $sizePop/2 # initialize population of assignments init optimization possibilities $sizePop # determine sets of equivalent peaks determine equivalent peaks print write log /dev/null # generate random intial assignments eval temp = $sizePop - $genGap eval t = $nrLocIt * 2 do i 1 $temp print "Initializing $i(I4)" reset assignment local optimization $t overwrite optimization possibility 2.0 $i $i end do set maxscore = -100000.0 print print print "Iteration Schedule Score Best Avg Mutations" print "================================================================" set i = 0.0 set j = 1 set oldavg = 0.0 do # determine extend of generation eval generation = mod($j-1,$sizePop) / $genGap eval t1 = $generation * $genGap + 1 eval t2 = ($generation + 1) * $genGap if ($t2 .gt. $sizePop) set t2 = $sizePop # score last population if (mod($j,$genGap) .eq. 1) then score population $t1 $t2 end if # temprature schedule if ($i .le. 1.0) then eval temprature = 2.0 else if ($i .le. 2.0) then eval temprature = 1.0 else if ($i .le. 8.0) then eval temprature = 1.0 * (1.0 - ($i - 2.0) / 6.0) else eval temprature = 0.0 end if # select parents select optimization possibilities $nrParents 2.0 $t1 $t2 # perform optimization evolutionary optimization $nrLocIt $temprature # write child eval child = mod($j+$genGap-1,$sizePop) + 1 overwrite optimization possibility 2.0 $child $child # status line print "$j(I4) $i(F8.2) $score(F8.2) $maxscore(F8.2) $avgscore(F8.2) $mutations(F6.2)" # save if best solution if ($score .gt. $maxscore) then $savemacro set maxscore = $score end if # increase loop counters if (mod($j,$genGap) .eq. 0) then if ($avgscore .le. $oldavg) eval i = $i + $increment set oldavg = $avgscore end if eval j = $j + 1 if ($i .gt. 10) break end do close log