# 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) # 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="PushDist", maximize=False, tag="<PushDist>") my_objective_dict.add_objective(name="fitness", maximize=True, tag="<PushRot>") my_objective_dict.add_objective(name="RotVel", maximize=True, tag="<RotVel>", logging_only=True) #my_objective_dict.add_objective(name="fitness", maximize=True, tag="<NormFinalDist>") # Add an objective to minimize the age of solutions: promotes diversity my_objective_dict.add_objective(name="age", maximize=False, tag=None) # Adding another objective called "num_voxels", which we want to minimize in order to minimize # the amount of material employed to build the robot, promoting at the same time non-trivial # morphologies. # This information can be computed in Python (it's not returned by Voxelyze, thus tag=None), # which is done by counting the non empty voxels (material != 0) composing the robot.
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, fitness_eval_init_time=INIT_TIME) my_env = Env(temp_amp=TEMP_AMP, frequency=FREQ, density=DENSITY) my_objective_dict = ObjectiveDict() my_objective_dict.add_objective(name="fitness", maximize=True, tag="<normAbsoluteDisplacement>") if AGE_PROTECTION: my_objective_dict.add_objective(name="age", maximize=False, tag=None) my_pop = Population(my_objective_dict, MyGenotype, MyPhenotype, 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, num_random_individuals=NUM_RANDOM_INDS, directory=RUN_DIR, name=RUN_NAME,
# 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) # Adding another objective called "num_voxels", which we want to minimize in order to minimize # the amount of material employed to build the robot, promoting at the same time non-trivial # morphologies. # This information can be computed in Python (it's not returned by Voxelyze, thus tag=None), # which is done by counting the non empty voxels (material != 0) composing the robot. my_objective_dict.add_objective(name="num_voxels", maximize=False, tag=None, node_func=np.count_nonzero, output_node_name="material")
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, num_random_individuals=NUM_RANDOM_INDS, directory=RUN_DIR, name=RUN_NAME, max_eval_time=MAX_EVAL_TIME,
# 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) # 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="<NormFinalDist>") # Initializing a population of SoftBots my_pop = Population(my_objective_dict, MyGenotype, MyPhenotype, pop_size=POPSIZE) # Setting up our optimization my_optimization = ParetoOptimization(my_sim, my_env, my_pop) # And, finally, our main if __name__ == "__main__": # Here is how to use the checkpointing mechanism
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, fitness_eval_init_time=INIT_TIME, min_temp_fact=MIN_TEMP_FACT) my_env = Env(temp_amp=TEMP_AMP, frequency=FREQ, muscle_stiffness=STIFFNESS) my_objective_dict = ObjectiveDict() my_objective_dict.add_objective(name="fitness", maximize=True, tag=FITNESS_TAG) 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, num_random_individuals=NUM_RANDOM_INDS, directory=RUN_DIR, name=RUN_NAME, max_eval_time=MAX_EVAL_TIME,
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) # 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="PushDist", maximize=False, tag="<PushDist>") #my_objective_dict.add_objective(name="PushRot", maximize=True, tag="<PushRot>") my_objective_dict.add_objective(name="fitness", maximize=True, tag="<PushRotUnwr>") #my_objective_dict.add_objective(name="RotVel", maximize=True, tag="<RotVel>", logging_only=True) #my_objective_dict.add_objective(name="fitness", maximize=True, tag="<NormFinalDist>") # Add an objective to minimize the age of solutions: promotes diversity my_objective_dict.add_objective(name="age", maximize=False, tag=None) # Adding another objective called "num_voxels", which we want to minimize in order to minimize # the amount of material employed to build the robot, promoting at the same time non-trivial # morphologies. # This information can be computed in Python (it's not returned by Voxelyze, thus tag=None), # which is done by counting the non empty voxels (material != 0) composing the robot. my_objective_dict.add_objective(name="num_voxels", maximize=False, tag=None, node_func=np.count_nonzero,
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) my_pop = Population(my_objective_dict, MyGenotype, Phenotype, pop_size=POP_SIZE)
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) my_objective_dict.add_objective(name="frozen_dist", maximize=True, tag="<NormFrozenDist>", logging_only=True) 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,
# 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) # 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="<NormFinalDist>") # Adding another objective named "old_materials", which should be minimized. # This information is computed in Python as the occurrences of old materials (materials number 1, 2, 3 and 4) my_objective_dict.add_objective(name="old_materials", maximize=False, tag=None, node_func=partial(count_occurrences, keys=[1, 2, 3, 4]), output_node_name="material") my_objective_dict.add_objective(name="num_voxels", maximize=False, tag=None, node_func=partial(
# 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) # 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="<NormFinalDist>") # Adding another objective named "energy", which should be minimized. # This information is computed in Python as the occurrences of active materials (materials number 3 and 4) my_objective_dict.add_objective(name="energy", maximize=False, tag=None, node_func=partial(count_occurrences, keys=[3, 4]), output_node_name="material") ''' # Add an objective to minimize the age of solutions: promotes diversity my_objective_dict.add_objective(name="age", maximize=False, tag=None) # Adding another objective called "num_voxels", which we want to minimize in order to minimize
# 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(obstacles=True, ind_size=IND_SIZE, env_size=ENV_SIZE, init_num_obstacles=INIT_NUM_OBSTACLES, time_between_traces=0.1) # Now specifying the objectives for the optimization. # Creating an objectives dictionary my_objective_dict = ObjectiveDict() ''' # Adding an objective named "L-coeff", which we want to maximize. This information is returned by Voxelyze # in a fitness .xml file, with a tag named "LCoefficient" my_objective_dict.add_objective(name="fitness", maximize=True, tag="<LCoefficient>") ''' # 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 "MaxXYDist" my_objective_dict.add_objective(name="fitness", maximize=True, tag="<MaxXYDist>") # Adding an objective named "L-coeff", which we want to maximize. This information is returned by Voxelyze # in a fitness .xml file, with a tag named "LCoefficient" my_objective_dict.add_objective(name="L-coeff", maximize=True,
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.1) # 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="<NormFinalDist>") # Add an objective to minimize the age of solutions: promotes diversity my_objective_dict.add_objective(name="age", maximize=False, tag=None) # Adding another objective called "num_voxels", which we want to minimize in order to minimize # the amount of material employed to build the robot, promoting at the same time non-trivial # morphologies. # This information can be computed in Python (it's not returned by Voxelyze, thus tag=None), # which is done by counting the non empty voxels (material != 0) composing the robot. my_objective_dict.add_objective(name="num_voxels", maximize=False, tag=None, node_func=np.count_nonzero, output_node_name="material") # Adding another objective named "energy", which should be minimized. # This information is not returned by Voxelyze (tag=None): it is instead computed in Python. # We also specify how energy should be computed, which is done by counting the occurrences of