Class: DAG::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/zipf/dag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label = nil, outgoing = [], incoming = [], score = nil) ⇒ Node

Returns a new instance of Node.



9
10
11
12
13
14
# File 'lib/zipf/dag.rb', line 9

def initialize label=nil, outgoing=[], incoming=[], score=nil
  @label    = label
  @outgoing = outgoing
  @incoming = incoming
  @score    = nil
end

Instance Attribute Details

#incomingObject

Returns the value of attribute incoming.



7
8
9
# File 'lib/zipf/dag.rb', line 7

def incoming
  @incoming
end

#labelObject

Returns the value of attribute label.



7
8
9
# File 'lib/zipf/dag.rb', line 7

def label
  @label
end

#markObject

Returns the value of attribute mark.



7
8
9
# File 'lib/zipf/dag.rb', line 7

def mark
  @mark
end

#outgoingObject

Returns the value of attribute outgoing.



7
8
9
# File 'lib/zipf/dag.rb', line 7

def outgoing
  @outgoing
end

#scoreObject

Returns the value of attribute score.



7
8
9
# File 'lib/zipf/dag.rb', line 7

def score
  @score
end

Instance Method Details

#add_edge(head, weight = 0) ⇒ Object



16
17
18
19
20
# File 'lib/zipf/dag.rb', line 16

def add_edge head, weight=0
  exit if self==head # no self-cycles!
  @outgoing << DAG::Edge.new(self, head, weight)
  return @outgoing.last
end

#reprObject



26
27
28
# File 'lib/zipf/dag.rb', line 26

def repr
  "#{to_s} #{@score} out:#{@outgoing} in:[#{@incoming.map{|e| e.to_s}.join ', '}]"
end

#to_sObject



22
23
24
# File 'lib/zipf/dag.rb', line 22

def to_s
  "DAG::Node<label:#{label}, outgoing:#{outgoing.size}, incoming:#{incoming.size}>"
end