Update scratch for plotting
This commit is contained in:
@@ -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,11 +21,12 @@ 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)
|
||||||
env.render(mode='post')
|
obs = env.reset()
|
||||||
for i in range(300):
|
env.render(mode='post')
|
||||||
|
for i in range(300):
|
||||||
action, _ = policy.predict(torch.tensor(obs))
|
action, _ = policy.predict(torch.tensor(obs))
|
||||||
# action = policy.sample(policy(torch.tensor(obs, dtype=torch.float32)))
|
# action = policy.sample(policy(torch.tensor(obs, dtype=torch.float32)))
|
||||||
obs, reward, done, _ = env.step(action)
|
obs, reward, done, _ = env.step(action)
|
||||||
@@ -35,7 +37,7 @@ for agent in range(151):
|
|||||||
colliding_agents.append(agent)
|
colliding_agents.append(agent)
|
||||||
print(" Collision")
|
print(" Collision")
|
||||||
break
|
break
|
||||||
env.close(filestr='idm/agent_{}'.format(agent))
|
env.close(filestr='idm3/agent_{}'.format(agent))
|
||||||
|
|
||||||
print(len(colliding_agents), "colliding_agents")
|
print(len(colliding_agents), "colliding_agents")
|
||||||
print(colliding_agents)
|
print(colliding_agents)
|
||||||
|
|||||||
Reference in New Issue
Block a user