Skip to content

Instantly share code, notes, and snippets.

@wjessop

wjessop/graph.rb

Created Sep 25, 2015
Embed
What would you like to do?
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
@wjessop

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment