-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from jerryz123/traffic_cam
Traffic light support
- Loading branch information
Showing
24 changed files
with
257 additions
and
70 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from gym_urbandriving.assets import TrafficLight | ||
|
||
class TrafficLightAgent: | ||
""" | ||
Agent for controlling traffic one traffic light. | ||
Attributes: | ||
----------- | ||
g_d : Duration of green light, in ticks | ||
r_d : Duration of red light, in ticks | ||
y_d : Duration of yellow light, in ticks | ||
g_d + y_d == r_d | ||
""" | ||
transitions = {"green":"yellow", | ||
"yellow":"red", | ||
"red":"green"} | ||
def __init__(self, agentnum=0, g_d=100, y_d=20, r_d=120): | ||
assert(g_d + y_d == r_d) | ||
self.color_times = {"green":g_d, | ||
"yellow":y_d, | ||
"red":r_d} | ||
self.agentnum = agentnum | ||
|
||
def eval_policy(self, state): | ||
obj = state.dynamic_objects[self.agentnum] | ||
assert(type(obj) == TrafficLight) | ||
if obj.time_in_color < self.color_times[obj.color]: | ||
return None | ||
return self.transitions[obj.color] | ||
|
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
Oops, something went wrong.