Update scratch for plotting

This commit is contained in:
Johannes Fischer
2022-03-01 09:57:36 +01:00
parent fa0e20998d
commit 2965dc9982

View File

@@ -3,13 +3,14 @@ import torch
from src.baselines.rule_policies import IDMRulePolicy from src.baselines.rule_policies import IDMRulePolicy
from tqdm import tqdm from tqdm import tqdm
from intersim.envs import NRasterizedIncrementingAgent, NRasterizedRandomAgent, NRasterized from intersim.envs import NRasterizedIncrementingAgent, NRasterizedRandomAgent, NRasterized,IntersimpleLidarFlat
from intersim.envs.intersimple import speed_reward from intersim.envs.intersimple import speed_reward
import functools import functools
env = NRasterizedIncrementingAgent( env = IntersimpleLidarFlat(
# agent = 4, agent = 51,
n_rays=5,
reward=functools.partial( reward=functools.partial(
speed_reward, speed_reward,
collision_penalty=1000 collision_penalty=1000
@@ -20,22 +21,23 @@ policy = IDMRulePolicy(env)
colliding_agents = [] colliding_agents = []
for agent in range(151): # for agent in range(151):
print("Start agent", agent) agent = env._agent
obs = env.reset() print("Start agent", agent)
obs = env.reset()
env.render(mode='post')
for i in range(300):
action, _ = policy.predict(torch.tensor(obs))
# action = policy.sample(policy(torch.tensor(obs, dtype=torch.float32)))
obs, reward, done, _ = env.step(action)
env.render(mode='post') env.render(mode='post')
for i in range(300): # print('step', i, 'reward', reward)
action, _ = policy.predict(torch.tensor(obs)) if done:
# action = policy.sample(policy(torch.tensor(obs, dtype=torch.float32))) if reward < -500:
obs, reward, done, _ = env.step(action) colliding_agents.append(agent)
env.render(mode='post') print(" Collision")
# print('step', i, 'reward', reward) break
if done: env.close(filestr='idm3/agent_{}'.format(agent))
if reward < -500:
colliding_agents.append(agent)
print(" Collision")
break
env.close(filestr='idm/agent_{}'.format(agent))
print(len(colliding_agents), "colliding_agents") print(len(colliding_agents), "colliding_agents")
print(colliding_agents) print(colliding_agents)