Skip to main content

GraphNode

Module: opytimizer.core.graph.node

A single vertex of a Graph/Tree.

Constructor​

GraphNode(name: str, value: Any = None, output_type: Optional[Type] = None, is_terminal: bool = True) -> None

Parameters​

ParameterTypeDefaultDescription
namestrDisplay/identifier name (e.g., the primitive's name, or a variable's name).
valueAnyNonePayload — for a terminal, the actual value; for a function node, the callable that should be applied to the node's children's evaluated outputs.
output_typeOptional[Type]NoneType produced when this node is evaluated. None means "untyped" (kept for plain graphs that don't need strongly-typed GP semantics).
is_terminalboolTrueWhether this node is a leaf (terminal) or an internal function node.

Methods​

add_child​

add_child(self, child: 'GraphNode', expected_type: Optional[Type] = None) -> None

Attaches child to this node.

Parameters​

ParameterTypeDefaultDescription
childGraphNodeNode to attach.
expected_typeOptional[Type]NoneIf provided (typed mode), validates that child.output_type matches before attaching.

copy​

copy(self) -> 'GraphNode'

Performs a deep, structure-preserving copy of the subtree/subgraph rooted at this node (recursively copies children).

evaluate​

evaluate(self) -> Any

Recursively evaluates this node: terminals return their value; function nodes apply self.value (a callable) over the evaluated children.

remove_child​

remove_child(self, child: 'GraphNode') -> None

Detaches child from this node (and vice-versa).

Parameters​

ParameterTypeDefaultDescription
childGraphNode—