ev3_problem.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:RobotNSGA 作者: LuisLaraP 项目源码 文件源码
def main(args):
    '''Module main function'''
    global database
    global genetic_algorithm
    global joint_positions
    global goal_positions
    pygame.init()
    random.seed()
    database = utils.initialize_database(args, 'RobotTrainingData')
    database.set_objective_names(['Tiempo', r'Error en $\theta_1$', r'Error en $\theta_2$', r'Error en $\theta_3$', 'Energía'])
    problem = EV3Problem()
    generation = database.properties['highest_population']
    population_size = database.properties['population_size']
    genetic_algorithm = evolution.NSGA(problem, population_size)

    x_path = os.path.abspath(pkg_resources.resource_filename('resources.ev3', 'x_train.txt'))
    y_path = os.path.abspath(pkg_resources.resource_filename('resources.ev3', 'y_train.txt'))
    batch_start = (generation % 10) * N_GOALS
    joint_positions = np.loadtxt(x_path)[batch_start : batch_start + N_GOALS, :]
    goal_positions = np.loadtxt(y_path)[batch_start : batch_start + N_GOALS, :]

    if generation > 0:
        parents, children = utils.load_data(database)
        genetic_algorithm.set_population(parents)
        genetic_algorithm.set_children(children)
    for _ in range(args.iterations):
        generation += 1
        print('Starting generation ' + str(generation))
        genetic_algorithm.iterate()
        database.create_population()
        utils.save_data(genetic_algorithm, database)
        print('=' * (SCREEN_WIDTH - 1))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号