-
Notifications
You must be signed in to change notification settings - Fork 4
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
Change _apply_rl_actions in green wave and added tests #42
Open
kjang96
wants to merge
3
commits into
berkeleyflow:master
Choose a base branch
from
kjang96:green_wave_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from flow.core.experiment import SumoExperiment | ||
from flow.controllers.routing_controllers import GridRouter | ||
from flow.controllers.car_following_models import IDMController | ||
from flow.envs.green_wave_env import PO_TrafficLightGridEnv | ||
|
||
os.environ["TEST_FLAG"] = "True" | ||
|
||
|
@@ -194,6 +195,45 @@ def test_k_closest(self): | |
self.assertTrue(self.env.vehicles.get_edge(veh_id) in c0_edges) | ||
|
||
|
||
def test_min_switch(self): | ||
# FOR THE PURPOSES OF THIS TEST, never set min switch to be < 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test enforce the constraint of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The setup script it uses has min_switch >=2, is that what you mean? |
||
|
||
# reset the environment | ||
self.env.reset() | ||
|
||
# Set up RL environment | ||
self.env = PO_TrafficLightGridEnv(self.env.env_params, | ||
self.env.sumo_params, | ||
self.env.scenario) | ||
|
||
for i in range(len(self.env.last_change)): | ||
self.assertEqual(self.env.last_change[i, 2], 1) | ||
|
||
# Run one step and make sure the count is incrementing | ||
self.env.step([1] * self.env.num_traffic_lights) | ||
for i in range(len(self.env.last_change)): | ||
self.assertEqual(self.env.last_change[i, 0], 1) | ||
self.assertEqual(self.env.last_change[i, 1], 0) | ||
self.assertEqual(self.env.last_change[i, 2], 1) | ||
|
||
# Run until green switches to yellow | ||
for i in range(int(self.env.min_green_time - 1.)): | ||
self.env.step([1] * self.env.num_traffic_lights) | ||
for i in range(len(self.env.last_change)): | ||
self.assertEqual(self.env.last_change[i, 0], 0) | ||
self.assertEqual(self.env.last_change[i, 1], 1) | ||
self.assertEqual(self.env.last_change[i, 2], 0) | ||
|
||
# Run until yellow switches to green | ||
for i in range(int(self.env.min_yellow_time)): | ||
self.env.step([1] * self.env.num_traffic_lights) | ||
|
||
for i in range(len(self.env.last_change)): | ||
self.assertEqual(self.env.last_change[i, 0], 0) | ||
self.assertEqual(self.env.last_change[i, 1], 1) | ||
self.assertEqual(self.env.last_change[i, 2], 1) | ||
|
||
|
||
class TestItRuns(unittest.TestCase): | ||
""" | ||
Tests the set_state function | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does
self.last_change
get incremented inside theelse
when it didn't before? (not too familiar with the green wave stuff though so I might just be missing something obvious)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.last_change used to only keep track of last change since a yellow phase began. Now it also keeps track of time since a green phase began. So now, last_change[i, 0] resets when the green phase begins (it didn't use to) and increments during the green phase as well.