Icon representing a recipe

Recipe: Cut And Wiggle Everything v1.3

created by KarenCH

Profile


Name
Cut And Wiggle Everything v1.3
ID
48890
Shared with
Public
Parent
None
Children
Created on
April 13, 2014 at 22:05 PM UTC
Updated on
April 13, 2014 at 22:05 PM UTC
Description

Cut And Wiggle Fuser, now supports longer stepsizes and offers "randomize" stepsize

Best for


Code


------------------------------------------------------------------------------- -- Cut And Wiggle Everything -- -- Performs a fuse-wiggle with cuts inserted every "stepsize" spot -- v1.2 fixed threshold bug -- v1.3 extended stepsize and offers "randomized" stepsizes -- Originally by Susume -- Gui added by KarenCH ------------------------------------------------------------------------------- maxStepsize=3 lowCI=0.3 highCI=1.0 shortwiggle = 2 longwiggle = 25 threshold = 1 --minimum point gain to do another iteration doRandomStepsizes = false function seedRandom() seed=os.time()/math.abs( current.GetEnergyScore() ) seed=seed%0.001 seed=1/seed while seed<10000000 do seed=seed*1000 end seed=seed-seed%1 print("Seed is: "..seed) math.randomseed(seed) end function RandomPrimeNotMoreThan( max ) local primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101} lastIdx = 1 for i=1, #primes do if primes[i] > max then break end lastIdx = i end return primes[ math.random( lastIdx ) ] end function DoWiggle( ) seedRandom() save.Quicksave(2) --starting position save.Quicksave(3) --high score segcount=structure.GetCount() highscore=current.GetEnergyScore() CI = behavior.SetClashImportance print("Original in slot 2, High score in slot 3") print("Starting score "..highscore) if doRandomStepsizes then print("Cut with random prime stepsizes, max="..maxStepsize.." segs, fusing, loop until less than "..threshold.." gain") else print("Cutting every "..maxStepsize.." segs, fusing, loop until less than "..threshold.." gain") end repeat iter_start_score = current.GetEnergyScore() currStepsize = maxStepsize if doRandomStepsizes then currStepsize = RandomPrimeNotMoreThan( maxStepsize ) end for startseg = 1, currStepsize do print("Starting at seg "..startseg.." with stepsize="..currStepsize) for i = startseg, segcount-1, currStepsize do structure.InsertCut(i) end CI(lowCI) structure.WiggleAll(shortwiggle) CI(highCI) structure.WiggleAll(longwiggle) for i = startseg, segcount-1, currStepsize do structure.DeleteCut(i) end CI(lowCI) structure.WiggleAll(shortwiggle) recentbest.Save() CI(highCI) structure.WiggleAll(longwiggle) recentbest.Restore() newscore = current.GetEnergyScore() print("New score = "..newscore) if newscore > highscore then save.Quicksave(3) highscore = newscore end print("High score = "..highscore) save.Quickload(3) end until highscore - iter_start_score < threshold end function GetParams() dlg = dialog.CreateDialog("Cut And Wiggle") dlg.step = dialog.AddSlider( "Stepsize", 3, 1, 17, 0 ) dlg.lowCI = dialog.AddSlider( "LowCI", 0.3, 0, 1, 2 ) dlg.highCI = dialog.AddSlider( "HighCI", 1.0, 0, 1, 2 ) dlg.shortwiggle = dialog.AddSlider( "ShortWiggleIters", 2, 1, 10, 0 ) dlg.longwiggle = dialog.AddSlider( "LongWiggleIters", 25, 1, 50, 0 ) dlg.comment = dialog.AddLabel("Threshold Decimal Places for min gain: 1, 0.1,.. 0.0001") dlg.thresholdExp = dialog.AddSlider( "ThreshExp:1E-", 0, 0, 4, 0 ) dlg.jumpsteps = dialog.AddCheckbox( "Use random prime stepsize (above is max)", false ) dlg.ok = dialog.AddButton("OK", 1) dlg.cancel = dialog.AddButton("Cancel", 0) if dialog.Show(dlg) > 0 then maxStepsize = dlg.step.value lowCI = dlg.lowCI.value highCI = dlg.highCI.value shortwiggle = dlg.shortwiggle.value longwiggle = dlg.longwiggle.value doRandomStepsizes = dlg.jumpsteps.value if dlg.thresholdExp.value == 0 then threshold = 1 elseif dlg.thresholdExp.value == 1 then threshold = 0.1 elseif dlg.thresholdExp.value == 2 then threshold = 0.01 elseif dlg.thresholdExp.value == 3 then threshold = 0.001 elseif dlg.thresholdExp.value == 4 then threshold = 0.0001 end return true else print( "dialog cancelled" ) end return false end function cleanup() save.Quickload(3) end function main() if GetParams() then DoWiggle( ) end end xpcall(main,cleanup)

Comments