Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created September 25, 2015 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wjessop/cf2e59d6e6f96578dc7b to your computer and use it in GitHub Desktop.
Save wjessop/cf2e59d6e6f96578dc7b to your computer and use it in GitHub Desktop.
require 'rgl/implicit'
require 'rgl/traversal'
vertices = ["one", "two", "three"]
g = RGL::ImplicitGraph.new do |g|
g.vertex_iterator { |b| vertices.map{|v| b.call(v) } }
g.adjacent_iterator { |x, b| b.call( vertices[(vertices.index(x) - 1).abs] ) }
g.directed = true
end
t = g.bfs_search_tree_from("one")
puts t.has_vertex?("two") # true
puts t.has_vertex?("three") # false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment