-
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.
Update GA operators and fix synthetic generator (#56)
- Fix synthetic generator The generator created graphs that had nodes, in addition to the final one, that did not have children. Now it is fixed. - Delete update_resource_borders_to_peak_values operator, because it can change chromosome such that corresponding schedule changes too, in cases when lag optimization is used. - Update scheduling order mutation operator. Now it uses in addition to information about node parents, information about children. New operator improves the performance of GA. - Use numpy in zones mutation operator - Delete borders update test
- Loading branch information
Showing
8 changed files
with
176 additions
and
196 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.