Skip to content
Snippets Groups Projects
Commit 3ba970a0 authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

demo.py is no simply working

parent d1c6a975
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -132,39 +132,16 @@ class Demo:
handle = self.env.get_agent_handles()
return handle
def run_demo(self, max_nbr_of_steps=100):
def run_demo(self, max_nbr_of_steps=30):
action_dict = dict()
time_obs = deque(maxlen=2)
action_prob = [0] * 4
agent_obs = [None] * self.env.get_num_agents()
agent_next_obs = [None] * self.env.get_num_agents()
# Reset environment
obs = self.env.reset(False, False)
for a in range(self.env.get_num_agents()):
data, distance = self.env.obs_builder.split_tree(tree=np.array(obs[a]), num_features_per_node=5, current_depth=0)
data = norm_obs_clip(data)
distance = norm_obs_clip(distance)
obs[a] = np.concatenate((data, distance))
for i in range(2):
time_obs.append(obs)
# env.obs_builder.util_print_obs_subtree(tree=obs[0], num_elements_per_node=5)
for a in range(self.env.get_num_agents()):
agent_obs[a] = np.concatenate((time_obs[0][a], time_obs[1][a]))
for step in range(max_nbr_of_steps):
time.sleep(.2)
# print(step)
# Action
for a in range(self.env.get_num_agents()):
action = np.random.choice(self.action_size) #self.agent.act(agent_obs[a])
action_prob[action] += 1
action = 2 #np.random.choice(self.action_size) #self.agent.act(agent_obs[a])
action_dict.update({a: action})
print(action_dict)
......@@ -173,20 +150,7 @@ class Demo:
# Environment step
next_obs, all_rewards, done, _ = self.env.step(action_dict)
for a in range(self.env.get_num_agents()):
data, distance = self.env.obs_builder.split_tree(tree=np.array(next_obs[a]), num_features_per_node=5,
current_depth=0)
data = norm_obs_clip(data)
distance = norm_obs_clip(distance)
next_obs[a] = np.concatenate((data, distance))
# Update replay buffer and train agent
for a in range(self.env.get_num_agents()):
agent_next_obs[a] = np.concatenate((time_obs[0][a], time_obs[1][a]))
time_obs.append(next_obs)
agent_obs = agent_next_obs.copy()
if done['__all__']:
break
......
%% Cell type:markdown id: tags:
# Rail Editor v0.2
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Output
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
%% Cell type:code id: tags:
``` python
import numpy as np
from numpy import array
import ipywidgets
import IPython
from IPython.core.display import display, HTML
```
%% Cell type:code id: tags:
``` python
display(HTML("<style>.container { width:95% !important; }</style>"))
```
%% Output
%% Cell type:code id: tags:
``` python
from flatland.utils.editor import EditorMVC, EditorModel, View, Controller
```
%% Cell type:code id: tags:
``` python
mvc = EditorMVC(sGL="PIL" ) # sGL="PIL")
```
%% Output
%% Cell type:markdown id: tags:
## Instructions
- Drag to draw (improved dead-ends)
- Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them)
- ctrl-click to add agent
- direction chosen randomly to fit rail
- ctrl-shift-click to add target for last agent
- target can be moved by repeating
- to Resize the env (cannot preserve work):
- select "Regen" tab, set regen size slider, click regenerate.
%% Cell type:code id: tags:
``` python
mvc.view.display()
```
%% Output
%% Cell type:code id: tags:
``` python
mvc.view.wOutput.clear_output()
mvc.view.wOutput
```
%% Output
%% Cell type:code id: tags:
``` python
len(mvc.editor.env.agents), len(mvc.editor.env.agents_static)
```
%% Output
(0, 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment