Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
baselines
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Flatland
baselines
Commits
dc738d78
Commit
dc738d78
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated prediction length in shortestpathpredictor
parent
e4c43e71
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
torch_training/multi_agent_inference.py
+6
-4
6 additions, 4 deletions
torch_training/multi_agent_inference.py
torch_training/predictors/predictions.py
+5
-1
5 additions, 1 deletion
torch_training/predictors/predictions.py
with
11 additions
and
5 deletions
torch_training/multi_agent_inference.py
+
6
−
4
View file @
dc738d78
...
@@ -17,11 +17,14 @@ from utils.observation_utils import normalize_observation
...
@@ -17,11 +17,14 @@ from utils.observation_utils import normalize_observation
random
.
seed
(
3
)
random
.
seed
(
3
)
np
.
random
.
seed
(
2
)
np
.
random
.
seed
(
2
)
tree_depth
=
3
observation_helper
=
TreeObsForRailEnv
(
max_depth
=
tree_depth
,
predictor
=
ShortestPathPredictorForRailEnv
(
10
))
file_name
=
"
./railway/simple_avoid.pkl
"
file_name
=
"
./railway/simple_avoid.pkl
"
env
=
RailEnv
(
width
=
10
,
env
=
RailEnv
(
width
=
10
,
height
=
20
,
height
=
20
,
rail_generator
=
rail_from_file
(
file_name
),
rail_generator
=
rail_from_file
(
file_name
),
obs_builder_object
=
TreeObsForRailEnv
(
max_depth
=
3
,
predictor
=
ShortestPathPredictorForRailEnv
())
)
obs_builder_object
=
observation_helper
)
x_dim
=
env
.
width
x_dim
=
env
.
width
y_dim
=
env
.
height
y_dim
=
env
.
height
...
@@ -38,13 +41,12 @@ env = RailEnv(width=x_dim,
...
@@ -38,13 +41,12 @@ env = RailEnv(width=x_dim,
rail_generator=complex_rail_generator(nr_start_goal=n_goals, nr_extra=2, min_dist=min_dist,
rail_generator=complex_rail_generator(nr_start_goal=n_goals, nr_extra=2, min_dist=min_dist,
max_dist=99999,
max_dist=99999,
seed=0),
seed=0),
obs_builder_object=
TreeObsForRailEnv(max_depth=3, predictor=ShortestPathPredictorForRailEnv())
,
obs_builder_object=
observation_helper
,
number_of_agents=n_agents)
number_of_agents=n_agents)
env.reset(True, True)
env.reset(True, True)
"""
"""
tree_depth
=
3
observation_helper
=
TreeObsForRailEnv
(
max_depth
=
tree_depth
,
predictor
=
ShortestPathPredictorForRailEnv
())
env_renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
)
env_renderer
=
RenderTool
(
env
,
gl
=
"
PILSVG
"
,
)
handle
=
env
.
get_agent_handles
()
handle
=
env
.
get_agent_handles
()
num_features_per_node
=
env
.
obs_builder
.
observation_dim
num_features_per_node
=
env
.
obs_builder
.
observation_dim
...
...
This diff is collapsed.
Click to expand it.
torch_training/predictors/predictions.py
+
5
−
1
View file @
dc738d78
...
@@ -8,7 +8,6 @@ from flatland.core.env_prediction_builder import PredictionBuilder
...
@@ -8,7 +8,6 @@ from flatland.core.env_prediction_builder import PredictionBuilder
from
flatland.core.grid.grid4_utils
import
get_new_position
from
flatland.core.grid.grid4_utils
import
get_new_position
from
flatland.envs.rail_env
import
RailEnvActions
from
flatland.envs.rail_env
import
RailEnvActions
class
ShortestPathPredictorForRailEnv
(
PredictionBuilder
):
class
ShortestPathPredictorForRailEnv
(
PredictionBuilder
):
"""
"""
ShortestPathPredictorForRailEnv object.
ShortestPathPredictorForRailEnv object.
...
@@ -17,6 +16,9 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
...
@@ -17,6 +16,9 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
The prediction acts as if no other agent is in the environment and always takes the forward action.
The prediction acts as if no other agent is in the environment and always takes the forward action.
"""
"""
def
__init__
(
self
,
max_depth
):
self
.
max_depth
=
max_depth
def
get
(
self
,
custom_args
=
None
,
handle
=
None
):
def
get
(
self
,
custom_args
=
None
,
handle
=
None
):
"""
"""
Called whenever get_many in the observation build is called.
Called whenever get_many in the observation build is called.
...
@@ -54,6 +56,7 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
...
@@ -54,6 +56,7 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
prediction
=
np
.
zeros
(
shape
=
(
self
.
max_depth
+
1
,
5
))
prediction
=
np
.
zeros
(
shape
=
(
self
.
max_depth
+
1
,
5
))
prediction
[
0
]
=
[
0
,
*
_agent_initial_position
,
_agent_initial_direction
,
0
]
prediction
[
0
]
=
[
0
,
*
_agent_initial_position
,
_agent_initial_direction
,
0
]
visited
=
set
()
visited
=
set
()
for
index
in
range
(
1
,
self
.
max_depth
+
1
):
for
index
in
range
(
1
,
self
.
max_depth
+
1
):
# if we're at the target, stop moving...
# if we're at the target, stop moving...
if
agent
.
position
==
agent
.
target
:
if
agent
.
position
==
agent
.
target
:
...
@@ -100,4 +103,5 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
...
@@ -100,4 +103,5 @@ class ShortestPathPredictorForRailEnv(PredictionBuilder):
# cleanup: reset initial position
# cleanup: reset initial position
agent
.
position
=
_agent_initial_position
agent
.
position
=
_agent_initial_position
agent
.
direction
=
_agent_initial_direction
agent
.
direction
=
_agent_initial_direction
return
prediction_dict
return
prediction_dict
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment