Class: Hits::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/hits/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

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

#graphObject (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


23
24
25
# File 'lib/hits/graph.rb', line 23

def in_links(vertex)
  @in_links[vertex]
end

#max_weightObject



43
44
45
# File 'lib/hits/graph.rb', line 43

def max_weight
  @edge_weights.values.max
end

#min_weightObject



47
48
49
# File 'lib/hits/graph.rb', line 47

def min_weight
  @edge_weights.values.min
end


27
28
29
# File 'lib/hits/graph.rb', line 27

def out_links(vertex)
  @graph.adjacent_vertices(vertex)
end

#to_sObject



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

#weightsObject



51
52
53
# File 'lib/hits/graph.rb', line 51

def weights
  @edge_weights.values
end