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(instance: Instance, solution, matrix): '''Create a timeline with state distribution for each time slot of the instance. ''' timeline = timeline = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for t in range(instance.get_latest_time() + 1)] for bf_id, converter_id in enumerate(solution): if converter_id == -1: start_time, schedule_timeline \ = create_emergency_timeline(instance, bf_id) i = start_time for state in schedule_timeline: timeline[i][state] += 1 i += 1 else: schedule = matrix[converter_id].sparse_list[bf_id] schedule_timeline \ = create_schedule_timeline(instance, schedule) i = schedule.start_time for state in schedule_timeline: timeline[i][state] += 1 i += 1 return ConflictTimeline(instance, timeline)