Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Traffic Light Tutorial #642

Merged
merged 39 commits into from Aug 20, 2019
Merged

Improving Traffic Light Tutorial #642

merged 39 commits into from Aug 20, 2019

Conversation

ashkan-software
Copy link
Member

Pull request information

  • Status: ready to merge
  • Kind of changes: Cleaning
  • Related PR or issue: I don't know :)

Description

  • Improves the traffic light tutorial by
    -- Revising the tutorial
    -- Reordering of the sections
    -- Adding new sections for reward and apply_rl_actions
  • Fixes the small typo in the main README
  • Fixes the wrong comment in the green_wave_env

Revised Section 2 of the tutorial, and removed the incorrect description of the traffic light phase
@eugenevinitsky eugenevinitsky added this to 0.4.2 -- tutorials in Release 0.4 -> 0.5 Jul 22, 2019
@coveralls
Copy link

coveralls commented Aug 2, 2019

Pull Request Test Coverage Report for Build 4257

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 41 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.02%) to 91.964%

Files with Coverage Reduction New Missed Lines %
flow/envs/green_wave_env.py 1 85.0%
tests/fast_tests/test_environment_base_class.py 6 97.06%
flow/envs/base_env.py 34 74.52%
Totals Coverage Status
Change from base Build 4241: -0.02%
Covered Lines: 9178
Relevant Lines: 9980

💛 - Coveralls

@ashkan-software
Copy link
Member Author

This is ready to review and possibly merge @eugenevinitsky

@@ -102,9 +108,15 @@
"## 2. Defining Traffic Light Phases \n",
"\n",
"\n",
"To start off, we define how Sumo represents traffic light phases. A phase is defined as the states that the traffic lights around an intersection can take. The typical four-way, traffic-light-controlled intersection is modeled by a string of length 12. Consider the phase \"GrGr\". Every letter in this phase string (\"G\", \"r\", \"G\", \"r\") corresponds to an edge in the intersection, in clockwise order. Explicitly, the northern and southern edges of the intersection both have a state of \"G\", where the eastern and western edges of the intersection both have a state of \"r\". \n",
"To start off, we define how SUMO represents traffic light phases. A phase is defined as the states that the traffic lights around an intersection can take. The phase of a typical four-way, traffic-light-controlled intersection is modeled by a string (of length 4, 8, or 12, etc., depending on the type of the signal). \n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'depending on the structure of the intersection' not the type of the signal

"Once the TrafficLightParams class is instantiated, traffic lights can be added via the classes' `add` function. One prerequisite of using this function is knowing the node id of any node you intend to manipulate. This information is baked into the experiment's scenario class, as well as the experiment's nod.xml file. For the experiment we are using with 2 rows and 3 columns, there are 6 nodes: \"center0\" to \"center5\".\n",
"\n",
"In this particular example, each of the 6 traffic light nodes corresponds to the same set of possible phases; in other words, at any time, each node will be at the same phase. You can, however, customize each traffic light node to have different phases."
"Once the `TrafficLightParams` class is instantiated, traffic lights can be added via the `add` function. One prerequisite of using this function is knowing the node id of any node you intend to manipulate. This information is baked into the experiment's scenario class, as well as the experiment's `nod.xml` file. For the experiment we are using with 2 rows and 3 columns, there are 6 nodes: \"center0\" to \"center5\"."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: node.xml I think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you describe the relative ordering of the nodes e.g. center0 is the bottom left, center2 is the bottom right, etc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually nod.xml

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Following this step, the TrafficLightParams class should be passed into your scenario as element `traffic_lights`."
"In this particular example, each of the 6 intersections corresponds to the same set of possible phases; in other words, at any time, all intersections will be at the same phase. You can, however, customize each traffic light node to have different phases."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tiny bit hard to parse. I think it is important to make clearer that this is only true for this specific example, and not for the grid in general.

@@ -266,24 +240,24 @@
"source": [
"For more flexibility than the static traffic lights defined above, and more control than RL-controlled traffic lights, actuated traffic lights are a good option to consider.\n",
"\n",
"As an excerpt from Sumo's documentation: \"SUMO supports gap-based actuated traffic control This control scheme is common in Germany and works by prolonging traffic phases whenever a continuous stream of traffic is detected. It switches to the next phase after detecting a sufficent time gap between sucessive vehicles. This allows for better distribution of green-time among phases and also affects cycle duration in response to dynamic traffic conditions.\""
"To explain the actuated traffic ligjts, we refer to an excerpt from SUMO's documentation: \"SUMO supports gap-based actuated traffic control. This control scheme is common in Germany and works by prolonging traffic phases whenever a continuous stream of traffic is detected. It switches to the next phase after detecting a sufficent time gap between sucessive vehicles. This allows for better distribution of green-time among phases and also affects cycle duration in response to dynamic traffic conditions.\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: lights

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The difference between phases for static and actuated traffic lights is that actuated traffic light phases take in two additional parameters, `minDur` and `maxDur`, which describe the allowed range of time durations for each phase.\n",
"The difference between phases for static and actuated traffic lights is that actuated traffic light has two additional parameters in `phases`, namely `minDur` and `maxDur`, which describe the allowed range of time durations for each phase.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add that minDur is how long the phase will at least be held for, and that it will be held no longer than maxDur?

"To control traffic lights via RL, no `tl_logic` element is necessary. This is because rllab is controlling all the parameters you were able to customize in the prior sections. Your `additional_net_params` should look something like this: "
"This is where we switch from the non-RL experiment script to the RL experiment. \n",
"\n",
"To control traffic lights via RL, no `tl_logic` element is necessary. This is because rllib is controlling all the parameters you were able to customize in the prior sections. The `additional_net_params` should look something like this: "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, don't think we should hardcode in RLlib. I think it's better to say that the RL agent is controlling the parameters.

@@ -355,7 +383,7 @@
"self.last_change = np.zeros((self.rows * self.cols, 1))\n",
"# keeps track of the direction of the intersection (the direction that is currently being allowed to flow. 0 indicates flow from top to bottom, and 1 indicates flow from left to right.)\n",
"self.direction = np.zeros((self.rows * self.cols, 1))\n",
"# value of 0 indicates that the intersection is in a red-yellow state. 1 indicates that the intersection is in a red-green state.\n",
"# value of 1 indicates that the intersection is in a red-yellow state. 0 indicates that the intersection is in a red-green state.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's not clear what a red-yellow state is. You mean rYrY right? I think this is held over text so it's not your mistake but I think it's sort of unclear what it means.

"cell_type": "markdown",
"metadata": {},
"source": [
"In the case that the action space is discrete, we need 1-bit (that can be 0 or 1) for the action of each traffic light node. Hence, we need `self.num_traffic_lights` bits to represent the action spacs. To make a `self.num_traffic_lights`-bit number, we use the pyhton's `Discrete(range)`, and since we have `self.num_traffic_lights` bits, the `range` will be 2^`self.num_traffic_lights`.\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: action space

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Observation Space"
"#### Observation Space"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it's not each vehicle, it's the N closest vehicles on each edge I think?

Copy link
Member

@eugenevinitsky eugenevinitsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM minus comments and the merge conflict.

@ashkan-software
Copy link
Member Author

I addressed all your concerns @eugenevinitsky! Thanks!

@ashkan-software ashkan-software merged commit 69ac244 into master Aug 20, 2019
Release 0.4 -> 0.5 automation moved this from 0.4.1 -- tutorials to Done! Aug 20, 2019
@AboudyKreidieh AboudyKreidieh deleted the ashkan-development branch October 24, 2019 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants