Skip to content
Snippets Groups Projects
Commit 26575b3e authored by Mikael Henriksson's avatar Mikael Henriksson :runner:
Browse files

resources.py: try-catch -> if cell not in cell_assignment

parent 878f17cb
No related branches found
No related tags found
1 merge request!255resources.py: try-catch -> if cell not in cell_assignment
Pipeline #92631 passed
......@@ -860,6 +860,8 @@ class ProcessCollection:
def graph_color_cell_assignment(
self,
coloring_strategy: str = "saturation_largest_first",
*,
coloring: Optional[Dict[Process, int]] = None,
) -> Set["ProcessCollection"]:
"""
Perform cell assignment of the processes in this collection using graph coloring with networkx.coloring.greedy_color.
......@@ -869,6 +871,9 @@ class ProcessCollection:
----------
coloring_strategy : str, default: "saturation_largest_first"
Graph coloring strategy passed to networkx.coloring.greedy_color().
coloring : dictionary, optional
An optional graph coloring, dictionary with Process and its associated color (int).
If a graph coloring is not provided throught this parameter, one will be created when calling this method.
Returns
-------
......@@ -877,15 +882,16 @@ class ProcessCollection:
"""
cell_assignment: Dict[int, ProcessCollection] = dict()
exclusion_graph = self.create_exclusion_graph_from_execution_time()
coloring: Dict[Process, int] = nx.coloring.greedy_color(
exclusion_graph, strategy=coloring_strategy
)
if coloring is None:
coloring = nx.coloring.greedy_color(
exclusion_graph, strategy=coloring_strategy
)
for process, cell in coloring.items():
try:
cell_assignment[cell].add_process(process)
except:
if cell not in cell_assignment:
cell_assignment[cell] = ProcessCollection(set(), self._schedule_time)
cell_assignment[cell].add_process(process)
else:
cell_assignment[cell].add_process(process)
return set(cell_assignment.values())
def left_edge_cell_assignment(self) -> Dict[int, "ProcessCollection"]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment