def execute_plan()

in Vehicle Routing Problem/src/baseline_model.py [0:0]


def execute_plan(env, action_plan):
    no = env.n_orders
    new_action_plan = []
    for i in range(len(action_plan)):
        next_action = action_plan[i]
        # print(next_action)
        if next_action == 0:
            action = next_action
            if i < len(action_plan) - 1:
                new_action_plan = action_plan[i + 1:]
            break

        elif next_action <= no:  # Accept order
            if env.o_status[next_action - 1] == 1:  # Order is open
                action = next_action
                # if i < len(action_plan) - 1:
                #    new_action_plan = action_plan[i + 1:]
                if i < len(action_plan):
                    new_action_plan = action_plan[i:]
                break

        elif next_action <= 2 * no:  # Pickup an order
            if env.o_status[next_action - 1 - no] == 2:  # Order is ready to be picked up
                action = next_action
                if i < len(action_plan):
                    new_action_plan = action_plan[i:]
                break

        elif next_action <= 3 * no:  # Deliver an order
            if env.o_status[next_action - 1 - 2 * no] == 3:  # Order is ready to be delivered
                action = next_action
                if i < len(action_plan):
                    new_action_plan = action_plan[i:]
                break
        else:  # Go back to a restaurant
            # @TODO: How to determine that this has been achieved? Check the locations.
            action = next_action
            if (env.dr_x, env.dr_y) != (env.res_x[action - 3 * no - 1], env.res_y[action - 3 * no - 1]):
                new_action_plan = [action]
            break

    return action, new_action_plan