Skip to content

Commit

Permalink
Add two utility methods to SelectWorkers resources
Browse files Browse the repository at this point in the history
  • Loading branch information
tpaviot committed Aug 28, 2024
1 parent da9a370 commit 7e1638a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions processscheduler/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self, **data) -> None:
# busy intervals can be for example [(1,3), (5, 7)]
# Dict[Task, Tuple[z3.ArithRef, z3.ArithRef]]
self._busy_intervals = {}
# a flag to tells whether or not this resource is part of a SelectWorker instance
self._part_of_selectworker = False

def add_busy_interval(
self, task, interval: Tuple[z3.ArithRef, z3.ArithRef]
Expand All @@ -77,6 +79,13 @@ def get_busy_intervals(self) -> List[Tuple[z3.ArithRef, z3.ArithRef]]:
"""returns the list of all busy intervals"""
return list(self._busy_intervals.values())

def set_part_of_selectworker(self) -> None:
"""Set the related flag to True"""
self._part_of_selectworker = True

def is_part_of_selectworker(self) -> bool:
return self._part_of_selectworker


class Worker(Resource):
"""A worker is an atomic resource that cannot be split into smaller parts.
Expand Down Expand Up @@ -122,9 +131,11 @@ def __init__(self, **data) -> None:
Worker(
name=f"{self.name}_CumulativeWorker_{i+1}",
productivity=productivities[i],
cost=ConstantFunction(value=costs_per_period[i])
if costs_per_period[i] is not None
else None,
cost=(
ConstantFunction(value=costs_per_period[i])
if costs_per_period[i] is not None
else None
),
)
for i in range(self.size)
]
Expand Down Expand Up @@ -165,8 +176,11 @@ def __init__(self, **data) -> None:
self._list_of_workers = []
for worker in self.list_of_workers:
if isinstance(worker, CumulativeWorker):
for w in worker._cumulative_workers:
w.set_part_of_selectworker()
self._list_of_workers.extend(worker._cumulative_workers)
else:
worker.set_part_of_selectworker()
self._list_of_workers.append(worker)

# a dict that maps workers and selected boolean
Expand Down

0 comments on commit 7e1638a

Please sign in to comment.