def main_schedule(year, week, capacity): wards = [] wards_list = db.session.query(Ward).all() for item in wards_list: wards.append(item.name) all_slots = [] all_events = [] ward_slot = {} for ward in wards: slots = get_slots_for_ward(year, week, ward, capacity) ward_slot[ward] = slots all_slots = all_slots + slots nurses = db.session.query(Nurse).all() for entry in nurses: nurse = entry.first_name + entry.last_name unavilable_slots = [] secure_random = random.SystemRandom() selected_ward = secure_random.choice(wards) remaining = [item for item in wards if item != selected_ward] for item in remaining: unavilable_slots = unavilable_slots + ward_slot[item] nurse_event, un_valiable = get_nurse_events_2(nurse, unavilable_slots) for entry in un_valiable: nurse_event[0].add_unavailability(entry) all_events = all_events + nurse_event func = objective_functions.efficiency_capacity_demand_difference # func = objective_functions.equity_capacity_demand_difference schedule = scheduler.schedule(all_events, all_slots) schedule.sort(key=lambda item: item.slot.starts_at) out_put = [] for item in schedule: line = 'Nurse {0} at {1} in {2} '.format(item.event.tags[0], item.slot.starts_at, item.slot.venue) out_put.append(line) return out_put
def calculate_autoschedule(self, original_schedule=None): """Calculate autoschedule based on self.autoevents and self.autoslots, optionally using original_schedule to minimise changes""" kwargs = {} kwargs["events"] = self.autoevents kwargs["slots"] = self.autoslots # include another schedule in the calculation? if original_schedule: kwargs["original_schedule"] = original_schedule kwargs["objective_function"] = objective_functions.number_of_changes else: # otherwise use the capacity demand difference thing kwargs[ "objective_function" ] = objective_functions.efficiency_capacity_demand_difference # calculate the new schedule autoschedule = scheduler.schedule(**kwargs) return autoschedule
def main(): wards = ["ER", "OPD", "SURG"] all_slots = [] all_events = [] ward_slot = {} for ward in wards: slots = get_slots_for_ward(2017, 1, ward, 3) ward_slot[ward] = slots all_slots = all_slots + slots nurses = ["latifa bibi", "Naveeda", "Majeed", "Rahim", 'Naveed', 'Mujeeb'] for nurse in nurses: unavilable_slots = [] secure_random = random.SystemRandom() selected_ward = secure_random.choice(wards) print(selected_ward) remaining = [item for item in wards if item != selected_ward] print(remaining) for item in remaining: unavilable_slots = unavilable_slots + ward_slot[item] nurse_events, un_valiable = get_nurse_events_2(nurse, unavilable_slots) all_events = all_events + nurse_events print(all_events) func = objective_functions.efficiency_capacity_demand_difference #func = objective_functions.equity_capacity_demand_difference schedule = scheduler.schedule(all_events, all_slots) schedule.sort(key=lambda item: item.slot.starts_at) for item in schedule: print( f"{item.event.tags[0]} at {item.slot.starts_at} in {item.slot.venue}" )
def test_schedule_solver_recognised_by_pulp_raises_error(events, slots): with pytest.raises(AttributeError): scheduler.schedule(events, slots, solver="Not a real solver")
def schedule(events, slots): return [item for item in scheduler.schedule(events, slots)]
def schedule(events, slots): return list(scheduler.schedule(events, slots))