Class: Hits::Graph
- Inherits:
-
Object
- Object
- Hits::Graph
- Defined in:
- lib/hits/graph.rb
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
Instance Method Summary collapse
- #add_edge(from, to, weight = 1.0) ⇒ Object
- #each_vertex(&b) ⇒ Object
- #in_links(vertex) ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #max_weight ⇒ Object
- #min_weight ⇒ Object
- #out_links(vertex) ⇒ Object
- #to_s ⇒ Object
- #weight(to, from) ⇒ Object
- #weight=(to, from, weight) ⇒ Object
- #weights ⇒ Object
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
10 11 12 13 14 |
# File 'lib/hits/graph.rb', line 10 def initialize @graph = RGL::DirectedAdjacencyGraph.new @in_links = {} @edge_weights = {} end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
8 9 10 |
# File 'lib/hits/graph.rb', line 8 def graph @graph end |
Instance Method Details
#add_edge(from, to, weight = 1.0) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/hits/graph.rb', line 16 def add_edge(from, to, weight = 1.0) @graph.add_edge(from, to) @in_links[to] ||= [] @in_links[to] << from unless @in_links[to].include? from @edge_weights[[to, from]] = weight end |
#each_vertex(&b) ⇒ Object
31 32 33 |
# File 'lib/hits/graph.rb', line 31 def each_vertex(&b) @graph.each_vertex(&b) end |
#in_links(vertex) ⇒ Object
23 24 25 |
# File 'lib/hits/graph.rb', line 23 def in_links(vertex) @in_links[vertex] end |
#max_weight ⇒ Object
43 44 45 |
# File 'lib/hits/graph.rb', line 43 def max_weight @edge_weights.values.max end |
#min_weight ⇒ Object
47 48 49 |
# File 'lib/hits/graph.rb', line 47 def min_weight @edge_weights.values.min end |
#out_links(vertex) ⇒ Object
27 28 29 |
# File 'lib/hits/graph.rb', line 27 def out_links(vertex) @graph.adjacent_vertices(vertex) end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/hits/graph.rb', line 55 def to_s @graph.edges.to_a.to_s end |
#weight(to, from) ⇒ Object
35 36 37 |
# File 'lib/hits/graph.rb', line 35 def weight(to, from) @edge_weights[[to, from]] end |
#weight=(to, from, weight) ⇒ Object
39 40 41 |
# File 'lib/hits/graph.rb', line 39 def weight=(to, from, weight) @edge_weights[[to, from]] = weight if @edge_weights[[to, from]] end |
#weights ⇒ Object
51 52 53 |
# File 'lib/hits/graph.rb', line 51 def weights @edge_weights.values end |