def try_swap_in(swap_in_task: SwapTask, swap_scheduler, access_of_target_tensor):
    free_intervals = get_free_intervals(swap_in_task, swap_scheduler[swap_in_task.tensor.job_id], access_of_target_tensor, 1, asc=False)
    succeed = False
    for interval in free_intervals:
        if ((interval[1] - interval[0]) >= swap_in_task.time_cost):
            swap_in_task.end_time = interval[1]
            swap_in_task.start_time = (swap_in_task.end_time - swap_in_task.time_cost)
            swap_scheduler[swap_in_task.tensor.job_id].append(swap_in_task)
            succeed = True
            break
    if (not succeed):
        return False
    else:
        return True
def try_swap_in(swap_in_task: SwapTask, swap_scheduler, access_of_target_tensor):
    free_intervals = get_free_intervals(swap_in_task, swap_scheduler[swap_in_task.tensor.job_id], access_of_target_tensor, 1, asc=False)
    succeed = False
    for interval in free_intervals:
        if ((interval[1] - interval[0]) >= swap_in_task.time_cost):
            swap_in_task.end_time = interval[1]
            swap_in_task.start_time = (swap_in_task.end_time - swap_in_task.time_cost)
            swap_scheduler[swap_in_task.tensor.job_id].append(swap_in_task)
            succeed = True
            break
    if (not succeed):
        return False
    else:
        return True