Exemple #1
0
def add_agent():
    global vehicle_count, destinations, list_origins, list_dests

    agent = Vehicle(vehicle_count, random_coord(), 0, 0, 0, random_coord(), 0,
                    0, 0)
    while agent.coord == agent.dest:
        agent.coord = random_coord()
    agent.steps_od = abs(agent.dest[0] - agent.coord[0]) + abs(agent.dest[1] -
                                                               agent.coord[1])
    agents.append(agent)
    agent.board_id = board.create_rectangle(
        agent.coord[0] * Width + Width * 2 / 10,
        agent.coord[1] * Width + Width * 2 / 10,
        agent.coord[0] * Width + Width * 8 / 10,
        agent.coord[1] * Width + Width * 8 / 10,
        fill="green",
        width=2)
    agent.t_id = board.create_text(agent.coord[0] * Width + Width * 1 / 2,
                                   agent.coord[1] * Width + Width * 1 / 2,
                                   text=agent.id)
    agent.board_id_d = board.create_rectangle(
        agent.dest[0] * Width + Width * 2 / 10,
        agent.dest[1] * Width + Width * 2 / 10,
        agent.dest[0] * Width + Width * 8 / 10,
        agent.dest[1] * Width + Width * 8 / 10,
        fill="yellow",
        width=1)
    agent.board_id_d_t = board.create_text(
        agent.dest[0] * Width + Width * 1 / 2,
        agent.dest[1] * Width + Width * 1 / 2,
        text=agent.id)
    vehicle_count += 1
    list_origins += 1
    if list_origins >= len(origins):
        list_origins = 0
    list_dests += 1
    if list_dests >= len(destinations):
        list_dests = 0