Created
September 25, 2015 16:35
-
-
Save wjessop/cf2e59d6e6f96578dc7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
http://blog.willj.net/2015/09/25/how-to-find-if-two-nodes-are-connected-in-an-rgl-graph/