Module: Jumoku::RawUndirectedTreeBuilder

Includes:
Shared, Plexus::UndirectedGraphBuilder
Included in:
RawUndirectedTree, TreeBuilder
Defined in:
lib/jumoku/builders/raw_undirected_tree.rb

Overview

A RawUndirectedTree sticks to the standard definition of trees in Graph Theory:

* undirected,
* connected,
* acyclic.

It thus uses Plexus::UndirectedGraphBuilder as its backend, which ensure the first constraint.

RawUndirectedTreeBuilder ensures the two remaining constraints are satisfied. It offers limited functionalities, therefore the main tree structure you’ll likely to use is its extended version, TreeBuilder.

Instance Attribute Summary

Attributes included from Shared

#_options

Instance Method Summary collapse

Methods included from Shared

#add_branch!, #add_node!, #branches, #empty?, included, #nodes, #remove_branch!, #remove_node!, #terminal?, #terminal_nodes

Instance Method Details

#initialize(*params) ⇒ Object

This method is called by the specialized implementations upon tree creation.

Initialization parameters can include:

  • an array of branches to add

  • one or several trees to copy (will be merged if multiple)

Parameters:

  • *params (Hash)

    the initialization parameters

Returns:

  • enhanced Plexus::UndirectedGraph



29
30
31
32
33
# File 'lib/jumoku/builders/raw_undirected_tree.rb', line 29

def initialize(*params)
  super(*params) # Delegates to Plexus.
  @_options = (params.pop if params.last.is_a? Hash) || {}
  _delay { alias has_branch? has_edge? }
end

#valid?Boolean

Checks whether the tree is really a valid tree, that is if the following conditions are fulfilled:

  • undirected

  • acyclic

  • connected

Returns:

  • (Boolean)


43
44
45
# File 'lib/jumoku/builders/raw_undirected_tree.rb', line 43

def valid?
  super && !directed?
end