Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/ruby
- require 'Problem'
- require 'logger'
- loadFile = ARGV[0] ? ARGV[0] : "problems.csv"
- answerFile = ARGV[1] ? ARGV[1] : "answer.txt"
- pReader = ProblemReader.new()
- problem = pReader.load(loadFile)
- answerOut = open(answerFile, "w")
- turn_max = 3000000 # これを超えたら、その問題はあきらめる
- level_overlap = 10
- logger = Logger.new('result.log')
- # 各問題に対して、個別最適解の探索
- for b in 0..(problem.boardList.size-1)
- board = problem.boardList[b]
- if (board.w * board.h > 12) then # このやり方では、3*4 や 4*3 が限界
- logger.info "[#{board.w},#{board.h}]#{board.key} -> #{board.endStatus()} : PASS!"
- answerOut.puts("")
- next
- end
- ss = State.new(board, "")
- ss.printState("StartState")
- stateMap = { ss.key() => ss }
- stateQueue = StateQueue.new (ss.board.w + ss.board.h)
- stateQueue.enqueue ss
- turn = 0
- result = nil
- while (result==nil && turn < turn_max && stateQueue.size()>0)
- state = stateQueue.dequeue
- l, r, u, d = state.board.movable?()
- ["l","r","u","d"].each do |dir|
- if eval(dir)
- ns = state.move(dir) # NextState
- unless stateMap.include?(ns.key) then # その状態が機知のものでなければ、下記実行
- w_filled, h_filled = ns.board.check()
- if w_filled || h_filled
- ns.board.uf += 1 if w_filled
- ns.board.lf += 1 if h_filled
- if ns.isEnd?()
- result = ns.minPath
- end
- end
- stateQueue.enqueue ns
- stateMap[ns.key] = ns
- end
- end
- end
- turn += 1
- if turn % 10000 == 0
- last = "(#{state.board.uf},#{state.board.lf})#{state.minPath}"
- p "[b]#{b}, [turn]#{turn}, [qs]#{stateQueue.to_s()}, [hs]#{stateMap.size} [last]#{last}"
- end
- end
- if result != nil # 見つかった
- logger.info "[#{b}][#{ss.board.w},#{ss.board.h}]#{ss.key} -> #{ss.board.endStatus()} : #{result}"
- answerOut.puts("#{result}")
- print "### result ### : [#{ss.board.w},#{ss.board.h}]#{ss.key} -> #{ss.board.endStatus()} : #{result} \n"
- else # 見つからなかった
- logger.info "[#{b}][#{ss.board.w},#{ss.board.h}]#{ss.key} -> #{ss.board.endStatus()} : not_found"
- answerOut.puts("")
- print "### result ### : [#{ss.board.w},#{ss.board.h}]#{ss.key} -> #{ss.board.endStatus()} : not_found \n"
- end
- end
- answerOut.close()
Add Comment
Please, Sign In to add comment