Class: NetworkX::CurrentEdge

Inherits:
Object
  • Object
show all
Defined in:
lib/networkx/flow/utils.rb

Overview

Helper class for preflow push algorithm

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(edges) ⇒ CurrentEdge

Returns a new instance of CurrentEdge.



6
7
8
9
10
11
12
# File 'lib/networkx/flow/utils.rb', line 6

def initialize(edges)
  @edges = edges
  @index = {}
  @n = edges.length
  @curr = 0
  edges.each_with_index { |(key, _value), idx| @index[idx] = key }
end

Instance Attribute Details

#currObject (readonly)

Returns the value of attribute curr.



4
5
6
# File 'lib/networkx/flow/utils.rb', line 4

def curr
  @curr
end

#edgesObject (readonly)

Returns the value of attribute edges.



4
5
6
# File 'lib/networkx/flow/utils.rb', line 4

def edges
  @edges
end

Instance Method Details

#getObject



14
15
16
# File 'lib/networkx/flow/utils.rb', line 14

def get
  [@index[@curr], @edges[@index[@curr]]]
end

#move_to_nextObject

Raises:

  • (StopIteration)


18
19
20
21
22
# File 'lib/networkx/flow/utils.rb', line 18

def move_to_next
  @temp = @curr
  @curr = (@curr + 1) % @n
  raise StopIteration if @temp == @n - 1
end