Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
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
yoogottamk
Flatland
Commits
96f38175
Commit
96f38175
authored
5 years ago
by
Erik Nygren
Browse files
Options
Downloads
Patches
Plain Diff
updated example of Flatland 2.0 and minor changes to schedule generator
parent
8e8bd7ff
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/flatland_2_0_example.py
+13
-11
13 additions, 11 deletions
examples/flatland_2_0_example.py
flatland/envs/schedule_generators.py
+4
-1
4 additions, 1 deletion
flatland/envs/schedule_generators.py
with
17 additions
and
12 deletions
examples/flatland_2_0_example.py
+
13
−
11
View file @
96f38175
import
numpy
as
np
from
flatland.envs.rail_generators
import
sparse_rail_generator
from
flatland.envs.observations
import
TreeObsForRailEnv
from
flatland.envs.predictions
import
ShortestPathPredictorForRailEnv
from
flatland.envs.rail_env
import
RailEnv
from
flatland.envs.rail_generators
import
sparse_rail_generator
from
flatland.envs.schedule_generators
import
sparse_schedule_generator
from
flatland.utils.rendertools
import
RenderTool
...
...
@@ -13,17 +13,23 @@ np.random.seed(1)
# Training on simple small tasks is the best way to get familiar with the environment
# Use a the malfunction generator to break agents from time to time
stochastic_data
=
{
'
prop_malfunction
'
:
0.
5
,
# Percentage of defective agents
stochastic_data
=
{
'
prop_malfunction
'
:
0.
0
,
# Percentage of defective agents
'
malfunction_rate
'
:
30
,
# Rate of malfunction occurence
'
min_duration
'
:
3
,
# Minimal duration of malfunction
'
max_duration
'
:
10
# Max duration of malfunction
}
TreeObservation
=
TreeObsForRailEnv
(
max_depth
=
2
,
predictor
=
ShortestPathPredictorForRailEnv
())
env
=
RailEnv
(
width
=
20
,
height
=
20
,
rail_generator
=
sparse_rail_generator
(
num_cities
=
2
,
# Number of cities in map (where train stations are)
num_intersections
=
1
,
# Number of intersections (no start / target)
speed_ration_map
=
{
1.
:
0.1
,
# Fast passenger train
0.5
:
0.2
,
# Slow commuter train
0.25
:
0.2
,
# Fast freight train
0.125
:
0.5
}
# Slow freight train
env
=
RailEnv
(
width
=
50
,
height
=
50
,
rail_generator
=
sparse_rail_generator
(
num_cities
=
10
,
# Number of cities in map (where train stations are)
num_intersections
=
5
,
# Number of intersections (no start / target)
num_trainstations
=
15
,
# Number of possible start/targets on map
min_node_dist
=
3
,
# Minimal distance of nodes
node_radius
=
3
,
# Proximity of stations to city center
...
...
@@ -32,7 +38,7 @@ env = RailEnv(width=20,
realistic_mode
=
True
,
enhance_intersection
=
True
),
schedule_generator
=
sparse_schedule_generator
(),
schedule_generator
=
sparse_schedule_generator
(
speed_ration_map
),
number_of_agents
=
5
,
stochastic_data
=
stochastic_data
,
# Malfunction data generator
obs_builder_object
=
TreeObservation
)
...
...
@@ -83,10 +89,6 @@ action_dict = dict()
print
(
"
Start episode...
"
)
# Reset environment and get initial observations for all agents
obs
=
env
.
reset
()
# Update/Set agent's speed
for
idx
in
range
(
env
.
get_num_agents
()):
speed
=
1.0
/
((
idx
%
5
)
+
1.0
)
env
.
agents
[
idx
].
speed_data
[
"
speed
"
]
=
speed
# Reset the rendering sytem
env_renderer
.
reset
()
...
...
This diff is collapsed.
Click to expand it.
flatland/envs/schedule_generators.py
+
4
−
1
View file @
96f38175
...
...
@@ -60,7 +60,10 @@ def sparse_schedule_generator(speed_ratio_map: Mapping[float, float] = None) ->
def
generator
(
rail
:
GridTransitionMap
,
num_agents
:
int
,
hints
:
Any
=
None
):
train_stations
=
hints
[
'
train_stations
'
]
agent_start_targets_nodes
=
hints
[
'
agent_start_targets_nodes
'
]
num_agents
=
hints
[
'
num_agents
'
]
max_num_agents
=
hints
[
'
num_agents
'
]
if
num_agents
>
max_num_agents
:
num_agents
=
max_num_agents
warnings
.
warn
(
"
Too many agents! Changes number of agents.
"
)
# Place agents and targets within available train stations
agents_position
=
[]
agents_target
=
[]
...
...
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