Пример #1
0
def read_heat_map(file_name, display=True):
    stones, cheerio, nest, path = init_stones(file_name)
    movie = Movie()
    movie.background([(s, "green") for s in stones])
    h = HeatMap()
    if not file_name:
        file_name = "tmp"
    h.read_map("data/" + file_name + "_heatmap.txt")
    movie.background(h.to_draw())
    movie.background([(path, "red")])
    movie.save_figure("data/" + file_name + "_heatmap")
    if display:
        movie.just_draw()
    else:
        movie.close()
Пример #2
0
def boxes(cfg, box_size_in_cheerio_radii=6, draw=True):
    if draw:
        movie = Movie()
        movie.background([(cfg, "black")])
    size = box_size_in_cheerio_radii * cfg.cheerio_radius

    index = 0
    path = cfg.path.points
    result = []
    while index < len(path) and path[index].x < 1 - size:
        p = path[index]
        box = rectangle.Rectangle(p.x, p.y - size / 2, p.x + size, p.y + size / 2)

        good = 0
        times = 10
        for i in range(times):
            cfg.start = p
            cfg.reset_runseed()
            r, sim_res = run.Run(run.SimulationRunner(cfg), containing_box=box).run()
            if sim_res:
                good += 1
            if draw:
                if sim_res:
                    color = "green"
                else:
                    color = "black"
                movie.background([(MotionPath(r), color)])

        r, ant_res = run.Run(run.AntRunner(cfg, index), containing_box=box).run()
        if draw:
            if ant_res:
                color = "green"
            else:
                color = "black"
            movie.background([(MotionPath(r), "blue")])
            box.add_text('{:.0f}%,{:.0f}%'.format(box_density(cfg, box) * 100, good / times * 100))
            movie.background([(box, color)])

        result.append((box_density(cfg, box), ant_res, good / times))
        while index < len(path) and path[index].x < box.qx:
            index += 1

    if draw:
        movie.save_figure(cfg.file_name + "_boxes")
        movie.close()
        # movie.just_draw()
    return result