Skip to content

Commit

Permalink
Factor out retrieval of target partition
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCBrammer committed Dec 5, 2024
1 parent 3b58659 commit 81cbfc9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tucan/canonicalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,22 @@ def refine_partitions(m: nx.Graph) -> Generator[nx.Graph, None, None]:
yield from refine_partitions(m_refined)


def get_target_partition(m: nx.Graph) -> int:
partitions = nx.get_node_attributes(m, PARTITION).values()
partition_sizes = Counter(sorted(partitions))

return max(partition_sizes, key=partition_sizes.get) # type: ignore


def get_refinement_tree_node_children(m: nx.Graph) -> Generator[nx.Graph, None, None]:
n_partitions = get_number_of_partitions(m)
partitions = nx.get_node_attributes(m, PARTITION)
partition_sizes = Counter(sorted(partitions.values()))
largest_partition = max(partition_sizes, key=partition_sizes.get) # type: ignore
target_partition = get_target_partition(m)

for atom, partition in m.nodes(data=PARTITION):
if partition_sizes[partition] == 1:
# No need to artificially split singleton partitions.
continue
if partition != largest_partition:
for atom, partition in m.nodes(data=PARTITION): # type: ignore
if partition != target_partition:
continue

# Split largest partition.
# Split target partition.
m_artificially_split = m.copy()
nx.set_node_attributes(
m_artificially_split,
Expand Down

0 comments on commit 81cbfc9

Please sign in to comment.