Icon representing a recipe

Recipe: Isaksson share for cookers 1.5.2

created by Bruno Kestemont

Profile


Name
Isaksson share for cookers 1.5.2
ID
103161
Shared with
Public
Parent
None
Children
None
Created on
January 12, 2021 at 12:25 PM UTC
Updated on
January 12, 2021 at 12:25 PM UTC
Description

Routine to exchange best results with other tracks/recipes

Best for


Code


--START Isaksson Share v1.5.2 --Copy this into your recipe and call before and after every period of time. --Warning: all saves onto you hard disk will have to be removed manually afterwards ! --reference: supplementary material for Koepnick et al (2019) De novo protein design by citizen scientists, Nature, volume 570, pages 390394 --https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-019-1274-4/MediaObjects/41586_2019_1274_MOESM1_ESM.pdf --v1: script by Isaksson --v1.2 added the dialog (BK 1/10/2019) --v1.3 added time intervals when no gain --v1.4 PrintVerbose, check every 60 seconds --v1.5 option Temp name --v1.5.2 fixed timeleft, Name to save timeLeft=os.difftime(puzzle.GetExpirationTime(),os.time())/3600 -- in hours print("Remaining time: "..timeLeft) startTime=os.time() -- in seconds userTimeInterval= 60 -- in seconds lastchecktime = startTime -- in seconds verbose = false -- print more or less info save_resolution=1000 function timeLeft() local result=os.difftime(puzzle.GetExpirationTime(),os.time())/3600 -- in hours return result end function PrintVerbose(text) if verbose then print(text) end end function ItsCheckTime() local currentTime= os.time() -- in seconds if currentTime-lastchecktime > userTimeInterval then PrintVerbose(timeLeft().." hours remaining") return true end return false end function rounding(x)--cut all afer 3-rd place return x-x%0.001 end function before_Solution(rnd,str_name) if save_resolution > 999 then return end -- New BK 1/10/2019 PrintVerbose("-Before-") hi_score = 0 hi_idx = 1 sol = save.GetSolutions() if (sol[0] == nil) then print("0 solutions found") --save.SaveSolution("auto_"..rnd) else PrintVerbose((#sol+1) .. " solutions found") for idx = 0, #sol do soli = sol[idx] if (string.find(soli.name,rnd) ~= nil) then PrintVerbose(soli.name .. " : " .. soli.score) if (soli.score > hi_score) then hi_score = soli.score hi_idx = idx end end end --print("Load the solution ...") if(current.GetEnergyScore()+save_resolution < hi_score) then save.LoadSolution(sol[hi_idx]) soli = sol[hi_idx] print("Load solution: "..soli.name.." : "..rounding(soli.score,value_score_resolution)) end end end function after_Solution(rnd,str_name) if save_resolution > 999 then return end -- New BK 1/10/2019 PrintVerbose("-After-") hi_score = 0 hi_idx = 1 sol = save.GetSolutions() if (sol[0] == nil) then print("0 solutions found") str = "auto".."-"..rnd.."-"..rounding(current.GetEnergyScore(),value_score_resolution) print("Save solution "..str) save.SaveSolution(str) else PrintVerbose((#sol+1) .. " solutions found") for idx = 0, #sol do soli = sol[idx] if (string.find(soli.name,rnd) ~= nil) then PrintVerbose(soli.name .. " : " .. soli.score) if (soli.score > hi_score) then hi_score = soli.score hi_idx = idx end end end PrintVerbose("Save the solution ...") band.DeleteAll() if(current.GetEnergyScore()-save_resolution > hi_score) then str = str_name.."-"..rnd.."-"..rounding(current.GetEnergyScore(),value_score_resolution) print("Save solution: "..str) save.SaveSolution(str) end end end str_name= ui.GetTrackName() -- copy-paste anywhere on top of the recipe rnd= "Temp" -- Warning: edit before in order to cach the right loop name --How to use: --Uncomment and insert the following 2 lines on the right places, before or after each loop: --if ItsCheckTime() then before_Solution(rnd,str_name) end -- as often as possible after score evaluations, e.g. in savebest(), or before any action --after_Solution(rnd,str_name) -- after any gain (will not save any loaded solution) --Uncommend and copy-paste the following 3x2 lines within the dialog on the right places: --ask.LabelRowBeforeSave = dialog.AddLabel("Keep save resolution to 1000 to avoid local saves") --(optional) copy-paste and adapt in the dialog --ask.save_resolution = dialog.AddSlider("Save resolution:", 1000, 0.3, 1000, 1) --copy-paste and adapt in the dialog (parameters)-- 1000 means no sharing --ask.save_Name = dialog.AddTextbox("Name to save: ", rnd) --rnd=ask.save_Name.value --save_resolution=ask.save_resolution.value -- copy-paste and adapt after the dialog.show --if save_resolution < 1000 then print("Checking for solution every "..userTimeInterval.." seconds") end --End of Isaksson Share

Comments


Bruno Kestemont Lv 1

Copy-paste into a recipe in order to make it share and load other solutions.

This originated in the supplementary material of a scientific paper, where isaksson explained how he shared parallel tracks.

Bruno Kestemont Lv 1

This was used in a series of "tandem" recipes just shared to public after long testing within Go Science team.
We waited all this time because there was a bug in the Main Foldit version, which is now resolved.