def calculate_solution_runs(instance: Instance, solution, matrix): '''Calculates the timeline for every schedule in the solution.''' runs = [] torpedoes = [] def _get_idle_torpedo(time): for torpedo in torpedoes: if time >= torpedo.current_run.start_empty_buffer: return torpedo torpedo = _Torpedo(len(torpedoes)) torpedoes.append(torpedo) return torpedo for bf_id, converter_id in enumerate(solution): if converter_id == -1: start, end, start_bf, end_bf = instance.get_emergency_interval( bf_id) torpedo = _get_idle_torpedo(start) if torpedo.current_run is not None: torpedo.current_run.end_empty_buffer = start run = _EmergencyTorpedoRun( torpedo.torpedo_id, bf_id, start_bf, end_bf, end, -1) torpedo.current_run = run runs.append(run) else: schedule = matrix[converter_id].sparse_list[bf_id] start = schedule.start_time torpedo = _get_idle_torpedo(start) if torpedo.current_run is not None: torpedo.current_run.end_empty_buffer = start run = _TorpedoRun.compile(instance, schedule, torpedo.torpedo_id) torpedo.current_run = run runs.append(run) latest_time = instance.get_latest_time() for torpedo in torpedoes: torpedo.current_run.end_empty_buffer = latest_time return runs, torpedoes
def create_emergency_timeline(instance: Instance, bf_id): '''Returns a timeline for a single emergency schedule.''' start, end, start_bf, end_bf = instance.get_emergency_interval(bf_id) return start, [T_EMPTY_TO_BF for t in range(start, start_bf)] \ + [AT_BF for t in range(start_bf, end_bf)] \ + [EMERGENCY for t in range(end_bf, end)]