Class: RGL::ImplicitGraph
Overview
An ImplicitGraph provides a handy way to define graphs on the fly, using two blocks for the two iterators defining a graph. Other examples are given by the methods Graph#vertices_filtered_by and Graph#edges_filtered_by, which can be applied to any graph.
Constant Summary collapse
- EMPTY_VERTEX_ITERATOR =
proc { |b| }
- EMPTY_NEIGHBOR_ITERATOR =
proc { |x, b| }
Instance Attribute Summary collapse
-
#directed ⇒ Object
writeonly
Sets the attribute directed.
Instance Method Summary collapse
-
#adjacent_iterator(&block) ⇒ Object
Sets the adjacent_iterator to block, which must be a block of two parameters:.
-
#directed? ⇒ Boolean
Returns the value of @directed.
- #each_adjacent(v, &block) ⇒ Object
- #each_edge(&block) ⇒ Object
- #each_vertex(&block) ⇒ Object
-
#edge_iterator(&block) ⇒ Object
Sets the edge_iterator to block, which must be a block of two parameters: The first parameter is the source of the edges; the second is the target of the edge.
-
#initialize {|_self| ... } ⇒ ImplicitGraph
constructor
Create a new ImplicitGraph, which is empty by default.
-
#vertex_iterator(&block) ⇒ Object
Sets the vertex_iterator to block, which must be a block of one parameter which again is the block called by #each_vertex.
Methods included from Graph
#acyclic?, #adjacent_vertices, #bellman_ford_shortest_paths, #bfs_iterator, #bfs_search_tree_from, #bipartite?, #bipartite_sets, #condensation_graph, #depth_first_search, #depth_first_visit, #dfs_iterator, #dijkstra_shortest_path, #dijkstra_shortest_paths, #dotty, #each, #each_connected_component, #edge_class, #edges, #edges_filtered_by, #empty?, #eql?, #has_edge?, #has_vertex?, #implicit_graph, #maximum_flow, #num_edges, #out_degree, #path?, #prim_minimum_spanning_tree, #print_dotted_on, #reverse, #set_edge_options, #set_vertex_options, #size, #strongly_connected_components, #to_adjacency, #to_dot_graph, #to_s, #to_undirected, #topsort_iterator, #transitive_closure, #transitive_reduction, #vertex_id, #vertex_label, #vertices, #vertices_filtered_by, #write_to_graphic_file
Constructor Details
#initialize {|_self| ... } ⇒ ImplicitGraph
Create a new RGL::ImplicitGraph, which is empty by default. The caller should configure the graph using vertex and neighbor iterators. If the graph is directed, the client should set @directed to true. The default value for @directed is false.
40 41 42 43 44 45 |
# File 'lib/rgl/implicit.rb', line 40 def initialize @directed = false @vertex_iterator = EMPTY_VERTEX_ITERATOR @adjacent_iterator = EMPTY_NEIGHBOR_ITERATOR yield self if block_given? # Let client overwrite defaults. end |
Instance Attribute Details
#directed=(value) ⇒ Object (writeonly)
Sets the attribute directed
30 31 32 |
# File 'lib/rgl/implicit.rb', line 30 def directed=(value) @directed = value end |
Instance Method Details
#adjacent_iterator(&block) ⇒ Object
Sets the adjacent_iterator to block, which must be a block of two parameters:
The first parameter is the vertex the neighbors of which are to be
traversed.
The second is the block which will be called for each neighbor
of this vertex.
86 87 88 |
# File 'lib/rgl/implicit.rb', line 86 def adjacent_iterator(&block) @adjacent_iterator = block end |
#directed? ⇒ Boolean
Returns the value of @directed.
49 50 51 |
# File 'lib/rgl/implicit.rb', line 49 def directed? @directed end |
#each_adjacent(v, &block) ⇒ Object
57 58 59 |
# File 'lib/rgl/implicit.rb', line 57 def each_adjacent(v, &block) @adjacent_iterator.call(v, block) end |
#each_edge(&block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/rgl/implicit.rb', line 61 def each_edge(&block) if defined? @edge_iterator @edge_iterator.call(block) else super # use default implementation end end |
#each_vertex(&block) ⇒ Object
53 54 55 |
# File 'lib/rgl/implicit.rb', line 53 def each_vertex(&block) @vertex_iterator.call(block) end |
#edge_iterator(&block) ⇒ Object
Sets the edge_iterator to block, which must be a block of two parameters: The first parameter is the source of the edges; the second is the target of the edge.
94 95 96 |
# File 'lib/rgl/implicit.rb', line 94 def edge_iterator(&block) @edge_iterator = block end |
#vertex_iterator(&block) ⇒ Object
Sets the vertex_iterator to block, which must be a block of one parameter which again is the block called by #each_vertex.
73 74 75 |
# File 'lib/rgl/implicit.rb', line 73 def vertex_iterator(&block) @vertex_iterator = block end |