def generate_swap_recomputation_release_order(tensor_access_by_tensor, swap_scheduler, recomputations, job_num):
    swap_orders = defaultdict(list)
    release_orders = defaultdict(list)
    recomp_orders = defaultdict(list)
    for job_id in range(job_num):
        tensor_accesses = sorted([i for tmp in tensor_access_by_tensor[job_id].values() for i in tmp], key=(lambda x: x.tensor.tensor_id))
        swap_tasks = sorted(swap_scheduler[job_id], key=(lambda x: x.start_time))
        for i in range(len(swap_tasks)):
            swap_tasks[i].swap_task_id = i
        releases = []
        swaps = []
        recomps = []
        for access in tensor_accesses:
            if access.release_flag:
                releases.append((access.operation_id, access.tensor.tensor_id))
        release_orders[job_id] = releases
        for access in recomputations:
            recomps.append((access.operation_id, access.tensor.tensor_id, access.release_for_recomputation))
        recomp_orders[job_id] = recomps
        for task in swap_tasks:
            ref = task.execute_ref.operation_id
            swaps.append([task.tensor.tensor_id, task.execute_time, ref, (0 if (task.task_type == TaskType.swap_out) else 1), 1, task.start_time])
        swap_orders[job_id] = list(map((lambda x: x[:(- 1)]), sorted(swaps, key=(lambda x: x[(- 1)]))))
    return (release_orders, swap_orders, recomp_orders)
def generate_swap_recomputation_release_order(tensor_access_by_tensor, swap_scheduler, recomputations, job_num):
    swap_orders = defaultdict(list)
    release_orders = defaultdict(list)
    recomp_orders = defaultdict(list)
    for job_id in range(job_num):
        tensor_accesses = sorted([i for tmp in tensor_access_by_tensor[job_id].values() for i in tmp], key=(lambda x: x.tensor.tensor_id))
        swap_tasks = sorted(swap_scheduler[job_id], key=(lambda x: x.start_time))
        for i in range(len(swap_tasks)):
            swap_tasks[i].swap_task_id = i
        releases = []
        swaps = []
        recomps = []
        for access in tensor_accesses:
            if access.release_flag:
                releases.append((access.operation_id, access.tensor.tensor_id))
        release_orders[job_id] = releases
        for access in recomputations:
            recomps.append((access.operation_id, access.tensor.tensor_id, access.release_for_recomputation))
        recomp_orders[job_id] = recomps
        for task in swap_tasks:
            ref = task.execute_ref.operation_id
            swaps.append([task.tensor.tensor_id, task.execute_time, ref, (0 if (task.task_type == TaskType.swap_out) else 1), 1, task.start_time])
        swap_orders[job_id] = list(map((lambda x: x[:(- 1)]), sorted(swaps, key=(lambda x: x[(- 1)]))))
    return (release_orders, swap_orders, recomp_orders)