/ppmz

pipe maze solver

Primary LanguageHaskell

Pipemaze.hs   this is the solver
notes         scratchpad & benchmark data
samples/      here are the samples
problems/     tiny files for ironing out problems
shell.nix     declares all dependencies in nix

presentation
  https://www.youtube.com/watch?v=tqhWM-uTPjw

documentation
  http://raitis.veinbahs.lv/maze/doc/Pipemaze.html

solve videos
  http://raitis.veinbahs.lv/maze/content/

--

running
  nix-shell shell.nix --run 'ghc Main.hs -o solve && ./solve samples/2'

running with websocket
  nix-shell shell.nix --run 'ghc Main.hs -o solve && time bench=True websocket=maze-server/pipes/#1,2,3,4,5,6 ./solve'

generate docs
  haddock Pipemaze.hs -o haddock -h --hyperlinked-source --quickjump

fun things to do for visualizations:
  remove coloring by equivalent parts in renderWithPositions
  screw with the score variable in sortContinues (this will likely lead to bad solve times)
  increase the frequency to see more intermediate steps

environment variables
  websocket=maze-server-host/websocket-path/#1,2,3,4,5,6,6,6
  hide=True  # hides passwords
  bench=True # skips debug output/image creation
  debug=0    # debug modes: 0=show %, 1=print maze, 2=print color maze, 3=2+clear screen, 4=make image, 5=images only during islands
  freq=10377 # call debug routine once every $freq iterations

--

benchmarking
  % time ghc Main.hs -o solve && time bench=True ./solve ./samples/6-01
  % time ghc Main.hs -o solve -threaded -with-rtsopts='-N4' && time bench=True ./solve trash/samples/{6..1}-01

with profiler
  % ghc Main.hs -o solve -prof -fprof-auto -rtsopts -with-rtsopts='-p' -fexternal-interpreter && bench=True ./solve samples/5

print trace of crash
  % ghc Main.hs -o solve -prof -with-rtsopts='-xc' && ./solve samples/2

restrict heap
  $ ghc Main.hs -o solve -rtsopts -with-rtsopts='-M1024m' && ./solve samples/3

run 8 cores
  % ghc Main.hs -o solve -threaded -with-rtsopts='-N8' && time ./solve ./samples/3

:l solve without having to resolve all type errors (amazing!)
  % ghci -fdefer-type-errors

--

with trace=4 you can make images in images/

after creating images you can animate them by running ./images/animate without any arguments (uses last directory)

insert this after "initSolve" to generate all solutions (works for 1..5 levels)
  flip (iterateMaybeM 1000) (p, 0) $ \(p, n) -> do
    p <- solve' p
    traverse ((liftIO . putStrLn =<<) . liftIO . renderStr . (\Progress{maze} -> maze)) p
    fmap (, n + 1) <$> traverse (renderImage' ("solution-" ++ show n)) p
  error "die"
  -- AND comment out the following line:
  solve' p@Progress{depth, maze=MMaze{size}} | depth == size = pure (Just p) -- remove this to compute all solutions

--

get more samples
  % (set -x; for i in {1..50}; do suffix=-$i ./samples/get 4 &; done; wait < <(jobs -p))

get 50 samples per level
  % (set -x; for level in {1..6}; do for i in {01..50}; do format="trash/samples/%i-$i" ./samples/get $level &; done; done; wait < <(jobs -p))

--

┏╸╺┓┏━╸╻┏━━╸╺┳╸╻╻╻╻╺┳╸┏━┓
┗┳┳┻┻╸╻┣╋╸╻╻╺┫┏┫┃┣┫╻┗┳┻┓╹
┏┛┗━━┓┗┫╹╺┫┗┳┛╹┣┛╹┗╋╸┃╻┗╸
┣━┳━╸┗┳╋━┓┣━╋╸╺╋╸╺┓┗┓┃┃┏┓
╹┏┻┓┏┓┃┣┓┃┃╺┫╺┳┫╺┓┃┏┻┫┣┛╹
╻┣╸╹╹┗┫┃╹┃┗╸┣━┛╹╻┣┫┃╺┻╋┓╻
┗┻╸╻┏┓╹╹╻┗┓╺┻┳━╸╹┣╋┻┓╻╹╹┃
╺┓┏┛┃┣┓╻┗┳┻┓┏┛╻┏━┫┗╸┗┛┏━┛
╻┗┫╺┛╹┗┻━┫╺┫┣━┻┻┓┗╸╺┓╺╋━╸
┃╻┣━━━┓╺━┫╻┗┛┏┳╸┣╸┏━┫┏╋┓╻
┃┃┃╺┓╻┃┏┳┛┗┳━┛┃╺┫╺┫╻┗┛╹┗┫
┣┻┛╺╋┻┛╹┃╺┓┣━╸╹╺╋━╋┻╸╻╻┏┫
╹┏┳━╋┳╸┏┻┓┣┛╺┳┓┏╋╸╹┏┳╋┻┫╹
╻┃┗╸┃┗┳┛╺╋┛╻╻╹┃┃╹╺┓╹┃┣╸┗╸
┣╋━╸╹┏╋━╸┗━┛┣╸┣┻━┳┫╻╹┃╻┏╸
┃┣╸╻╻╹┃╻╺━┓┏┛╺┻┳╸╹┃┣╸┃┃┣╸
╹╹╻┗╋━┻┛╺┳┛┗━┓╻┗╸╺┻┻┓┃┃┣┓
╻╻┣┳┻┳━╸┏┻━┳┓┣┻━━┳━┳┛┣┻┛┃
┣┻┫┃╻┗┳╸┣┓╺┫┣╋╸╺━┛┏┛╻┃╻╺┫
╹╺┛╹┗━┛╺┛╹╺┛╹┗━━╸╺┻╸┗┻┻╸╹