From 2c9e8f12130493e21b00a52f812475ba00107b19 Mon Sep 17 00:00:00 2001 From: dds0117 <965040559@qq.com> Date: Mon, 29 Mar 2021 16:06:25 +0200 Subject: [PATCH] The environmen is finished. --- simzoo/envs/cart_pole/CartPole.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/simzoo/envs/cart_pole/CartPole.py b/simzoo/envs/cart_pole/CartPole.py index 74b7580d..4282f86b 100644 --- a/simzoo/envs/cart_pole/CartPole.py +++ b/simzoo/envs/cart_pole/CartPole.py @@ -390,12 +390,12 @@ def COST_V2(r1, r2, e1, e2, x, x_dot, theta, theta_dot): env = CartPoleCustom() # Take T steps in the environment - T = 60000 + T = 1000 path = [] t1 = [] s = env.reset() print(f"Taking {T} steps in the Cartpole environment.") - for i in range(int(T / env.dt)): + for i in range(T): action = ( env.np_random.uniform( env.action_space.low, env.action_space.high, env.action_space.shape @@ -404,24 +404,20 @@ def COST_V2(r1, r2, e1, e2, x, x_dot, theta, theta_dot): else np.zeros(env.action_space.shape) ) s, r, done, info = env.step(action) + env.render() path.append(s) - t1.append(i * env.dt) + t1.append(i) print("Finished Cartpole environment simulation.") # Plot results print("Plot results.") fig = plt.figure(figsize=(9, 6)) ax = fig.add_subplot(111) - # ax.plot(t1, np.array(path)[:, 0], color="orange", label="mRNA1") - # ax.plot(t1, np.array(path)[:, 1], color="magenta", label="mRNA2") - # ax.plot(t1, np.array(path)[:, 2], color="sienna", label="mRNA3") - ax.plot(t1, np.array(path)[:, 3], color="blue", label="protein1") - # ax.plot(t1, np.array(path)[:, 4], color="cyan", label="protein2") - # ax.plot(t1, np.array(path)[:, 5], color="green", label="protein3") - # ax.plot(t1, np.array(path)[:, 0:3], color="blue", label="mRNA") - # ax.plot(t1, np.array(path)[:, 3:6], color="blue", label="protein") - ax.plot(t1, np.array(path)[:, 6], color="yellow", label="reference") - ax.plot(t1, np.array(path)[:, 7], color="red", label="error") + ax.plot(t1, np.array(path)[:, 0], color="orange", label="x") + ax.plot(t1, np.array(path)[:, 1], color="magenta", label="x_dot") + ax.plot(t1, np.array(path)[:, 2], color="sienna", label="theta") + ax.plot(t1, np.array(path)[:, 3], color="blue", label=" theat_dot1") + handles, labels = ax.get_legend_handles_labels() ax.legend(handles, labels, loc=2, fancybox=False, shadow=False) plt.show()