self.to_phenotype_mapping.add_map(name="init_offset", tag="<PhaseOffset>") if not os.path.isfile("./" + RUN_DIR + "/checkpoint.pickle"): random.seed(SEED) np.random.seed(SEED) my_sim = Sim(dt_frac=DT_FRAC, simulation_time=SIM_TIME, min_temp_fact=MIN_TEMP_FACT, fitness_eval_init_time=INIT_TIME) my_env = Env(temp_amp=TEMP_AMP) my_env.add_param("growth_amplitude", GROWTH_AMPLITUDE, "<GrowthAmplitude>") my_objective_dict = ObjectiveDict() my_objective_dict.add_objective(name="fitness", maximize=True, tag="<finalDistY>") my_objective_dict.add_objective(name="age", maximize=False, tag=None) my_pop = Population(my_objective_dict, MyGenotype, Phenotype, pop_size=POP_SIZE) my_optimization = ParetoOptimization(my_sim, my_env, my_pop) my_optimization.run(max_hours_runtime=MAX_TIME, max_gens=MAX_GENS,
self.to_phenotype_mapping.add_map(name="init_offset", tag="<PhaseOffset>") random.seed(SEED) np.random.seed(SEED) my_sim = Sim(dt_frac=DT_FRAC, simulation_time=SIM_TIME, min_temp_fact=MIN_TEMP_FACT, fitness_eval_init_time=INIT_TIME) my_env = Env(temp_amp=TEMP_AMP, falling_prohibited=STOP_AFTER_FALLING, time_between_traces=TIME_BETWEEN_TRACES) my_env.add_param("growth_amplitude", GROWTH_AMPLITUDE, "<GrowthAmplitude>") my_env.add_param("save_traces", int(SAVE_TRACES), "<SaveTraces>") my_objective_dict = ObjectiveDict() my_objective_dict.add_objective(name="fitness", maximize=True, tag="<finalDistY>") my_objective_dict.add_objective(name="age", maximize=False, tag=None) my_objective_dict.add_objective(name="lifetime", maximize=True, tag="<Lifetime>", logging_only=True) my_objective_dict.add_objective(name="trace", maximize=True, tag="<CMTrace>", logging_only=True)
# Discarding the robot if it doesn't have at least a given percentage of muscles (materials 3 and 4) if count_occurrences(state, [3, 4]) < np.product( self.genotype.orig_size_xyz) * min_percent_muscle: return False return True # Setting up the simulation object my_sim = Sim(dt_frac=DT_FRAC, simulation_time=SIM_TIME, fitness_eval_init_time=INIT_TIME) # Setting up the environment object my_env = Env(sticky_floor=0, time_between_traces=0) # Here we tell the physics engine that we want to simulate a fluid environment my_env.add_param("fluid_environment", 1, "<FluidEnvironment>") my_env.add_param("aggregate_drag_coefficient", AGGREGATE_DRAG_COEF, "<AggregateDragCoefficient>") # Now specifying the objectives for the optimization. # Creating an objectives dictionary my_objective_dict = ObjectiveDict() # Adding an objective named "fitness", which we want to maximize. This information is returned by Voxelyze # in a fitness .xml file, with a tag named "NormFinalDist" my_objective_dict.add_objective(name="fitness", maximize=True, tag="<normAbsoluteDisplacement>") # Add an objective to minimize the age of solutions: promotes diversity my_objective_dict.add_objective(name="age", maximize=False, tag=None)
if not os.path.isfile("./" + RUN_DIR + "/pickledPops/Gen_0.pickle"): random.seed(SEED) np.random.seed(SEED) my_sim = Sim(dt_frac=DT_FRAC, simulation_time=SIM_TIME, min_temp_fact=MIN_TEMP_FACT, fitness_eval_init_time=INIT_TIME, afterlife_time=AFTERLIFE_TIME, mid_life_freeze_time=MID_LIFE_FREEZE_TIME) my_env = Env(temp_amp=TEMP_AMP, time_between_traces=TIME_BETWEEN_TRACES) my_env.add_param("growth_amplitude", GROWTH_AMPLITUDE, "<GrowthAmplitude>") my_env.add_param("min_growth_time", MIN_GROWTH_TIME, "<MinGrowthTime>") my_env.add_param("falling_prohibited", int(FALLING_PROHIBITED), "<FallingProhibited>") my_env.add_param("norm_dist_by_vol", int(NORMALIZE_DIST_BY_VOL), "<NormDistByVol>") my_env.add_param("normalization_exponent", int(NORMALIZATION_EXPONENT), "<NormalizationExponent>") my_env.add_param("save_traces", int(SAVE_TRACES), "<SaveTraces>") my_objective_dict = ObjectiveDict() my_objective_dict.add_objective(name="fitness", maximize=True, tag="<NormFinalDist>") my_objective_dict.add_objective(name="age", maximize=False, tag=None)