Exemplo n.º 1
0
def main(num_agents):
    world, starts, goals = util.generate_problem(num_agents, 16, 16, 0.2)

    # Create agents
    agents = [Agent(world, starts[i], goals[i]) for i in range(num_agents)]
    start_time = timeit.default_timer()
    paths = dimpp(agents, None, None)
    end_time = timeit.default_timer()
    print(f'elapsed time: {(end_time - start_time) * 1000:5.3f}ms')

    print('Making visualisation')
    vis = visualisation.Visualisation(world, num_agents, scale=20)
    vis.draw_paths('midpp.mkv', paths)
Exemplo n.º 2
0
def main(agents):
    world, starts, goals = util.generate_problem(agents, 16, 16, 0.2)
    print(starts, goals)

    start_time = timeit.default_timer()
    paths = standard_algorithm(agents, world, starts, goals,
                               start_time=start_time, max_time=15)
    end_time = timeit.default_timer()
    print(f'elapsed time: {(end_time - start_time) * 1000:5.3f}ms')

    print('Writing visualisations')
    vis = visualisation.Visualisation(world, agents, scale=20)
    frames = vis.draw_paths('sa.mkv', paths)
Exemplo n.º 3
0
def main(agents):
    world, starts, goals = util.generate_problem(agents, 16, 16, 0.2)
    print('starts:', starts)
    print('goals: ', goals)

    start_time = timeit.default_timer()
    paths = odid2(agents,
                  world,
                  starts,
                  goals,
                  start_time=start_time,
                  max_time=5)

    print('Writing visualisations')
    vis = visualisation.Visualisation(world, agents, scale=20)
    frames = vis.draw_paths('odid.mkv', paths)
Exemplo n.º 4
0
def main(num_agents):
    world, starts, goals = util.generate_problem(num_agents, 16, 16, 0.2)

    # Create agents
    agents = [Agent(world, starts[i], goals[i]) for i in range(num_agents)]
    start_time = timeit.default_timer()
    if '--simple' in sys.argv or '-s' in sys.argv:
        paths = simple_poc(agents)
    else:
        paths = poc(agents, start_time=start_time, max_time=5)
    end_time = timeit.default_timer()
    print(f'elapsed time: {(end_time - start_time) * 1000:5.3f}ms')

    print('Making visualisation')
    vis = visualisation.Visualisation(world, num_agents, scale=20)
    vis.draw_paths('poc.mkv', paths)
Exemplo n.º 5
0
def version1(agents, start_time, max_time, visualize=False):
    paths = []
    for agent in agents:
        agent.plan(start_time=start_time, max_time=max_time)
        paths.append(agent.path)

    if visualize:
        vis = visualisation.Visualisation(agents[0].world,
                                          len(agents),
                                          scale=20)
        count = 0
    conflicts = util.paths_conflict(paths)
    init_conflicts = len(convert_conflicts(agents, conflicts))
    while conflicts:
        time = timeit.default_timer()
        if start_time != None and (time - start_time) > max_time:
            raise TimeExceeded()
        if visualize:
            print('Exporting conflicts')
            im = vis.draw_paths_with_conflicts(paths, conflicts)
            im.save(f'conflict_{count:05}.png')
            count += 1
        #print(f'Conflicts found: {len(conflicts)}')
        #pprint(conflicts)
        conflict_objs = convert_conflicts(agents, conflicts)
        #pprint(conflict_objs)
        # Add conflicts to agents
        for agent in agents:
            agent.conflicts.clear()
        for conflict in conflict_objs.values():
            for agent in conflict.agents:
                agent.conflicts.add(conflict)

        # Get the agents to resove the conflicts
        for agent in agents:
            try:
                conflict = agent.conflicts[0]
            except IndexError:
                continue  # Agent has no conflicts
            conflict.resolve(agents, start_time, max_time)

        # Update the list of conflicts
        paths = [agent.path for agent in agents]
        conflicts = util.paths_conflict(paths)
        #print() # Just a new line to break up iterations

    # Final visualisation
    if visualize:
        print('Exporting final conflicts')
        im = vis.draw_paths_with_conflicts(paths, conflicts)
        im.save(f'conflict_{count:05}.png')
    # Find number of conflicts solved
    conflicts = set()
    for agent in agents:
        conflicts.update(agent.resolved_conflicts)
    # Find the size of conflicts
    sizes = (len(c.agents) for c in conflicts)
    return {'paths': paths,
            'initial': init_conflicts,
            'solved': len(conflicts),
            'sizes': sizes,
        }