Skip to content

Commit

Permalink
Added zone finalizing info to end_of_project
Browse files Browse the repository at this point in the history
  • Loading branch information
StannisMod committed Nov 16, 2023
1 parent 3639235 commit 26e94f8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion sampo/scheduler/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,14 @@ def build_scheduler(self,
finish_time += start_time

if index == len(ordered_nodes) - 1: # we are scheduling the work `end of the project`
start_time = max(start_time, timeline.zone_timeline.finish_statuses())
finish_time, finalizing_zones = timeline.zone_timeline.finish_statuses()
start_time = max(start_time, finish_time)

# apply work to scheduling
timeline.schedule(node, node2swork, best_worker_team, contractor, work_spec,
start_time, work_spec.assigned_time, assigned_parent_time, work_estimator)

if index == len(ordered_nodes) - 1: # we are scheduling the work `end of the project`
node2swork[node].zones_pre = finalizing_zones

return node2swork.values(), assigned_parent_time, timeline
6 changes: 5 additions & 1 deletion sampo/scheduler/genetic/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ def work_scheduled(args) -> bool:
st = assigned_parent_time # this work should always have st = 0, so we just re-assign it

if idx == len(works_order) - 1: # we are scheduling the work `end of the project`
st = max(st, timeline.zone_timeline.finish_statuses())
finish_time, finalizing_zones = timeline.zone_timeline.finish_statuses()
st = max(start_time, finish_time)

# finish using time spec
timeline.schedule(node, node2swork, worker_team, contractor, work_spec,
st, exec_time, assigned_parent_time, work_estimator)

if idx == len(works_order) - 1: # we are scheduling the work `end of the project`
node2swork[node].zones_pre = finalizing_zones

work_timeline.update_timeline(st, exec_time, None)
return True
return False
Expand Down
15 changes: 12 additions & 3 deletions sampo/scheduler/timeline/zone_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ def update_timeline(self, index: int, zones: list[Zone], start_time: Time, exec_
end_time=start_time))
return sworks

def append_statuses(self, zones: list[Zone]) -> Time:
def append_statuses(self, zones: list[Zone]) -> tuple[Time, list[ZoneTransition]]:
global_finish_time = Time(0)
sworks = []

for zone in zones:
state = self._timeline[zone.name]
Expand All @@ -286,9 +287,17 @@ def append_statuses(self, zones: list[Zone]) -> Time:
state.add(ScheduleEvent(Time.inf().value, EventType.START, latest_time, None, zone.status))
state.add(ScheduleEvent(Time.inf().value, EventType.END, finish_time, None, zone.status))

if latest_status != zone.status and zone.status != 0:
# if we need to change status, record it
sworks.append(ZoneTransition(name=zone.name,
from_status=latest_status,
to_status=zone.status,
start_time=latest_time - change_cost,
end_time=latest_time))

global_finish_time = max(global_finish_time, finish_time)

return global_finish_time
return global_finish_time, sworks

def finish_statuses(self) -> Time:
def finish_statuses(self) -> tuple[Time, list[ZoneTransition]]:
return self.append_statuses([Zone(*v) for v in self._config.end_statuses])
4 changes: 3 additions & 1 deletion tests/pipeline/basic_pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_plain_scheduling_with_no_sufficient_number_of_contractors(setup_wg, set
try:
SchedulingPipeline.create() \
.wg(setup_wg) \
.contractors(setup_empty_contractors)
.contractors(setup_empty_contractors) \
.schedule(HEFTScheduler()) \
.finish()
except NoSufficientContractorError:
thrown = True

Expand Down

0 comments on commit 26e94f8

Please sign in to comment.