Class: BipartiteGraph::Subgraph

Inherits:
Object
  • Object
show all
Defined in:
lib/bipartite_graph/subgraph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph) ⇒ Subgraph

Returns a new instance of Subgraph.



4
5
6
7
# File 'lib/bipartite_graph/subgraph.rb', line 4

def initialize(graph)
  @graph = graph
  clear
end

Instance Attribute Details

#edgesObject (readonly)

Returns the value of attribute edges.



3
4
5
# File 'lib/bipartite_graph/subgraph.rb', line 3

def edges
  @edges
end

#graphObject (readonly)

Returns the value of attribute graph.



3
4
5
# File 'lib/bipartite_graph/subgraph.rb', line 3

def graph
  @graph
end

#nodesObject (readonly)

Returns the value of attribute nodes.



3
4
5
# File 'lib/bipartite_graph/subgraph.rb', line 3

def nodes
  @nodes
end

#sinksObject (readonly)

Returns the value of attribute sinks.



3
4
5
# File 'lib/bipartite_graph/subgraph.rb', line 3

def sinks
  @sinks
end

#sourcesObject (readonly)

Returns the value of attribute sources.



3
4
5
# File 'lib/bipartite_graph/subgraph.rb', line 3

def sources
  @sources
end

Instance Method Details

#add_edge(edge) ⇒ Object



16
17
18
19
20
21
# File 'lib/bipartite_graph/subgraph.rb', line 16

def add_edge(edge)
  @edges << edge
  @sources << edge.from
  @sinks   << edge.to
  @nodes = @sources + @sinks
end

#clearObject



9
10
11
12
13
14
# File 'lib/bipartite_graph/subgraph.rb', line 9

def clear
  @sources = Set.new
  @sinks   = Set.new
  @nodes   = Set.new
  @edges   = EdgeSet.new
end

#has_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/bipartite_graph/subgraph.rb', line 23

def has_node?(node)
  nodes.include?(node)
end