class Tangle::Directed::Graph
A directed graph
Public Instance Methods
balanced?()
click to toggle source
Is the graph balanced?
# File lib/tangle/directed/graph.rb, line 114 def balanced? vertices.all? { |vertex| in_degree(vertex) == out_degree(vertex) } end
direct_predecessor?(vertex, other)
click to toggle source
Is other
a direct predecessor of vertex
?
# File lib/tangle/directed/graph.rb, line 24 def direct_predecessor?(vertex, other) direct_predecessors(vertex).include?(other) end
direct_predecessors(vertex)
click to toggle source
Return the direct predecessors of vertex
# File lib/tangle/directed/graph.rb, line 18 def direct_predecessors(vertex) in_edges(vertex).map(&:tail).to_set end
direct_successor?(vertex, other)
click to toggle source
Is other
a direct successor of vertex
?
# File lib/tangle/directed/graph.rb, line 60 def direct_successor?(vertex, other) direct_successors(vertex).include?(other) end
direct_successors(vertex)
click to toggle source
Return the direct successors of vertex
# File lib/tangle/directed/graph.rb, line 54 def direct_successors(vertex) out_edges(vertex).map(&:head).to_set end
in_degree(vertex)
click to toggle source
Return the in degree for vertex
# File lib/tangle/directed/graph.rb, line 84 def in_degree(vertex) in_edges(vertex).count end
in_edges(vertex)
click to toggle source
Return the incoming edges for vertex
# File lib/tangle/directed/graph.rb, line 12 def in_edges(vertex) edges(vertex).select { |edge| edge.head?(vertex) } end
internal?(vertex)
click to toggle source
Is vertex
internal in the graph?
# File lib/tangle/directed/graph.rb, line 108 def internal?(vertex) !(sink?(vertex) || source?(vertex)) end
out_degree(vertex)
click to toggle source
Return the out degree for vertex
# File lib/tangle/directed/graph.rb, line 90 def out_degree(vertex) out_edges(vertex).count end
out_edges(vertex)
click to toggle source
Return the outgoing edges for vertex
# File lib/tangle/directed/graph.rb, line 48 def out_edges(vertex) edges(vertex).select { |edge| edge.tail?(vertex) } end
predecessor?(vertex, other)
click to toggle source
Is other
a predecessor of vertex
?
# File lib/tangle/directed/graph.rb, line 36 def predecessor?(vertex, other) predecessors(vertex).any? { |vtx| other.eql?(vtx) } end
predecessor_subgraph(vertex, &selector)
click to toggle source
Return a subgraph with all predecessors of a vertex
# File lib/tangle/directed/graph.rb, line 42 def predecessor_subgraph(vertex, &selector) subgraph(predecessors(vertex), &selector) end
predecessors(vertex)
click to toggle source
Return a breadth first enumerator for all predecessors
# File lib/tangle/directed/graph.rb, line 30 def predecessors(vertex) vertex_enumerator(vertex, :direct_predecessors) end
sink?(vertex)
click to toggle source
Is vertex
a sink in the graph?
# File lib/tangle/directed/graph.rb, line 96 def sink?(vertex) out_degree(vertex).zero? end
source?(vertex)
click to toggle source
Is vertex
a source in the graph?
# File lib/tangle/directed/graph.rb, line 102 def source?(vertex) in_degree(vertex).zero? end
successor?(vertex, other)
click to toggle source
Is other
a successor of vertex
?
# File lib/tangle/directed/graph.rb, line 72 def successor?(vertex, other) successors(vertex).any? { |vtx| other.eql?(vtx) } end
successor_subgraph(vertex, &selector)
click to toggle source
Return a subgraph with all successors of a vertex
# File lib/tangle/directed/graph.rb, line 78 def successor_subgraph(vertex, &selector) subgraph(successors(vertex), &selector) end
successors(vertex)
click to toggle source
Return a breadth first enumerator for all successors
# File lib/tangle/directed/graph.rb, line 66 def successors(vertex) vertex_enumerator(vertex, :direct_successors) end
Private Instance Methods
new_edge(*args, **kwargs)
click to toggle source
# File lib/tangle/directed/graph.rb, line 120 def new_edge(*args, **kwargs) Edge.new(*args, **kwargs) end