当前位置: 首页>>代码示例>>Python>>正文


Python Population.random方法代码示例

本文整理汇总了Python中population.Population.random方法的典型用法代码示例。如果您正苦于以下问题:Python Population.random方法的具体用法?Python Population.random怎么用?Python Population.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在population.Population的用法示例。


在下文中一共展示了Population.random方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import random [as 别名]
def main():
    parser = argparse.ArgumentParser(description="Digital germs %(prog)s", prog="digerms")

    parser.add_argument("--fps", "-f",  type=int, help="Frames per second")
    parser.add_argument("--fullscreen", "-F", action="store_true", help="Fullscreen mode")
    parser.add_argument("--screen", "-S", action="store", help="Screen number")
    parser.add_argument("--show-fps",    action="store_true", help="Display FPS count")
    parser.add_argument("--paused",      action="store_true", help="Start paused")
    parser.add_argument("--debug", "-d", action="store_true", help="Debug mode")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--size", "-s", type=str, help="Field size")
    group.add_argument("--random-maze", "-r", action="store_true", help="Random maze")
    group.add_argument("--maze", "-m", type=argparse.FileType('r'), help="Maze name or path to a file")
    parser.set_defaults(**DEFAULTS)
    options = parser.parse_args()

    params = dict(fullscreen=options.fullscreen,
                  visible=False,
                  vsync=False,
                  fps=options.fps,
                  show_fps=options.show_fps,
                  screen=int(options.screen))

    maze = None
    grid_size = None

    # guessing dimensions:
    # from fullscreen dimensions
    # from maze
    # from size parameter
    if options.maze:
        maze = Walls.load(options.maze)
        grid_size = maze.shape
    elif options.random_maze:
        maze = Walls.load(choice(list(glob('mazes/*.npy'))))
        grid_size = maze.shape
    if options.fullscreen:
        app = Application(**params)
    else:
        # TODO понять, как определять высоту из высоты лабиринта и высоты статистики
        if maze is None:
            size = map(int, options.size.split('x'))
            grid_size = (size[1] // GRID_SCALE, size[0] // GRID_SCALE)
        width = grid_size[1] * GRID_SCALE
        height = grid_size[0] * GRID_SCALE
        params.update(dict(width=width, height=height+160,))
        app = Application(**params)

    # population = PolulationWithMessia.random(POPULATION_SIZE)
    population = Population.random(POPULATION_SIZE)
    env_view = ExperimentMode(app.window, population, maze, stats_height=160, debug=options.debug)
    env_view.paused = options.paused
    app.set_mode(env_view, 1./2000)
    app.run()
开发者ID:naymen,项目名称:MELA,代码行数:56,代码来源:run.py

示例2: setup

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import random [as 别名]
def setup():
    n = 100
    population = Population.random(n)
    assert len(population) == n

    env = Environment(10, 20, 8)
    env.set_population(population)
    population.set_X(
        np.hstack([np.linspace(0, 20 * 8 - 1, 100)[:, np.newaxis], np.linspace(0, 10 * 8 - 1, 100)[:, np.newaxis]])
    )
    a = population._agents
    a.ax = 1
    a.ay = 0
    a.speed = 1
    return population
开发者ID:naymen,项目名称:MELA,代码行数:17,代码来源:test_population.py


注:本文中的population.Population.random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。