3 # A simple graph library
6 # A vertex in a graph. The edge can have arbitrary attributes,treated as
8 class Vertex
< OpenStruct
15 # Connect this vertex to another, creating an Edge to do so, and returning
21 other
.edges
<< e
unless self === other
25 # Connect this vertex to another, creating an Edge to do so, and returning
32 # Return the set of neighbouring vertices
34 vertices
= self.edges
.map
{|e
| e
.vertices
}.flatten
35 vertices_to_me
= vertices
.select
{|v
| v
== self}
36 other_vertices
= vertices
.select
{|v
| v
!= self}
37 (vertices_to_me
[1..-1] || []) + other_vertices