Module: Jumoku::RawDirectedTreeBuilder

Includes:
Shared, Plexus::DirectedGraphBuilder
Included in:
ArborescenceBuilder, RawDirectedTree
Defined in:
lib/jumoku/builders/raw_directed_tree.rb

Overview

A RawDirectedTree relax the undirected constraint of trees as defined in Graph Theory. They remain connected and acyclic though.

It thus uses Plexus::DirectedGraphBuilder as its backend.

It offers limited functionalities, therefore the main tree structure you'll likely to use is its extended version, Arborescence.

Constant Summary

Constant Summary

Constants included from Shared

Shared::STRATEGIES

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

- (Object) initialize(*params)

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::DirectedGraph



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jumoku/builders/raw_directed_tree.rb', line 24

def initialize(*params)
  super(*params) # Delegates to Plexus.
  args = (params.pop if params.last.is_a? Hash) || {}
  @_options = args
  strategies = _extract_strategies(args)

  class << self; self; end.module_eval do
    strategies.each { |strategy| include strategy }
    alias has_branch? has_arc?
  end
end

- (true, false) valid?

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

  • directed
  • acyclic
  • connected

Returns:

  • (true, false)


45
46
47
# File 'lib/jumoku/builders/raw_directed_tree.rb', line 45

def valid?
  super and directed?
end