Class: ROOGLI::DirectedGraph

Inherits:
Graph
  • Object
show all
Includes:
Enumerable
Defined in:
lib/roogli/directed_graph.rb

Overview

A directed graph class, allowing reflexive loops, but not multiple edges between the same pair of nodes (i.e.: it is not a multigraph)

Instance Attribute Summary

Attributes inherited from Graph

#nodes

Instance Method Summary collapse

Methods inherited from Graph

#add_node, #del_node, #each_node, #empty?, #export, #initialize, #size, #to_png, #to_s

Constructor Details

This class inherits a constructor from ROOGLI::Graph

Instance Method Details

#each_edgeObject

Calls block on all edges (in #each_node order)



13
14
15
16
17
18
19
# File 'lib/roogli/directed_graph.rb', line 13

def each_edge
  self.each_node do |node|
    node.out_edges.each do |edge|
      yield(edge)
    end
  end
end

#to_dot(name = 'G') ⇒ Object

returns the graph description in Graphviz's DOT language



22
23
24
25
26
27
28
29
# File 'lib/roogli/directed_graph.rb', line 22

def to_dot(name = 'G')
  s = "digraph #{name} {\n"
  s += "\tnode [shape=\"circle\"]\n"
  nodes.each {|n| s += "\t" + n.to_dot + "\n"}
  self.each_edge {|e| s += "\t" + e.to_dot + "\n"}

  return s + '}'
end