Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def self.iterative_deepening_search(root, problem)
  2.     fringe = [root]
  3.     visited = []
  4.     past_fringe = []
  5.     until fringe.empty?
  6.       vertex = fringe.pop
  7.  
  8.       visited << vertex
  9.       past_fringe << vertex
  10.  
  11.       solution = problem[vertex]
  12.       return solution if solution
  13.  
  14.       if fringe.empty?
  15.         fringe = past_fringe.collect(&:neighbours).flatten - visited
  16.         past_fringe = []
  17.       end
  18.     end
  19.     false
  20.   end
  21. end