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 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
import functools
env = NRasterizedIncrementingAgent(
# agent = 4,
env = IntersimpleLidarFlat(
agent = 51,
n_rays=5,
reward=functools.partial(
speed_reward,
collision_penalty=1000
@@ -20,22 +21,23 @@ policy = IDMRulePolicy(env)
colliding_agents = []
for agent in range(151):
print("Start agent", agent)
obs = env.reset()
# for agent in range(151):
agent = env._agent
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')
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')
# print('step', i, 'reward', reward)
if done:
if reward < -500:
colliding_agents.append(agent)
print(" Collision")
break
env.close(filestr='idm/agent_{}'.format(agent))
# print('step', i, 'reward', reward)
if done:
if reward < -500:
colliding_agents.append(agent)
print(" Collision")
break
env.close(filestr='idm3/agent_{}'.format(agent))
print(len(colliding_agents), "colliding_agents")
print(colliding_agents)