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
pranjal_dhole
Flatland
Commits
5c8f9fe6
Commit
5c8f9fe6
authored
5 years ago
by
Egli Adrian (IT-SCI-API-PFI)
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
ssh://gitlab.aicrowd.com/flatland/flatland
parents
db3a7c31
9cdfef4c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/training_example.py
+9
-6
9 additions, 6 deletions
examples/training_example.py
with
9 additions
and
6 deletions
examples/training_example.py
+
9
−
6
View file @
5c8f9fe6
...
...
@@ -12,7 +12,6 @@ env = RailEnv(width=15,
rail_generator
=
complex_rail_generator
(
nr_start_goal
=
10
,
nr_extra
=
10
,
min_dist
=
10
,
max_dist
=
99999
,
seed
=
0
),
number_of_agents
=
5
)
# Import your own Agent or use RLlib to train agents on Flatland
# As an example we use a random agent here
...
...
@@ -39,14 +38,17 @@ class RandomAgent:
"""
return
def
save
(
self
):
def
save
(
self
,
filename
):
# Store the current policy
return
def
load
(
self
,
filename
):
# Load a policy
return
# Initialize the agent with the parameters corresponding to the environment and observation_builder
agent
=
RandomAgent
(
218
,
4
)
n_trials
=
1000
n_trials
=
5
# Empty dictionary for all agent action
action_dict
=
dict
()
...
...
@@ -71,11 +73,12 @@ for trials in range(1, n_trials + 1):
next_obs
,
all_rewards
,
done
,
_
=
env
.
step
(
action_dict
)
# Update replay buffer and train agent
agent
.
step
((
obs
[
a
],
action_dict
[
a
],
all_rewards
[
a
],
next_obs
[
a
],
done
[
a
]))
score
+=
all_rewards
[
a
]
for
a
in
range
(
env
.
get_num_agents
()):
agent
.
step
((
obs
[
a
],
action_dict
[
a
],
all_rewards
[
a
],
next_obs
[
a
],
done
[
a
]))
score
+=
all_rewards
[
a
]
obs
=
next_obs
.
copy
()
if
done
[
'
__all__
'
]:
break
print
(
'
Episode Nr. {}
'
.
format
(
trials
))
print
(
'
Episode Nr.
{}
\t
Score =
{}
'
.
format
(
trials
,
score
))
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