Note
Click here to download the full example code
Example: Solving an OpenAI Gym environment with CGP.¶
This examples demonstrates how to solve an OpenAI Gym environment (https://gym.openai.com/envs/) with Cartesian genetic programming. We choose the “MountainCarContinuous” environment due to its continuous observation and action spaces.
Preparatory steps: Install the OpenAI Gym package: pip install gym
# The docopt str is added explicitly to ensure compatibility with
# sphinx-gallery.
docopt_str = """
Usage:
example_parametrized_nodes.py [--max-generations=<N>] [--visualize-final-champion]
Options:
-h --help
--max-generations=<N> Maximum number of generations [default: 1500]
--visualize-final-champion Create animation of final champion in the mountain car env.
"""
import functools
import warnings
import matplotlib.pyplot as plt
import numpy as np
import sympy
from docopt import docopt
import cgp
try:
import gym
except ImportError:
raise ImportError(
"Failed to import the OpenAI Gym package. Please install it via `pip install gym`."
)
args = docopt(docopt_str)
For more flexibility in the evolved expressions, we define two constants that can be used in the expressions, with values 0.1 and 10.
class ConstantFloatZeroPointOne(cgp.ConstantFloat):
_def_output = "0.1"
class ConstantFloatTen(cgp.ConstantFloat):
_def_output = "10.0"
Then we define the objective function for the evolution. The inner objective accepts a Python callable as input. This callable determines the action taken by the agent upon receiving observations from the environment. The fitness of the given callable on the task is then computed as the cumulative reward over a fixed number of episodes.
def inner_objective(f, seed, n_runs_per_individual, n_total_steps, *, render):
env = gym.make("MountainCarContinuous-v0")
env.seed(seed)
cum_reward_all_episodes = []
for _ in range(n_runs_per_individual):
observation = env.reset()
cum_reward_this_episode = 0
for _ in range(n_total_steps):
if render:
env.render()
continuous_action = f(*observation)
observation, reward, done, _ = env.step([continuous_action])
cum_reward_this_episode += reward
if done:
cum_reward_all_episodes.append(cum_reward_this_episode)
cum_reward_this_episode = 0
observation = env.reset()
env.close()
return cum_reward_all_episodes
The objective then takes an individual, evaluates the inner objective, and updates the fitness of the individual. If the expression of the individual leads to a division by zero, this error is caught and the individual gets a fitness of -infinity assigned.
def objective(ind, seed, n_runs_per_individual, n_total_steps):
if not ind.fitness_is_None():
return ind
f = ind.to_func()
try:
with warnings.catch_warnings(): # ignore warnings due to zero division
warnings.filterwarnings(
"ignore", message="divide by zero encountered in double_scalars"
)
warnings.filterwarnings(
"ignore", message="invalid value encountered in double_scalars"
)
cum_reward_all_episodes = inner_objective(
f, seed, n_runs_per_individual, n_total_steps, render=False
)
# more episodes are better, more reward is better
n_episodes = float(len(cum_reward_all_episodes))
mean_cum_reward = np.mean(cum_reward_all_episodes)
ind.fitness = n_episodes / n_runs_per_individual + mean_cum_reward
except ZeroDivisionError:
ind.fitness = -np.inf
return ind
We then define the main loop for the evolution, which consists of:
parameters for the population, the genome of individuals, and the evolutionary algorithm.
creating a Population instance and instantiating the evolutionary algorithm.
defining a recording callback closure for bookkeeping of the progression of the evolution.
Finally, we call the evolve method to perform the evolutionary search.
def evolve(seed):
objective_params = {"n_runs_per_individual": 3, "n_total_steps": 2000}
population_params = {"n_parents": 1, "seed": seed}
genome_params = {
"n_inputs": 2,
"n_outputs": 1,
"n_columns": 16,
"n_rows": 1,
"levels_back": None,
"primitives": (
cgp.Add,
cgp.Sub,
cgp.Mul,
cgp.Div,
cgp.ConstantFloat,
ConstantFloatZeroPointOne,
ConstantFloatTen,
),
}
ea_params = {"n_offsprings": 4, "tournament_size": 1, "mutation_rate": 0.04, "n_processes": 4}
evolve_params = {
"max_generations": int(args["--max-generations"]),
"termination_fitness": 100.0,
}
pop = cgp.Population(**population_params, genome_params=genome_params)
ea = cgp.ea.MuPlusLambda(**ea_params)
history = {}
history["expr_champion"] = []
history["fitness_champion"] = []
def recording_callback(pop):
history["expr_champion"].append(pop.champion.to_sympy())
history["fitness_champion"].append(pop.champion.fitness)
obj = functools.partial(
objective,
seed=seed,
n_runs_per_individual=objective_params["n_runs_per_individual"],
n_total_steps=objective_params["n_total_steps"],
)
cgp.evolve(pop, obj, ea, **evolve_params, print_progress=True, callback=recording_callback)
return history, pop.champion
For visualization, we define a function to plot the fitness over generations.
def plot_fitness_over_generation_index(history):
width = 6.0
fig = plt.figure(figsize=(width, width / 1.618))
ax = fig.add_axes([0.15, 0.15, 0.8, 0.8])
ax.set_xlabel("Generation index")
ax.set_ylabel("Fitness champion")
ax.plot(history["fitness_champion"])
fig.savefig("example_mountain_car.png", dpi=300)
We define a function that checks whether the best expression fulfills the “solving criteria”, i.e., average reward of at least 90.0 over 100 consecutive trials. (https://github.com/openai/gym/wiki/Leaderboard#mountaincarcontinuous-v0)
def evaluate_champion(ind):
env = gym.make("MountainCarContinuous-v0")
env.seed(seed)
observation = env.reset()
f = ind.to_func()
cum_reward_all_episodes = []
cum_reward_this_episode = 0
while len(cum_reward_all_episodes) < 100:
continuous_action = f(*observation)
observation, reward, done, _ = env.step([continuous_action])
cum_reward_this_episode += reward
if done:
cum_reward_all_episodes.append(cum_reward_this_episode)
cum_reward_this_episode = 0
observation = env.reset()
env.close()
cum_reward_average = np.mean(cum_reward_all_episodes)
print(f"average reward over 100 consecutive trials: {cum_reward_average:.05f}", end="")
if cum_reward_average >= 90.0:
print("-> environment solved!")
else:
print()
return cum_reward_all_episodes
Furthermore, we define a function for visualizing the agent’s behaviour for each expression that increase over the currently best performing individual.
def visualize_behaviour_for_evolutionary_jumps(seed, history, only_final_solution=True):
n_runs_per_individual = 1
n_total_steps = 999
max_fitness = -np.inf
for i, fitness in enumerate(history["fitness_champion"]):
if only_final_solution and i != (len(history["fitness_champion"]) - 1):
continue
if fitness > max_fitness:
expr = history["expr_champion"][i][0]
expr_str = str(expr).replace("x_0", "x").replace("x_1", "dx/dt")
print(f'visualizing behaviour for expression "{expr_str}" (fitness: {fitness:.05f})')
x_0, x_1 = sympy.symbols("x_0, x_1")
f_lambdify = sympy.lambdify([x_0, x_1], expr)
def f(x):
return [f_lambdify(x[0], x[1])]
inner_objective(f, seed, n_runs_per_individual, n_total_steps, render=True)
max_fitness = fitness
Finally, we execute the evolution and visualize the results. To animate the behavior of the car for the found expression, uncomment the last line of the example.
if __name__ == "__main__":
seed = 818821
print("starting evolution")
history, champion = evolve(seed)
print("evolution ended")
max_fitness = history["fitness_champion"][-1]
best_expr = history["expr_champion"][-1]
best_expr_str = str(best_expr).replace("x_0", "x").replace("x_1", "dx/dt")
print(f'solution with highest fitness: "{best_expr_str}" (fitness: {max_fitness:.05f})')
plot_fitness_over_generation_index(history)
evaluate_champion(champion)
if args["--visualize-final-champion"]:
visualize_behaviour_for_evolutionary_jumps(seed, history)
Out:
starting evolution
[2/1500] max fitness: -97.8999999999986[K
[3/1500] max fitness: -97.8999999999986[K
[4/1500] max fitness: -97.8999999999986[K
[5/1500] max fitness: -97.8999999999986[K
[6/1500] max fitness: -97.8999999999986[K
[7/1500] max fitness: -97.8999999999986[K
[8/1500] max fitness: -97.8999999999986[K
[9/1500] max fitness: -97.8999999999986[K
[10/1500] max fitness: -97.8999999999986[K
[11/1500] max fitness: -51.477965251020066[K
[12/1500] max fitness: -51.477965251020066[K
[13/1500] max fitness: -51.477965251020066[K
[14/1500] max fitness: -51.477965251020066[K
[15/1500] max fitness: -51.477965251020066[K
[16/1500] max fitness: -51.477965251020066[K
[17/1500] max fitness: -51.477965251020066[K
[18/1500] max fitness: 1.9996849395480436[K
[19/1500] max fitness: 1.9996849395480436[K
[20/1500] max fitness: 1.9996849395480436[K
[21/1500] max fitness: 1.9996849395480436[K
[22/1500] max fitness: 1.9996849395480436[K
[23/1500] max fitness: 1.9996849395480436[K
[24/1500] max fitness: 1.9996849395480436[K
[25/1500] max fitness: 1.9996849395480436[K
[26/1500] max fitness: 1.9996849395480436[K
[27/1500] max fitness: 1.9996849395480436[K
[28/1500] max fitness: 1.9996849395480436[K
[29/1500] max fitness: 1.9996849395480436[K
[30/1500] max fitness: 1.9996849395480436[K
[31/1500] max fitness: 1.9996849395480436[K
[32/1500] max fitness: 1.9996849395480436[K
[33/1500] max fitness: 1.9996849395480436[K
[34/1500] max fitness: 1.9999999206327992[K
[35/1500] max fitness: 1.9999999206327992[K
[36/1500] max fitness: 1.9999999206327992[K
[37/1500] max fitness: 1.9999999206327992[K
[38/1500] max fitness: 1.9999999206327992[K
[39/1500] max fitness: 1.9999999206327992[K
[40/1500] max fitness: 1.9999999206327992[K
[41/1500] max fitness: 1.9999999206327992[K
[42/1500] max fitness: 1.9999999206327992[K
[43/1500] max fitness: 1.9999999206327992[K
[44/1500] max fitness: 1.9999999206327992[K
[45/1500] max fitness: 1.9999999206327992[K
[46/1500] max fitness: 1.9999999206327992[K
[47/1500] max fitness: 1.9999999206327992[K
[48/1500] max fitness: 1.9999999206327992[K
[49/1500] max fitness: 1.9999999206327992[K
[50/1500] max fitness: 1.9999999206327992[K
[51/1500] max fitness: 1.9999999206327992[K
[52/1500] max fitness: 1.9999999206327992[K
[53/1500] max fitness: 2.0[K
[54/1500] max fitness: 2.0[K
[55/1500] max fitness: 2.0[K
[56/1500] max fitness: 2.0[K
[57/1500] max fitness: 2.0[K
[58/1500] max fitness: 2.0[K
[59/1500] max fitness: 2.0[K
[60/1500] max fitness: 2.0[K
[61/1500] max fitness: 2.0[K
[62/1500] max fitness: 2.0[K
[63/1500] max fitness: 2.0[K
[64/1500] max fitness: 2.0[K
[65/1500] max fitness: 2.0[K
[66/1500] max fitness: 2.0[K
[67/1500] max fitness: 2.0[K
[68/1500] max fitness: 2.0[K
[69/1500] max fitness: 2.0[K
[70/1500] max fitness: 2.0[K
[71/1500] max fitness: 2.0[K
[72/1500] max fitness: 2.0[K
[73/1500] max fitness: 2.0[K
[74/1500] max fitness: 2.0[K
[75/1500] max fitness: 2.0[K
[76/1500] max fitness: 2.0[K
[77/1500] max fitness: 2.0[K
[78/1500] max fitness: 2.0[K
[79/1500] max fitness: 2.0[K
[80/1500] max fitness: 2.0[K
[81/1500] max fitness: 2.0[K
[82/1500] max fitness: 2.0[K
[83/1500] max fitness: 2.0[K
[84/1500] max fitness: 2.0[K
[85/1500] max fitness: 2.0[K
[86/1500] max fitness: 2.0[K
[87/1500] max fitness: 2.0[K
[88/1500] max fitness: 2.0[K
[89/1500] max fitness: 2.0[K
[90/1500] max fitness: 2.0[K
[91/1500] max fitness: 2.0[K
[92/1500] max fitness: 2.0[K
[93/1500] max fitness: 2.0[K
[94/1500] max fitness: 2.0[K
[95/1500] max fitness: 2.0[K
[96/1500] max fitness: 2.0[K
[97/1500] max fitness: 2.0[K
[98/1500] max fitness: 2.0[K
[99/1500] max fitness: 2.0[K
[100/1500] max fitness: 2.0[K
[101/1500] max fitness: 2.0[K
[102/1500] max fitness: 2.0[K
[103/1500] max fitness: 2.0[K
[104/1500] max fitness: 2.0[K
[105/1500] max fitness: 2.0[K
[106/1500] max fitness: 2.0[K
[107/1500] max fitness: 2.0[K
[108/1500] max fitness: 2.0[K
[109/1500] max fitness: 2.0[K
[110/1500] max fitness: 2.0[K
[111/1500] max fitness: 2.0[K
[112/1500] max fitness: 2.0[K
[113/1500] max fitness: 2.0[K
[114/1500] max fitness: 2.0[K
[115/1500] max fitness: 2.0[K
[116/1500] max fitness: 2.0[K
[117/1500] max fitness: 2.0[K
[118/1500] max fitness: 2.0[K
[119/1500] max fitness: 2.0[K
[120/1500] max fitness: 2.0[K
[121/1500] max fitness: 2.0[K
[122/1500] max fitness: 2.0[K
[123/1500] max fitness: 2.0[K
[124/1500] max fitness: 2.0[K
[125/1500] max fitness: 2.0[K
[126/1500] max fitness: 2.0[K
[127/1500] max fitness: 2.0[K
[128/1500] max fitness: 2.0[K
[129/1500] max fitness: 2.0[K
[130/1500] max fitness: 2.0[K
[131/1500] max fitness: 2.0[K
[132/1500] max fitness: 2.0[K
[133/1500] max fitness: 2.0[K
[134/1500] max fitness: 2.0[K
[135/1500] max fitness: 2.0[K
[136/1500] max fitness: 2.0[K
[137/1500] max fitness: 2.0[K
[138/1500] max fitness: 2.0[K
[139/1500] max fitness: 2.0[K
[140/1500] max fitness: 2.0[K
[141/1500] max fitness: 2.0[K
[142/1500] max fitness: 2.0[K
[143/1500] max fitness: 2.0[K
[144/1500] max fitness: 2.0[K
[145/1500] max fitness: 2.0[K
[146/1500] max fitness: 2.0[K
[147/1500] max fitness: 2.0[K
[148/1500] max fitness: 2.0[K
[149/1500] max fitness: 2.0[K
[150/1500] max fitness: 2.0[K
[151/1500] max fitness: 2.0[K
[152/1500] max fitness: 2.0[K
[153/1500] max fitness: 2.0[K
[154/1500] max fitness: 2.0[K
[155/1500] max fitness: 2.0[K
[156/1500] max fitness: 2.0[K
[157/1500] max fitness: 2.0[K
[158/1500] max fitness: 2.0[K
[159/1500] max fitness: 2.0[K
[160/1500] max fitness: 2.0[K
[161/1500] max fitness: 2.0[K
[162/1500] max fitness: 2.0[K
[163/1500] max fitness: 2.0[K
[164/1500] max fitness: 2.0[K
[165/1500] max fitness: 2.0[K
[166/1500] max fitness: 2.0[K
[167/1500] max fitness: 2.0[K
[168/1500] max fitness: 2.0[K
[169/1500] max fitness: 2.0[K
[170/1500] max fitness: 2.0[K
[171/1500] max fitness: 2.0[K
[172/1500] max fitness: 2.0[K
[173/1500] max fitness: 2.0[K
[174/1500] max fitness: 2.0[K
[175/1500] max fitness: 2.0[K
[176/1500] max fitness: 2.0[K
[177/1500] max fitness: 2.0[K
[178/1500] max fitness: 2.0[K
[179/1500] max fitness: 2.0[K
[180/1500] max fitness: 2.0[K
[181/1500] max fitness: 2.0[K
[182/1500] max fitness: 2.0[K
[183/1500] max fitness: 2.0[K
[184/1500] max fitness: 2.0[K
[185/1500] max fitness: 2.0[K
[186/1500] max fitness: 2.0[K
[187/1500] max fitness: 2.0[K
[188/1500] max fitness: 2.0[K
[189/1500] max fitness: 2.0[K
[190/1500] max fitness: 2.0[K
[191/1500] max fitness: 2.0[K
[192/1500] max fitness: 2.0[K
[193/1500] max fitness: 2.0[K
[194/1500] max fitness: 2.0[K
[195/1500] max fitness: 2.0[K
[196/1500] max fitness: 2.0[K
[197/1500] max fitness: 2.0[K
[198/1500] max fitness: 2.0[K
[199/1500] max fitness: 2.0[K
[200/1500] max fitness: 2.0[K
[201/1500] max fitness: 2.0[K
[202/1500] max fitness: 2.0[K
[203/1500] max fitness: 2.0[K
[204/1500] max fitness: 2.0[K
[205/1500] max fitness: 2.0[K
[206/1500] max fitness: 2.0[K
[207/1500] max fitness: 2.0[K
[208/1500] max fitness: 2.0[K
[209/1500] max fitness: 2.0[K
[210/1500] max fitness: 2.0[K
[211/1500] max fitness: 2.0[K
[212/1500] max fitness: 2.0[K
[213/1500] max fitness: 2.0[K
[214/1500] max fitness: 2.0[K
[215/1500] max fitness: 2.0[K
[216/1500] max fitness: 2.0[K
[217/1500] max fitness: 2.0[K
[218/1500] max fitness: 2.0[K
[219/1500] max fitness: 2.0[K
[220/1500] max fitness: 2.0[K
[221/1500] max fitness: 2.0[K
[222/1500] max fitness: 2.0[K
[223/1500] max fitness: 2.0[K
[224/1500] max fitness: 2.0[K
[225/1500] max fitness: 2.0[K
[226/1500] max fitness: 2.0[K
[227/1500] max fitness: 2.0[K
[228/1500] max fitness: 2.0[K
[229/1500] max fitness: 2.0[K
[230/1500] max fitness: 2.0[K
[231/1500] max fitness: 2.0[K
[232/1500] max fitness: 2.0[K
[233/1500] max fitness: 2.0[K
[234/1500] max fitness: 2.0[K
[235/1500] max fitness: 2.0[K
[236/1500] max fitness: 2.0[K
[237/1500] max fitness: 2.0[K
[238/1500] max fitness: 2.0[K
[239/1500] max fitness: 2.0[K
[240/1500] max fitness: 2.0[K
[241/1500] max fitness: 2.0[K
[242/1500] max fitness: 2.0[K
[243/1500] max fitness: 2.0[K
[244/1500] max fitness: 2.0[K
[245/1500] max fitness: 2.0[K
[246/1500] max fitness: 2.0[K
[247/1500] max fitness: 2.0[K
[248/1500] max fitness: 2.0[K
[249/1500] max fitness: 2.0[K
[250/1500] max fitness: 2.0[K
[251/1500] max fitness: 2.0[K
[252/1500] max fitness: 2.0[K
[253/1500] max fitness: 2.0[K
[254/1500] max fitness: 2.0[K
[255/1500] max fitness: 2.0[K
[256/1500] max fitness: 2.0[K
[257/1500] max fitness: 2.0[K
[258/1500] max fitness: 2.0[K
[259/1500] max fitness: 2.0[K
[260/1500] max fitness: 2.0[K
[261/1500] max fitness: 2.0[K
[262/1500] max fitness: 2.0[K
[263/1500] max fitness: 2.0[K
[264/1500] max fitness: 2.0[K
[265/1500] max fitness: 2.0[K
[266/1500] max fitness: 2.0[K
[267/1500] max fitness: 2.0[K
[268/1500] max fitness: 2.0[K
[269/1500] max fitness: 2.0[K
[270/1500] max fitness: 2.0[K
[271/1500] max fitness: 2.0[K
[272/1500] max fitness: 2.0[K
[273/1500] max fitness: 2.0[K
[274/1500] max fitness: 2.0[K
[275/1500] max fitness: 2.0[K
[276/1500] max fitness: 2.0[K
[277/1500] max fitness: 2.0[K
[278/1500] max fitness: 2.0[K
[279/1500] max fitness: 2.0[K
[280/1500] max fitness: 2.0[K
[281/1500] max fitness: 2.0[K
[282/1500] max fitness: 2.0[K
[283/1500] max fitness: 2.0[K
[284/1500] max fitness: 2.0[K
[285/1500] max fitness: 2.0[K
[286/1500] max fitness: 2.0[K
[287/1500] max fitness: 2.0[K
[288/1500] max fitness: 2.0[K
[289/1500] max fitness: 2.0[K
[290/1500] max fitness: 2.0[K
[291/1500] max fitness: 2.0[K
[292/1500] max fitness: 2.0[K
[293/1500] max fitness: 2.0[K
[294/1500] max fitness: 2.0[K
[295/1500] max fitness: 2.0[K
[296/1500] max fitness: 2.0[K
[297/1500] max fitness: 2.0[K
[298/1500] max fitness: 2.0[K
[299/1500] max fitness: 2.0[K
[300/1500] max fitness: 2.0[K
[301/1500] max fitness: 2.0[K
[302/1500] max fitness: 2.0[K
[303/1500] max fitness: 2.0[K
[304/1500] max fitness: 2.0[K
[305/1500] max fitness: 2.0[K
[306/1500] max fitness: 2.0[K
[307/1500] max fitness: 2.0[K
[308/1500] max fitness: 2.0[K
[309/1500] max fitness: 2.0[K
[310/1500] max fitness: 2.0[K
[311/1500] max fitness: 2.0[K
[312/1500] max fitness: 2.0[K
[313/1500] max fitness: 2.0[K
[314/1500] max fitness: 2.0[K
[315/1500] max fitness: 2.0[K
[316/1500] max fitness: 2.0[K
[317/1500] max fitness: 2.0[K
[318/1500] max fitness: 2.0[K
[319/1500] max fitness: 2.0[K
[320/1500] max fitness: 2.0[K
[321/1500] max fitness: 2.0[K
[322/1500] max fitness: 2.0[K
[323/1500] max fitness: 2.0[K
[324/1500] max fitness: 2.0[K
[325/1500] max fitness: 2.0[K
[326/1500] max fitness: 2.0[K
[327/1500] max fitness: 2.0[K
[328/1500] max fitness: 2.0[K
[329/1500] max fitness: 2.0[K
[330/1500] max fitness: 2.0[K
[331/1500] max fitness: 2.0[K
[332/1500] max fitness: 2.0[K
[333/1500] max fitness: 2.0[K
[334/1500] max fitness: 2.0[K
[335/1500] max fitness: 2.0[K
[336/1500] max fitness: 2.0[K
[337/1500] max fitness: 2.0[K
[338/1500] max fitness: 2.0[K
[339/1500] max fitness: 2.0[K
[340/1500] max fitness: 2.0[K
[341/1500] max fitness: 2.0[K
[342/1500] max fitness: 2.0[K
[343/1500] max fitness: 2.0[K
[344/1500] max fitness: 2.0[K
[345/1500] max fitness: 2.0[K
[346/1500] max fitness: 2.0[K
[347/1500] max fitness: 2.0[K
[348/1500] max fitness: 2.0[K
[349/1500] max fitness: 2.0[K
[350/1500] max fitness: 2.0[K
[351/1500] max fitness: 2.0[K
[352/1500] max fitness: 2.0[K
[353/1500] max fitness: 2.0[K
[354/1500] max fitness: 2.0[K
[355/1500] max fitness: 2.0[K
[356/1500] max fitness: 2.0[K
[357/1500] max fitness: 2.0[K
[358/1500] max fitness: 2.0[K
[359/1500] max fitness: 2.0[K
[360/1500] max fitness: 2.0[K
[361/1500] max fitness: 2.0[K
[362/1500] max fitness: 2.0[K
[363/1500] max fitness: 2.0[K
[364/1500] max fitness: 2.0[K
[365/1500] max fitness: 2.0[K
[366/1500] max fitness: 2.0[K
[367/1500] max fitness: 2.0[K
[368/1500] max fitness: 2.0[K
[369/1500] max fitness: 2.0[K
[370/1500] max fitness: 2.0[K
[371/1500] max fitness: 2.0[K
[372/1500] max fitness: 2.0[K
[373/1500] max fitness: 2.0[K
[374/1500] max fitness: 2.0[K
[375/1500] max fitness: 2.0[K
[376/1500] max fitness: 2.0[K
[377/1500] max fitness: 2.0[K
[378/1500] max fitness: 2.0[K
[379/1500] max fitness: 2.0[K
[380/1500] max fitness: 2.0[K
[381/1500] max fitness: 2.0[K
[382/1500] max fitness: 2.0[K
[383/1500] max fitness: 2.0[K
[384/1500] max fitness: 2.0[K
[385/1500] max fitness: 2.0[K
[386/1500] max fitness: 2.0[K
[387/1500] max fitness: 2.0[K
[388/1500] max fitness: 2.0[K
[389/1500] max fitness: 2.0[K
[390/1500] max fitness: 2.0[K
[391/1500] max fitness: 2.0[K
[392/1500] max fitness: 2.0[K
[393/1500] max fitness: 2.0[K
[394/1500] max fitness: 2.0[K
[395/1500] max fitness: 2.0[K
[396/1500] max fitness: 2.0[K
[397/1500] max fitness: 2.0[K
[398/1500] max fitness: 2.0[K
[399/1500] max fitness: 2.0[K
[400/1500] max fitness: 2.0[K
[401/1500] max fitness: 2.0[K
[402/1500] max fitness: 2.0[K/opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/numpy/lib/function_base.py:3942: RuntimeWarning: invalid value encountered in multiply
x2 = take(ap, indices_above, axis=axis) * weights_above
[403/1500] max fitness: 2.0[K
[404/1500] max fitness: 2.0[K
[405/1500] max fitness: 2.0[K
[406/1500] max fitness: 2.0[K
[407/1500] max fitness: 2.0[K
[408/1500] max fitness: 2.0[K
[409/1500] max fitness: 2.0[K
[410/1500] max fitness: 2.0[K
[411/1500] max fitness: 2.0[K
[412/1500] max fitness: 2.0[K
[413/1500] max fitness: 2.0[K
[414/1500] max fitness: 2.0[K
[415/1500] max fitness: 2.0[K
[416/1500] max fitness: 2.0[K
[417/1500] max fitness: 2.0[K
[418/1500] max fitness: 2.0[K
[419/1500] max fitness: 2.0[K
[420/1500] max fitness: 2.0[K
[421/1500] max fitness: 2.0[K
[422/1500] max fitness: 2.0[K
[423/1500] max fitness: 2.0[K
[424/1500] max fitness: 2.0[K
[425/1500] max fitness: 2.0[K
[426/1500] max fitness: 2.0[K
[427/1500] max fitness: 2.0[K
[428/1500] max fitness: 2.0[K
[429/1500] max fitness: 2.0[K
[430/1500] max fitness: 2.0[K
[431/1500] max fitness: 2.0[K
[432/1500] max fitness: 2.0[K
[433/1500] max fitness: 2.0[K
[434/1500] max fitness: 2.0[K
[435/1500] max fitness: 2.0[K
[436/1500] max fitness: 2.0[K
[437/1500] max fitness: 2.0[K
[438/1500] max fitness: 2.0[K
[439/1500] max fitness: 2.0[K
[440/1500] max fitness: 102.55337700605139[K
evolution ended
solution with highest fitness: "9.0*dx/dt" (fitness: 102.55338)
average reward over 100 consecutive trials: 96.41038-> environment solved!
Total running time of the script: ( 0 minutes 18.822 seconds)