class DAG::Vertex
Attributes
dag[R]
outgoing_edges[R]
payload[R]
Public Class Methods
new(dag, payload)
click to toggle source
# File lib/simple_dag/vertex.rb, line 7 def initialize(dag, payload) @dag = dag @payload = payload @outgoing_edges = [] end
Public Instance Methods
[](key)
click to toggle source
Retrieve a value from the vertex's payload. This is a shortcut for vertex.payload.
@param key [Object] the payload key @return the corresponding value from the payload Hash, or nil if not found
# File lib/simple_dag/vertex.rb, line 72 def [](key) @payload[key] end
ancestors(result_set = Set.new)
click to toggle source
# File lib/simple_dag/vertex.rb, line 76 def ancestors(result_set = Set.new) predecessors.each do |v| v.ancestors(result_set) unless result_set.add?(v).nil? end result_set end
descendants(result_set = Set.new)
click to toggle source
# File lib/simple_dag/vertex.rb, line 83 def descendants(result_set = Set.new) successors.each do |v| v.descendants(result_set) unless result_set.add?(v).nil? end result_set end
incoming_edges()
click to toggle source
# File lib/simple_dag/vertex.rb, line 15 def incoming_edges @dag.enumerated_edges.select { |e| e.destination == self } end
inspect()
click to toggle source
# File lib/simple_dag/vertex.rb, line 27 def inspect "DAG::Vertex:#{@payload.inspect}" end
path_to?(other)
click to toggle source
Is there a path from here to other
following edges in the DAG
?
@param [DAG::Vertex] another Vertex
is the same DAG
@raise [ArgumentError] if other
is not a Vertex
@return true iff there is a path following edges within this DAG
# File lib/simple_dag/vertex.rb, line 38 def path_to?(other) raise ArgumentError, 'You must supply a vertex' unless other.is_a? Vertex visited = Set.new visit = lambda { |v| return false if visited.include? v return true if v.successors.lazy.include? other return true if v.successors.lazy.any? { |succ| visit.call succ } visited.add v false } visit.call self end
predecessors()
click to toggle source
# File lib/simple_dag/vertex.rb, line 19 def predecessors incoming_edges.map(&:origin) end
reachable_from?(other)
click to toggle source
Is there a path from other
to here following edges in the DAG
?
@param [DAG::Vertex] another Vertex
is the same DAG
@raise [ArgumentError] if other
is not a Vertex
@return true iff there is a path following edges within this DAG
# File lib/simple_dag/vertex.rb, line 60 def reachable_from?(other) raise ArgumentError, 'You must supply a vertex' unless other.is_a? Vertex other.path_to? self end
successors()
click to toggle source
# File lib/simple_dag/vertex.rb, line 23 def successors @outgoing_edges.map(&:destination) end
Private Instance Methods
add_edge(destination, properties)
click to toggle source
# File lib/simple_dag/vertex.rb, line 92 def add_edge(destination, properties) Edge.new(self, destination, properties).tap { |e| @outgoing_edges << e } end