Skip to content

Commit d5734c6

Browse files
committed
Add unbounded events
1 parent 613222f commit d5734c6

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

src/scheduler/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ def build(
101101

102102
if solution is not None:
103103
allocations = defn.allocations(resources)
104-
defn.add_allocations(events, slots, solution, allocations)
104+
unbounded = defn.unbounded(resources)
105+
defn.add_allocations(events, slots, solution, allocations, unbounded)
105106
logger.debug(convert.schedule_to_text(solution, events, slots))
106107
io.export_solution_and_definition(
107-
resources, events, slots, solution, session.folders['solution'])
108+
resources, events, slots, allocations, solution,
109+
session.folders['solution'])
108110

109111

110112
@scheduler.command()

src/scheduler/define.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ def allocations(resources):
9898
return allocations
9999

100100

101+
def unbounded(resources):
102+
unbounded = dn.unbounded(resources['unbounded'], resources['timetable'])
103+
logger.debug(f'\nunbounded\n{unbounded}')
104+
logger.info(f'{len(unbounded)} unbounded event(s)')
105+
return unbounded
106+
107+
101108
def add_unavailability_to_events(events, slots, unavailability):
102109
for event, unavailable_slots in unavailability.items():
103110
events[event].add_unavailability(
@@ -124,7 +131,11 @@ def add_unsuitability_to_events(events, slots, unsuitability):
124131
'venue suitability.')
125132

126133

127-
def add_allocations(events, slots, solution, allocations):
134+
def add_allocations(events, slots, solution, allocations, unbounded):
135+
for unbound in unbounded:
136+
slots.append(unbound['slot'])
137+
138+
allocations.extend(unbounded)
128139
for allocation in allocations:
129140
events.append(allocation['event'])
130141

@@ -134,3 +145,4 @@ def add_allocations(events, slots, solution, allocations):
134145
solution.append((event_idx, slot_idx))
135146

136147
logger.info(f'Added {len(allocations)} pre-allocated event(s) to solution')
148+
logger.info(f'Added {len(unbounded)} event(s) to solution')

src/scheduler/denormalise.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,28 @@ def allocations(allocations_definition):
294294
for event, details in allocation.items()]
295295
except TypeError:
296296
return []
297+
298+
299+
def unbounded(unbound_definition, timetable):
300+
return [
301+
{
302+
'event': Event(
303+
name=event,
304+
duration=0,
305+
demand=0,
306+
tags=[day, venue]),
307+
'slot': Slot(
308+
venue=venue,
309+
starts_at=(datetime.combine(
310+
day,
311+
datetime.min.time()) +
312+
timedelta(seconds=details['starts_at'])),
313+
duration=0,
314+
session=f'{day} unbound',
315+
capacity=0)
316+
}
317+
for unbound in unbound_definition
318+
for event, details in unbound.items()
319+
for venue, days in timetable.items()
320+
for day in days
321+
]

src/scheduler/io.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def import_schedule_definition(solution_folder):
7373

7474

7575
def pickle_solution_and_definition(
76-
resources, events, slots, solution, solution_folder
76+
resources, events, slots, allocations, solution, solution_folder
7777
):
7878
"""Store the computed solution, the resources dict and the associated
7979
events and slots lists in pickle format"""
@@ -84,6 +84,7 @@ def pickle_solution_and_definition(
8484
'resources': resources,
8585
'events': events,
8686
'slots': slots,
87+
'allocations': allocations,
8788
'solution': solution
8889
}
8990
with pickle_file.open('wb') as f:
@@ -114,9 +115,9 @@ def export_schedule(solution, events, slots, solution_folder):
114115

115116

116117
def export_solution_and_definition(
117-
resources, events, slots, solution, solution_folder
118+
resources, events, slots, allocations, solution, solution_folder
118119
):
119120
solution_folder.mkdir(exist_ok=True)
120121
pickle_solution_and_definition(
121-
resources, events, slots, solution, solution_folder)
122+
resources, events, slots, allocations, solution, solution_folder)
122123
export_schedule(solution, events, slots, solution_folder)

0 commit comments

Comments
 (0)