Beispiel #1
0
def generate_map_homes_data(N, number_of_runs=50):
    """ generate pairs of (map, homes)
    5 movingai maps, {original (closed), open}
    5 fixed mazes, {closed,open}
    5 {10,20,30}% map {closed,open}
    """
    print "using N=%s" % N
    def iter_maps():
        for i in xrange(5):
            yield maps.read_maze('maze_%03d.map' % i)
    for m in iter_maps():
        rows = len(m)
        max_col = max(len(x) for x in m)
        if rows > N or max_col > N:
            print "Warning: you are chunking your maze from (%d,%d) to %d" % (
                    rows, max_col, N)
    fixed_mazes = [
        lambda maze=maps.chunk(N, maps.read_maze('maze_%03d.map' % i)):
            maze for i in xrange(5)]
    fixed_percent = sum([
            [lambda: maps.grid_generators.grid_makers[0](size=(N,N), p_empty=p_empty)
                for p_empty in [p]*5]
                 for p in [0.9, 0.8, 0.7]
        ],
        [])
    # movingai maps - not chunked. This is important.
    movingai_closed = [lambda maze=maps.read_movingai(m): maze for m in glob('movingai/closed/*.map')]
    movingai_open = [lambda maze=maps.read_movingai(m): maze for m in glob('movingai/open/*.map')]
    p = itertools.product
    c = itertools.chain
    def do_one((maze_gen, extend_map)):
        map_count = 0
        while map_count < number_of_runs:
            thrown = 0
            zmap, homes = maps.make_map_with_ants_on_vacancies(
                 default_homes=[(2,2), (3,7)], make_map=maze_gen, make_homes=maps.random_homes)
            a = astar(homes, zmap)
            if a is None or a < 20:
                thrown += 1
                continue
            print("ASTAR: %d (thrown %d)" % (a, thrown))
            if extend_map:
                xmap = extend_and_add_trap_to_map(zmap)
            else:
                xmap = zmap
            return xmap, homes, {'closed': not extend_map}
            map_count += 1
            #astar, ROA, ROA one ant, GOA, GOA one ant
            #    time, num of pheromones

    pairs = c(p(movingai_closed, [False]), p(movingai_open, [True]),
              p(fixed_mazes + fixed_percent, [False, True]))
    # XXX - can always turn this back to a yield, but then need to move the
    # consumer into the p.map, into do_one, to gain multiprocessing?
    ret = pmap_interleaved(pool, do_one, pairs)
    return ret
Beispiel #2
0
 def iter_maps():
     for i in xrange(5):
         yield maps.read_maze('maze_%03d.map' % i)