Module: Jumoku::Strategies::SimpleEdgeLabeling
- Includes:
- EdgeLabelingBackend
- Defined in:
- lib/jumoku/strategies/edge_labeling/simple.rb
Overview
A simple edge labeling strategy: as new nodes are added, new edges are assigned increasing integers. Removed edges do not trigger reindexing, so for a tree with n nodes, the labeling set is ||n|| but indexes are not necessarily < n (indexing starts from 0).
This simple strategy allows for using simple search algorithms as well for simple ordering schemes.
Instance Attribute Summary collapse
-
#next_simple_edge_label_number ⇒ Object
Returns the value of attribute next_simple_edge_label_number.
Instance Method Summary collapse
-
#add_branch!(u, v = nil, l = nil) ⇒ Object
Override to handle an iterator for simple edge labeling.
-
#sort_edges(set) ⇒ Array
Sort a set of edges.
-
#sorted_arcs_from(node) ⇒ Array<Plexus::Arc>
(also: #sorted_edges_from)
Only for directed trees.
-
#sorted_children_of(node) ⇒ Array<Node>
Only for directed trees.
-
#sorted_edges(&block) ⇒ Array
Sort edges by increasing weight number.
Instance Attribute Details
#next_simple_edge_label_number ⇒ Object
Returns the value of attribute next_simple_edge_label_number.
14 15 16 |
# File 'lib/jumoku/strategies/edge_labeling/simple.rb', line 14 def next_simple_edge_label_number @next_simple_edge_label_number end |
Instance Method Details
#add_branch!(u, v = nil, l = nil) ⇒ Object
Override to handle an iterator for simple edge labeling. When a branch is added, it is labeled with an OpenHash with one :_weight key which value is an increasing integer. One may pass any custom label to the method, which will be available under the :label key of the hash.
21 22 23 24 25 26 27 |
# File 'lib/jumoku/strategies/edge_labeling/simple.rb', line 21 def add_branch!(u, v = nil, l = nil) self.next_simple_edge_label_number ||= 0 label = OpenHash.new(:_weight => self.next_simple_edge_label_number) label.label = l unless l.nil? super(u, v, label) _edge_labeling_inc end |
#sort_edges(set) ⇒ Array
Sort a set of edges.
44 45 46 |
# File 'lib/jumoku/strategies/edge_labeling/simple.rb', line 44 def sort_edges(set) _sort_edges(set) end |
#sorted_arcs_from(node) ⇒ Array<Plexus::Arc> Also known as: sorted_edges_from
Only for directed trees.
Return the sorted list of arcs branched out from the specified node.
55 56 57 58 59 60 |
# File 'lib/jumoku/strategies/edge_labeling/simple.rb', line 55 def sorted_arcs_from(node) return nil unless is_a? RawDirectedTreeBuilder adjacent(node).map do |child_node| edge_class[node, child_node, edge_label(node, child_node)] end.sort_by { |e| e.label._weight } end |
#sorted_children_of(node) ⇒ Array<Node>
Only for directed trees.
Return the sorted list of nodes branched out from the specified node.
70 71 72 73 |
# File 'lib/jumoku/strategies/edge_labeling/simple.rb', line 70 def sorted_children_of(node) return nil unless is_a? RawDirectedTreeBuilder sorted_edges_from(node).map { |edge| edge.target } end |
#sorted_edges(&block) ⇒ Array
Sort edges by increasing weight number. If a block is provided, rely on the backend implementation (#sort_by).
34 35 36 37 |
# File 'lib/jumoku/strategies/edge_labeling/simple.rb', line 34 def sorted_edges(&block) return super(&block) if block_given? _sort_edges(edges) end |