-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/parallel_sgs
# Conflicts: # sampo/scheduler/genetic/operators.py # sampo/scheduler/genetic/schedule_builder.py # tests/scheduler/genetic/converter_test.py
- Loading branch information
Showing
8 changed files
with
176 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
import queue | ||
|
||
from sampo.schemas.graph import GraphNode | ||
|
||
|
||
def count_node_ancestors(finish: GraphNode, root: GraphNode) -> int: | ||
def count_ancestors(first_ancestors: list[GraphNode], root: GraphNode) -> int: | ||
""" | ||
Counts the number of ancestors of the whole graph. | ||
:param finish: The node for which ancestors are to be counted. | ||
:param first_ancestors: First ancestors of ancestors which must be counted. | ||
:param root: The root node of the graph. | ||
:return: | ||
""" | ||
q = queue.Queue() | ||
count = 0 | ||
q = list(first_ancestors) | ||
count = len(first_ancestors) | ||
used = set() | ||
used.add(root) | ||
q.put(finish) | ||
while not q.empty(): | ||
node = q.get() | ||
while q: | ||
node = q.pop() | ||
for parent in node.parents: | ||
if parent in used: | ||
continue | ||
used.add(parent) | ||
q.put(parent) | ||
q.insert(0, parent) | ||
count += 1 | ||
|
||
return count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.