Icon representing a recipe

Recipe: Rav3n_pl WalkeR MarathoN

created by StackOverflow

Profile


Name
Rav3n_pl WalkeR MarathoN
ID
49237
Shared with
Public
Parent
None
Children
Created on
May 30, 2014 at 03:41 AM UTC
Updated on
May 30, 2014 at 03:41 AM UTC
Description

A randomatic LWS sequence walker.

Best for


Code


--[[ WalkeR v1.0 a randomatic LWS script set from-to set min-max len of lws ser minimum points per iter optiona at end ]]-- --[[ Tlaloc`s math library ------------------------------------------------------------------------ The original random script this was ported from has the following notices: Copyright (c) 2007 Richard L. Mueller Hilltop Lab web site - http://www.rlmueller.net Version 1.0 - January 2, 2007 You have a royalty-free right to use, modify, reproduce, and distribute this script file in any way you find useful, provided that you agree that the copyright owner above has no warranty, obligations, or liability for such use. ------------------------------------------------------------------------ ]]-- -- Updated to Script V2 and given some repeat options (StackOverflow) local lngX = 1000 local lngC = 48313 local function _MWC() local S_Hi local S_Lo local C_Hi local C_Lo local F1 local F2 local F3 local T1 local T2 local T3 local A_Hi = 63551 local A_Lo = 25354 local M = 4294967296 local H = 65536 local S_Hi = math.floor(lngX / H) local S_Lo = lngX - (S_Hi * H) local C_Hi = math.floor(lngC / H) local C_Lo = lngC - (C_Hi * H) local F1 = A_Hi * S_Hi local F2 = (A_Hi * S_Lo) + (A_Lo * S_Hi) + C_Hi local F3 = (A_Lo * S_Lo) + C_Lo local T1 = math.floor(F2 / H) local T2 = F2 - (T1 * H) lngX = (T2 * H) + F3 local T3 = math.floor(lngX / M) lngX = lngX - (T3 * M) lngC = math.floor((F2 / H) + F1) return lngX end local function _abs(value) if value < 0 then value = -value end return value end local function _floor(value) return value - (value % 1) end local function _randomseed(x) lngX = x end local function _random(m,n) if n == nil and m ~= nil then n = m m = 1 end if (m == nil) and (n == nil) then return _MWC() / 4294967296 else if n < m then return nil end return math.floor((_MWC() / 4294967296) * (n - m + 1)) + m end end math= { abs = _abs, floor = _floor, random = _random, randomseed = _randomseed, } --[[ End math library ]]-- function Score() return current.GetScore () end function seed() local s=math.abs(Score()) s=s%0.001 s=1/s while s<10000000 do s=s*10 end s=s-s%1 math.randomseed(s) end seed() segCnt=structure.GetCount () p=print function round(x)--cut all afer 3-rd place return x-x%0.001 end function down(x) return x-x%1 end function ShuffeleTable() p("Mixing LWS table...") local tl=#lwsTable for i=1,tl do local n=math.random(tl) lwsTable[i],lwsTable[n]=lwsTable[n],lwsTable[i] end --p("Mixing done.") --save some screen space, redundant message (Stack) end lwsTable={} function CreateTable() p("Preparing LWS table...") lwsTable={} if segEnd==nil then segEnd=segCnt end for sn=segStart,segEnd do for l=minLen, maxLen do if (sn+l-1)<=segEnd then lwsTable[#lwsTable+1]={sn,l} end end end p("We have LWS ",#lwsTable," starts to do.") end function lws() repeat local s=Score() structure.LocalWiggleSelected(2) local g=Score()-s if g<0 then recentbest.Restore() end until g<minPpi end function WalkeR() recentbest.Save () save.Quicksave(3) local ss=Score() p("Starting WalkeR, Score=",round(ss)) local tl=#lwsTable for i=1, tl do local sc=Score() local s=lwsTable[i][1] local l=lwsTable[i][2] selection.DeselectAll () selection.SelectRange(s,s+l-1) lws() save.Quicksave(3) print("Iter " ..i .. "/" .. tl .. " (" .. s .. ":" .. l .. ") g: " .. round(Score()-sc) .. " score: " .. round(Score()) .. plus() ) end p("Total gain: ",round(Score()-ss)) end segStart=1 --start from segEnd=nil --end seg: nil=end of protein minLen=1 --minimum lws len maxLen=7 --maximum lws len minPpi=0.01 --minimum points gain per 2 wiggles, set 0.0001 in endgame :) function go () CreateTable() ShuffeleTable() WalkeR() end function main () -- main added by StackOverflow startScore = current.GetScore () local mf = dialog.CreateDialog ( "Rav3n Marathon WalkeR" ) mf.chk1 = dialog.AddCheckbox ( "Run specified number of times" , true ) mf.sldr = dialog.AddSlider ( "Times" , 3 , 1 , 10 , 0 ) mf.chk2 = dialog.AddCheckbox ( "Run until no more gains are achieved" , false ) mf.chk3 = dialog.AddCheckbox ( "Run forever" , false ) mf.btnGo = dialog.AddButton ( "Start" , 1 ) mf.btnExit = dialog.AddButton ( "Exit" , 0 ) local cmd = dialog.Show ( mf ) if ( cmd == 1 ) then if ( mf.chk3.value == true ) then local iter1 = 1 while ( true ) do print ( "Run " .. iter1 .. " (will run forever!)" ) go () iter1 = iter1 + 1 print ( newscore () ) end elseif ( mf.chk2.value == true ) then local ssc = current.GetScore () - 1 local iter2 = 1 while ( flr ( current.GetScore () , 3 ) > flr ( ssc , 3 ) ) do print ( "Run " .. iter2 .. " (will run until no gains are achieved)" ) ssc = current.GetScore () go () iter2 = iter2 + 1 print ( newscore () ) end elseif ( mf.chk1.value == true ) then for r = 1 , mf.sldr.value do print ( "Run " .. r .. " of " .. mf.sldr.value ) go () print ( newscore () ) end else print ( "no valid repeat options specified, running once only" ) go () end else print ( "user cancelled" ) end end function newscore () return "New Score: " .. flr ( current.GetScore() , 3 ) .. plus () end function plus () return " (+" .. flr((current.GetScore() - startScore),3) .. ")" end function flr(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult) / mult end main ()

Comments