-
Notifications
You must be signed in to change notification settings - Fork 4
added outflow test MERGE BLOCKED BY KATHY #62
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,51 +290,6 @@ def _split_edge(self, edge): | |
else: | ||
return 0 | ||
|
||
def additional_command(self): | ||
"""Used to insert vehicles that are on the exit edge and place them | ||
back on their entrance edge.""" | ||
for veh_id in self.vehicles.get_ids(): | ||
self._reroute_if_final_edge(veh_id) | ||
|
||
def _reroute_if_final_edge(self, veh_id): | ||
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. same as above |
||
"""Checks if an edge is the final edge. If it is return the route it | ||
should start off at.""" | ||
edge = self.vehicles.get_edge(veh_id) | ||
if edge == "": | ||
return | ||
if edge[0] == ":": # center edge | ||
return | ||
pattern = re.compile(r"[a-zA-Z]+") | ||
edge_type = pattern.match(edge).group() | ||
edge = edge.split(edge_type)[1].split('_') | ||
row_index, col_index = [int(x) for x in edge] | ||
|
||
# find the route that we're going to place the vehicle on if we are | ||
# going to remove it | ||
route_id = None | ||
if edge_type == 'bot' and col_index == self.cols: | ||
route_id = "bot{}_0".format(row_index) | ||
elif edge_type == 'top' and col_index == 0: | ||
route_id = "top{}_{}".format(row_index, self.cols) | ||
elif edge_type == 'left' and row_index == 0: | ||
route_id = "left{}_{}".format(self.rows, col_index) | ||
elif edge_type == 'right' and row_index == self.rows: | ||
route_id = "right0_{}".format(col_index) | ||
|
||
if route_id is not None: | ||
route_id = "route" + route_id | ||
# remove the vehicle | ||
self.traci_connection.vehicle.remove(veh_id) | ||
# reintroduce it at the start of the network | ||
type_id = self.vehicles.get_state(veh_id, "type") | ||
lane_index = self.vehicles.get_lane(veh_id) | ||
self.traci_connection.vehicle.addFull( | ||
veh_id, route_id, typeID=str(type_id), | ||
departLane=str(lane_index), | ||
departPos="0", departSpeed="max") | ||
speed_mode = self.vehicles.type_parameters[type_id]["speed_mode"] | ||
self.traci_connection.vehicle.setSpeedMode(veh_id, speed_mode) | ||
|
||
def k_closest_to_intersection(self, edges, k): | ||
""" | ||
Return the veh_id of the k closest vehicles to an intersection for | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ def test_collide(self): | |
|
||
def test_collide_inflows(self): | ||
"""Tests collisions in the presence of inflows.""" | ||
# create the environment and scenario classes for a ring road | ||
# create the environment and scenario classes for a 1x1 grid | ||
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. nice catch |
||
sumo_params = SumoParams(sim_step=1, sumo_binary="sumo") | ||
total_vehicles = 12 | ||
vehicles = Vehicles() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,16 @@ | |
import numpy as np | ||
|
||
from flow.core.vehicles import Vehicles | ||
from flow.core.params import SumoCarFollowingParams, NetParams, InitialConfig | ||
from flow.core.params import SumoCarFollowingParams, NetParams, InitialConfig \ | ||
, SumoParams, InFlows | ||
from flow.controllers.car_following_models import IDMController, \ | ||
SumoCarFollowingController | ||
from flow.controllers.lane_change_controllers import StaticLaneChanger | ||
from flow.controllers.rlcontroller import RLController | ||
from flow.core.experiment import SumoExperiment | ||
from flow.controllers.routing_controllers import GridRouter | ||
from tests.setup_scripts import ring_road_exp_setup, grid_mxn_exp_setup | ||
|
||
from tests.setup_scripts import ring_road_exp_setup | ||
|
||
os.environ["TEST_FLAG"] = "True" | ||
|
||
|
@@ -232,17 +235,17 @@ def tearDown(self): | |
self.env.terminate() | ||
self.env = None | ||
|
||
def runTest(self): | ||
def test_ids_by_edge(self): | ||
self.env.reset() | ||
ids = self.env.vehicles.get_ids_by_edge("bottom") | ||
expected_ids = ["test_0", "test_1", "test_2", "test_3", "test_4"] | ||
self.assertCountEqual(ids, expected_ids) | ||
self.assertListEqual(sorted(ids), sorted(expected_ids)) | ||
|
||
|
||
class TestObservedIDs(unittest.TestCase): | ||
"""Tests the observed_ids methods, which are used for visualization.""" | ||
|
||
def run_test(self): | ||
def test_obs_ids(self): | ||
vehicles = Vehicles() | ||
vehicles.add(veh_id="test", num_vehicles=10) | ||
|
||
|
@@ -261,13 +264,97 @@ def run_test(self): | |
|
||
# test removing observed values | ||
vehicles.remove_observed("test_0") | ||
self.assertCountEqual(vehicles.get_observed_ids(), ["test_1"]) | ||
self.assertListEqual(vehicles.get_observed_ids(), ["test_1"]) | ||
|
||
# ensures that removing a value that does not exist does not lead to | ||
# an error | ||
vehicles.remove_observed("test_0") | ||
self.assertCountEqual(vehicles.get_observed_ids(), ["test_1"]) | ||
|
||
class TestOutflowInfo(unittest.TestCase): | ||
"""Tests that the out methods return the correct values""" | ||
def test_inflows(self): | ||
vehicles = Vehicles() | ||
self.assertEqual(0, vehicles.get_outflow_rate(10000), | ||
"outflow should be zero when there are no vehicles") | ||
|
||
# now construct a scenario where a vehicles is going to leave | ||
# create the environment and scenario classes for a 1x1 grid | ||
|
||
sumo_params = SumoParams(sim_step=1, sumo_binary="sumo") | ||
total_vehicles = 4 | ||
vehicles = Vehicles() | ||
vehicles.add(veh_id="krauss", | ||
acceleration_controller=(RLController, {}), | ||
routing_controller=(GridRouter, {}), | ||
num_vehicles=total_vehicles, | ||
speed_mode="all_checks") | ||
grid_array = {"short_length": 30, "inner_length": 30, | ||
"long_length": 30, "row_num": 1, | ||
"col_num": 1, | ||
"cars_left": 1, | ||
"cars_right": 1, | ||
"cars_top": 1, | ||
"cars_bot": 1} | ||
|
||
additional_net_params = {"speed_limit": 35, "grid_array": grid_array, | ||
"horizontal_lanes": 1, "vertical_lanes": 1} | ||
|
||
net_params = NetParams(no_internal_links=False, | ||
additional_params=additional_net_params) | ||
|
||
self.env, self.scenario = grid_mxn_exp_setup(row_num=1, col_num=1, | ||
sumo_params=sumo_params, | ||
vehicles=vehicles, | ||
net_params=net_params) | ||
|
||
# go through the env and set all the lights to green | ||
for i in range(self.env.rows * self.env.cols): | ||
self.env.traci_connection.trafficlight.setRedYellowGreenState( | ||
'center' + str(i), "gggrrrgggrrr") | ||
|
||
|
||
# instantiate an experiment class | ||
self.exp = SumoExperiment(self.env, self.scenario) | ||
|
||
self.exp.run(1, 15) | ||
|
||
# test outflow rate | ||
self.assertAlmostEqual(2*3600.0/15.0, vehicles.get_outflow_rate(100)) | ||
|
||
# test get num arrived | ||
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. are these coming later? 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. Yeah, just filled them out for future |
||
|
||
# test get initial speed | ||
|
||
# test get speed | ||
|
||
# test get position | ||
|
||
# test get edge | ||
|
||
# test get lane | ||
|
||
# test get/set length | ||
|
||
# test get_acc_controller | ||
|
||
# test get_lane_changing_controller | ||
|
||
# test get_routing_controller | ||
|
||
# test get_route | ||
|
||
# test get_leader | ||
|
||
# test get_follower | ||
|
||
# test get_lane_headways | ||
|
||
# test get_lane_leaders | ||
|
||
# test get_lane_tailways | ||
|
||
# test get_lane_followers | ||
|
||
if __name__ == '__main__': | ||
if __name__=='__main__': | ||
unittest.main() |
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.
did you mean to delete this? it's not mentioned in the overview or the commits
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.
Yeah, that's why this is blocked. Can we just leave this PR open and I'll move it later?