1- """Compute a schedule in one of three forms, convert a schedule between forms
2- and compute the difference between .
1+ """Compute a schedule in one of three forms and compute the difference between
2+ two schedules .
33
44A schedule can be represented in one of three forms:
55
1111
1212import pulp
1313import numpy as np
14+ import conference_scheduler .converter as conv
1415import conference_scheduler .lp_problem as lp
1516import conference_scheduler .heuristics as heu
1617import conference_scheduler .validator as val
1718from conference_scheduler .resources import (
18- ScheduledItem , Shape , ChangedEventScheduledItem , ChangedSlotScheduledItem
19+ Shape , ChangedEventScheduledItem , ChangedSlotScheduledItem
1920)
2021
2122# __all__ is defined so that we can control the order in which the functions
2223# are documented by sphinx.
2324__all__ = [
24- 'solution' , 'array' , 'schedule' , 'solution_to_array' ,
25- 'solution_to_schedule' , 'schedule_to_array' , 'array_to_schedule' ,
25+ 'solution' , 'array' , 'schedule' ,
2626 'event_schedule_difference' , 'slot_schedule_difference' ]
2727
2828
@@ -185,7 +185,7 @@ def array(events, slots, objective_function=None, solver=None, **kwargs):
185185 [0, 0, 0, 0, 1, 0, 0],
186186 [0, 0, 0, 0, 0, 1, 0]]
187187 """
188- return solution_to_array (
188+ return conv . solution_to_array (
189189 solution (events , slots , objective_function , solver = solver , ** kwargs ),
190190 events , slots
191191 )
@@ -212,128 +212,12 @@ def schedule(events, slots, objective_function=None, solver=None, **kwargs):
212212 list
213213 A list of instances of :py:class:`resources.ScheduledItem`
214214 """
215- return solution_to_schedule (
215+ return conv . solution_to_schedule (
216216 solution (events , slots , objective_function , solver = solver , ** kwargs ),
217217 events , slots
218218 )
219219
220220
221- # Functions to convert the schedule from one form to another
222-
223- def solution_to_array (solution , events , slots ):
224- """Convert a schedule from solution to array form
225-
226- Parameters
227- ----------
228- solution : list or tuple
229- of tuples of event index and slot index for each scheduled item
230- events : list or tuple
231- of :py:class:`resources.Event` instances
232- slots : list or tuple
233- of :py:class:`resources.Slot` instances
234-
235- Returns
236- -------
237- np.array
238- An E by S array (X) where E is the number of events and S the
239- number of slots. Xij is 1 if event i is scheduled in slot j and
240- zero otherwise
241-
242- Example
243- -------
244- For For 3 events, 7 slots and the solution::
245-
246- [(0, 1), (1, 4), (2, 5)]
247-
248- The resulting array would be::
249-
250- [[0, 1, 0, 0, 0, 0, 0],
251- [0, 0, 0, 0, 1, 0, 0],
252- [0, 0, 0, 0, 0, 1, 0]]
253- """
254- array = np .zeros ((len (events ), len (slots )), dtype = np .int8 )
255- for item in solution :
256- array [item [0 ], item [1 ]] = 1
257- return array
258-
259-
260- def solution_to_schedule (solution , events , slots ):
261- """Convert a schedule from solution to schedule form
262-
263- Parameters
264- ----------
265- solution : list or tuple
266- of tuples of event index and slot index for each scheduled item
267- events : list or tuple
268- of :py:class:`resources.Event` instances
269- slots : list or tuple
270- of :py:class:`resources.Slot` instances
271-
272- Returns
273- -------
274- list
275- A list of instances of :py:class:`resources.ScheduledItem`
276- """
277- return [
278- ScheduledItem (
279- event = events [item [0 ]],
280- slot = slots [item [1 ]]
281- )
282- for item in solution
283- ]
284-
285-
286- def schedule_to_array (schedule , events , slots ):
287- """Convert a schedule from schedule to array form
288-
289- Parameters
290- ----------
291- schedule : list or tuple
292- of instances of :py:class:`resources.ScheduledItem`
293- events : list or tuple
294- of :py:class:`resources.Event` instances
295- slots : list or tuple
296- of :py:class:`resources.Slot` instances
297-
298- Returns
299- -------
300- np.array
301- An E by S array (X) where E is the number of events and S the
302- number of slots. Xij is 1 if event i is scheduled in slot j and
303- zero otherwise
304- """
305- array = np .zeros ((len (events ), len (slots )), dtype = np .int8 )
306- for item in schedule :
307- array [events .index (item .event ), slots .index (item .slot )] = 1
308- return array
309-
310-
311- def array_to_schedule (array , events , slots ):
312- """Convert a schedule from array to schedule form
313-
314- Parameters
315- ----------
316- array : np.array
317- An E by S array (X) where E is the number of events and S the
318- number of slots. Xij is 1 if event i is scheduled in slot j and
319- zero otherwise
320- events : list or tuple
321- of :py:class:`resources.Event` instances
322- slots : list or tuple
323- of :py:class:`resources.Slot` instances
324-
325- Returns
326- -------
327- list
328- A list of instances of :py:class:`resources.ScheduledItem`
329- """
330- scheduled = np .transpose (np .nonzero (array ))
331- return [
332- ScheduledItem (event = events [item [0 ]], slot = slots [item [1 ]])
333- for item in scheduled
334- ]
335-
336-
337221# Functions to compute the difference between two schedules
338222
339223
0 commit comments