Class: RGL::BipartiteBFSIterator

Inherits:
BFSIterator show all
Defined in:
lib/rgl/bipartite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from RGL::BFSIterator

Instance Attribute Details

#bipartite_sets_mapObject (readonly)

Returns the value of attribute bipartite_sets_map.



49
50
51
# File 'lib/rgl/bipartite.rb', line 49

def bipartite_sets_map
  @bipartite_sets_map
end

#color_mapHash (readonly) Originally defined in module GraphVisitor

Returns a map which store the colors for each vertex.

Returns:

  • (Hash)

    a map which store the colors for each vertex

#found_odd_cycleObject (readonly)

Returns the value of attribute found_odd_cycle.



49
50
51
# File 'lib/rgl/bipartite.rb', line 49

def found_odd_cycle
  @found_odd_cycle
end

#graphGraph Originally defined in module GraphWrapper

Returns the wrapped graph.

Returns:

  • (Graph)

    the wrapped graph

Instance Method Details

#handle_back_edge(u, v) ⇒ Object



73
74
75
# File 'lib/rgl/bipartite.rb', line 73

def handle_back_edge(u, v)
  verify_odd_cycle(u, v)
end

#handle_forward_edge(u, v) ⇒ Object



77
78
79
# File 'lib/rgl/bipartite.rb', line 77

def handle_forward_edge(u, v)
  verify_odd_cycle(u, v)
end

#handle_tree_edge(u, v) ⇒ Object



69
70
71
# File 'lib/rgl/bipartite.rb', line 69

def handle_tree_edge(u, v)
  @bipartite_sets_map[v] = (@bipartite_sets_map[u] + 1) % 2 unless u.nil?  # put v into the other set
end

#resetObject



51
52
53
54
55
56
# File 'lib/rgl/bipartite.rb', line 51

def reset
  super

  @bipartite_sets_map = {}
  @found_odd_cycle = false
end

#reset_start(new_start) ⇒ Object



64
65
66
67
# File 'lib/rgl/bipartite.rb', line 64

def reset_start(new_start)
  @start_vertex = new_start
  set_to_begin
end

#set_to_beginObject



58
59
60
61
62
# File 'lib/rgl/bipartite.rb', line 58

def set_to_begin
  super

  @bipartite_sets_map[@start_vertex] = 0
end