fitnesses
This commit is contained in:
@@ -61,14 +61,18 @@ class Node:
|
||||
|
||||
prune_recursive(self, 1)
|
||||
|
||||
def get_subtree_depth(self) -> int:
|
||||
def get_depth(self) -> int:
|
||||
"""Вычисляет глубину поддерева, начиная с текущего узла."""
|
||||
return (
|
||||
max(child.get_subtree_depth() for child in self.children) + 1
|
||||
max(child.get_depth() for child in self.children) + 1
|
||||
if self.children
|
||||
else 1
|
||||
)
|
||||
|
||||
def get_size(self) -> int:
|
||||
"""Вычисляет размер поддерева, начиная с текущего узла."""
|
||||
return sum(child.get_size() for child in self.children) + 1
|
||||
|
||||
def get_level(self) -> int:
|
||||
"""Вычисляет уровень узла в дереве (расстояние от корня). Корень имеет уровень 1."""
|
||||
return self.parent.get_level() + 1 if self.parent else 1
|
||||
|
||||
Reference in New Issue
Block a user