tree

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Type     NodeType
	Value    string // The name of the function or the terminal value (e.g. "ADD", "X", "5")
	Children []*Node
}

Node represents a single node in the abstract syntax tree.

func GenerateFull

func GenerateFull(rng *rand.Rand, maxDepth int, pset PrimitiveSet) *Node

GenerateFull creates a tree where all branches reach the exact maxDepth.

func GenerateGrow

func GenerateGrow(rng *rand.Rand, maxDepth int, pset PrimitiveSet) *Node

GenerateGrow creates a tree where branches may end before maxDepth.

func (*Node) Clone

func (n *Node) Clone() *Node

Clone creates a deep copy of the node and its children.

type NodeType

type NodeType int
const (
	FunctionNode NodeType = iota
	TerminalNode
)

type PrimitiveSet

type PrimitiveSet struct {
	Functions []string
	Terminals []string
	// Arity defines how many children each function takes
	Arity map[string]int
}

PrimitiveSet defines the available functions and terminals.

type Tree

type Tree struct {
	Root *Node
}

Tree represents the genome for Genetic Programming.

func (Tree) Clone

func (t Tree) Clone() Tree

Clone returns a deep copy of the Tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL