Class: Wallace::Koza::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/modules/koza/builder.rb

Overview

The base class used by all Koza tree builders.

Direct Known Subclasses

FullBuilder, GrowBuilder, HalfBuilder

Defined Under Namespace

Classes: FullBuilder, GrowBuilder, HalfBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#depth_limitsObject

The range of depths that trees within this species may have.



5
6
7
# File 'lib/modules/koza/builder.rb', line 5

def depth_limits
  @depth_limits
end

#non_terminalsObject (readonly)

Returns the value of attribute non_terminals.



7
8
9
# File 'lib/modules/koza/builder.rb', line 7

def non_terminals
  @non_terminals
end

#terminalsObject (readonly)

Returns the value of attribute terminals.



7
8
9
# File 'lib/modules/koza/builder.rb', line 7

def terminals
  @terminals
end

Instance Method Details

#build_subtree(max_depth, opts = {}) ⇒ Object

Builds a new subtree of a maximum given depth.

Parameters:

  • max_depth, the maximum depth of the sub-tree.

  • opts, a hash of keyword options for this method. -> random, the RNG to use for building the subtree.

Returns: The root node of the built sub-tree.

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/modules/koza/builder.rb', line 44

def build_subtree(max_depth, opts = {})
  raise NotImplementedError, 'No "build_subtree" function was implemented by this builder.'
end

#build_tree(opts = {}) ⇒ Object

Builds a new tree according to this build method that meets the depth constraints of the species.

Parameters:

  • opts, a hash of keyword options for this method. -> random, the RNG to use for building the tree.

Returns: The built tree.

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/modules/koza/builder.rb', line 31

def build_tree(opts = {})
  raise NotImplementedError, 'No "build_tree" function was implemented by this builder.'
end

#prepare(terminals, non_terminals, depth_limits) ⇒ Object

Prepares the builder.

Parameters:

  • terminals, the list of terminals.

  • non_terminals, the list of non-terminals.

  • depth_limits, the range of depths that trees within the species may have.



16
17
18
19
20
# File 'lib/modules/koza/builder.rb', line 16

def prepare(terminals, non_terminals, depth_limits)
  @terminals = terminals
  @non_terminals = non_terminals
  @depth_limits = depth_limits
end