@@ -87,29 +87,34 @@ def lay(depth, solution)
8787Dir . chdir __dir__
8888use_gemfile
8989
90+ BOARD = Ractor . make_shareable ( board )
91+ OBSTRUCTED = Ractor . make_shareable ( obstructed )
92+ OUTPUT_FILENAME = Ractor . make_shareable ( output_filename )
93+ EXPANSIONS_DIR = Ractor . make_shareable ( expansions_dir )
94+
9095run_benchmark ( 10 ) do
91- depth = Lee ::Matrix . new ( board . height , board . width )
96+ depth = Lee ::Matrix . new ( BOARD . height , BOARD . width )
9297
9398 solutions = { }
9499
95- board . routes . each do |route |
96- cost = expand ( board , obstructed , depth , route )
97- solution = solve ( board , route , cost )
100+ BOARD . routes . each do |route |
101+ cost = expand ( BOARD , OBSTRUCTED , depth , route )
102+ solution = solve ( BOARD , route , cost )
98103
99- if expansions_dir
100- Lee . draw board , solutions . values , [ [ cost . keys , solution ] ] , File . join ( expansions_dir , "expansion-#{ route . object_id } .svg" )
104+ if EXPANSIONS_DIR
105+ Lee . draw BOARD , solutions . values , [ [ cost . keys , solution ] ] , File . join ( EXPANSIONS_DIR , "expansion-#{ route . object_id } .svg" )
101106 end
102107
103108 lay depth , solution
104109 solutions [ route ] = solution
105110 end
106111
107- raise 'invalid solution' unless Lee . solution_valid? ( board , solutions )
112+ raise 'invalid solution' unless Lee . solution_valid? ( BOARD , solutions )
108113
109- cost , depth = Lee . cost_solutions ( board , solutions )
110- #puts "routes: #{board .routes.size}"
114+ cost , depth = Lee . cost_solutions ( BOARD , solutions )
115+ #puts "routes: #{BOARD .routes.size}"
111116 #puts "cost: #{cost}"
112117 #puts "depth: #{depth}"
113118
114- Lee . draw board , solutions . values , output_filename if output_filename
119+ Lee . draw BOARD , solutions . values , OUTPUT_FILENAME if OUTPUT_FILENAME
115120end
0 commit comments