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.



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

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.



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

def incoming
  @incoming
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#markObject

Returns the value of attribute mark.



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

def mark
  @mark
end

#outgoingObject

Returns the value of attribute outgoing.



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

def outgoing
  @outgoing
end

#scoreObject

Returns the value of attribute score.



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

def score
  @score
end

Instance Method Details

#add_edge(head, weight = 0) ⇒ Object



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

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



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

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

#to_sObject



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

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