From bd04fc9ebe3e3ee012a13e175735f964eab08e4a Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Sun, 5 May 2019 09:36:05 -0700 Subject: [PATCH 1/9] added a new method for plotting time space diagrams --- flow/visualize/time_space_diagram.py | 507 +++++++++++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 flow/visualize/time_space_diagram.py diff --git a/flow/visualize/time_space_diagram.py b/flow/visualize/time_space_diagram.py new file mode 100644 index 000000000..873b9b1f0 --- /dev/null +++ b/flow/visualize/time_space_diagram.py @@ -0,0 +1,507 @@ +"""Generate a time space diagram for some networks. + +This method accepts as input a csv file containing the sumo-formatted emission +file, and then uses this data to generate a time-space diagram, with the x-axis +being the time (in seconds), the y-axis being the position of a vehicle, and +color representing the speed of te vehicles. + +If the number of simulation steps is too dense, you can plot every nth step in +the plot by setting the input `--steps=n`. + +Note: This script assumes that the provided network has only one lane on the +each edge, or one lane on the main highway in the case of MergeScenario. + +Usage +----- +:: + python time_space_diagram.py .csv .json +""" +from flow.utils.rllib import get_flow_params +import csv +from matplotlib import pyplot as plt +from matplotlib.collections import LineCollection +import matplotlib.colors as colors +import numpy as np +import argparse + +# scenarios that can be plotted by this method +ACCEPTABLE_SCENARIOS = [ + 'LoopScenario', + 'Figure8Scenario', + 'MergeScenario', +] + + +def import_data_from_emission(fp): + """Import relevant data from the predefined emission (.csv) file. + + Parameters + ---------- + fp : str + file path (for the .csv formatted file) + + Returns + ------- + dict of dict + Key = "veh_id": name of the vehicle \n Elements: + + * "time": time step at every sample + * "edge": edge ID at every sample + * "pos": relative position at every sample + * "vel": speed at every sample + """ + # initialize all output variables + veh_id, t, edge, rel_pos, vel = [], [], [], [], [] + + # import relevant data from emission file + for record in csv.DictReader(open(fp)): + veh_id.append(record['id']) + t.append(record['time']) + edge.append(record['edge_id']) + rel_pos.append(record['relative_position']) + vel.append(record['speed']) + + # we now want to separate data by vehicle ID + ret = {key: {'time': [], 'edge': [], 'pos': [], 'vel': []} + for key in np.unique(veh_id)} + for i in range(len(veh_id)): + ret[veh_id[i]]['time'].append(float(t[i])) + ret[veh_id[i]]['edge'].append(edge[i]) + ret[veh_id[i]]['pos'].append(float(rel_pos[i])) + ret[veh_id[i]]['vel'].append(float(vel[i])) + + return ret + + +def get_time_space_data(data, params): + """Compute the unique inflows and subsequent outflow statistics. + + Parameters + ---------- + data : dict of dict + Key = "veh_id": name of the vehicle \n Elements: + + * "time": time step at every sample + * "edge": edge ID at every sample + * "pos": relative position at every sample + * "vel": speed at every sample + params : dict + flow-specific parameters, including: + + * "scenario" (str): name of the scenario that was used when generating + the emission file. Must be one of the scenario names mentioned in + ACCEPTABLE_SCENARIOS, + * "net_params" (flow.core.params.NetParams): network-specific + parameters. This is used to collect the lengths of various network + links. + + Returns + ------- + as_array + n_steps x n_veh matrix specifying the absolute position of every + vehicle at every time step. Set to zero if the vehicle is not present + in the network at that time step. + as_array + n_steps x n_veh matrix specifying the speed of every vehicle at every + time step. Set to zero if the vehicle is not present in the network at + that time step. + + Raises + ------ + AssertionError + if the specified scenario is not supported by this method + """ + # check that the scenario is appropriate + assert params['scenario'] in ACCEPTABLE_SCENARIOS, \ + 'Scenario must be one of: ' + ', '.join(ACCEPTABLE_SCENARIOS) + + # switcher used to compute the positions based on the type of scenario + switcher = { + 'LoopScenario': _ring_road, + 'MergeScenario': _merge, + 'Figure8Scenario': _figure_eight + } + + # simulation step size + dt = flow_params['sim'].sim_step + + # number of simulation steps + max_time = max(max(data[veh_id]['time']) for veh_id in data.keys()) + min_time = min(min(data[veh_id]['time']) for veh_id in data.keys()) + num_steps = int((max_time - min_time)/dt) + 1 + + # Get the function from switcher dictionary + func = switcher[params['scenario']] + + # Execute the function + return func(data, params, dt, num_steps) + + +def _merge(data, params, dt, num_steps): + """Generate position and speed data for the merge. + + This only include vehicles on the main highway, and not on the adjacent + on-ramp. + + Parameters + ---------- + data : dict of dict + Key = "veh_id": name of the vehicle \n Elements: + + * "time": time step at every sample + * "edge": edge ID at every sample + * "pos": relative position at every sample + * "vel": speed at every sample + params : dict + flow-specific parameters + dt : float + simulation step size + num_steps : int + number of simulation steps + + Returns + ------- + as_array + n_steps x n_veh matrix specifying the absolute position of every + vehicle at every time step. Set to zero if the vehicle is not present + in the network at that time step. + as_array + n_steps x n_veh matrix specifying the speed of every vehicle at every + time step. Set to zero if the vehicle is not present in the network at + that time step. + """ + # import network data from flow params + inflow_edge_len = 100 + premerge = params['net'].additional_params['pre_merge_length'] + postmerge = params['net'].additional_params['post_merge_length'] + + # generate edge starts + edgestarts = { + "inflow_highway": 0, + "left": inflow_edge_len + 0.1, + "center": inflow_edge_len + premerge + 8.1, + "inflow_merge": inflow_edge_len + premerge + postmerge + 8.1, + "bottom": 2 * inflow_edge_len + premerge + postmerge + 8.2, + ":left_0": inflow_edge_len, + ":center_0": inflow_edge_len + premerge + 0.1, + ":center_1": inflow_edge_len + premerge + 0.1, + ":bottom_0": 2 * inflow_edge_len + premerge + postmerge + 8.1 + } + + # compute the absolute position + for veh_id in data.keys(): + data[veh_id]['abs_pos'] = _get_abs_pos(data[veh_id]['edge'], + data[veh_id]['pos'], edgestarts) + + # prepare the speed and absolute position in a way that is compatible with + # the space-time diagram, and compute the number of vehicles at each step + pos = np.zeros((num_steps, len(data.keys()))) + speed = np.zeros((num_steps, len(data.keys()))) + for i, veh_id in enumerate(data.keys()): + for spd, abs_pos, ti, edge in zip(data[veh_id]['vel'], + data[veh_id]['abs_pos'], + data[veh_id]['time'], + data[veh_id]['edge']): + # avoid vehicles outside the main highway + if int(ti * (1 / dt)) >= num_steps or \ + edge in ['inflow_merge', 'bottom', ':bottom_0']: + continue + speed[int(ti * (1 / dt)), i] = spd + pos[int(ti * (1 / dt)), i] = abs_pos + + return pos, speed + + +def _ring_road(data, params, dt, num_steps): + """Generate position and speed data for the ring road. + + Vehicles that reach the top of the plot simply return to the bottom and + continue. + + Parameters + ---------- + data : dict of dict + Key = "veh_id": name of the vehicle \n Elements: + + * "time": time step at every sample + * "edge": edge ID at every sample + * "pos": relative position at every sample + * "vel": speed at every sample + params : dict + flow-specific parameters + dt : float + simulation step size + num_steps : int + number of simulation steps + + Returns + ------- + as_array + n_steps x n_veh matrix specifying the absolute position of every + vehicle at every time step. Set to zero if the vehicle is not present + in the network at that time step. + as_array + n_steps x n_veh matrix specifying the speed of every vehicle at every + time step. Set to zero if the vehicle is not present in the network at + that time step. + """ + # import network data from flow params + total_len = params['net'].additional_params['length'] + + # generate edge starts + edgestarts = { + 'bottom': 0, + 'right': total_len / 4, + 'top': total_len / 2, + 'left': 3 * total_len / 4 + } + + # compute the absolute position + for veh_id in data.keys(): + data[veh_id]['abs_pos'] = _get_abs_pos(data[veh_id]['edge'], + data[veh_id]['pos'], edgestarts) + + # create the output variables + pos = np.zeros((num_steps, len(data.keys()))) + speed = np.zeros((num_steps, len(data.keys()))) + for i, veh_id in enumerate(data.keys()): + for spd, abs_pos, ti in zip(data[veh_id]['vel'], + data[veh_id]['abs_pos'], + data[veh_id]['time']): + if int(ti * (1 / dt)) >= num_steps: + continue + speed[int(ti * (1 / dt)), i] = spd + pos[int(ti * (1 / dt)), i] = abs_pos + + return pos, speed + + +def _figure_eight(data, params, dt, num_steps): + """Generate position and speed data for the figure eight. + + The vehicles traveling towards the intersection from one side will be + plotted from the top downward, while the vehicles from the other side will + be plotted from the bottom upward. + + Parameters + ---------- + data : dict of dict + Key = "veh_id": name of the vehicle \n Elements: + + * "time": time step at every sample + * "edge": edge ID at every sample + * "pos": relative position at every sample + * "vel": speed at every sample + params : dict + flow-specific parameters + dt : float + simulation step size + num_steps : int + number of simulation steps + + Returns + ------- + as_array + n_steps x n_veh matrix specifying the absolute position of every + vehicle at every time step. Set to zero if the vehicle is not present + in the network at that time step. + as_array + n_steps x n_veh matrix specifying the speed of every vehicle at every + time step. Set to zero if the vehicle is not present in the network at + that time step. + """ + # import network data from flow params + net_params = params['net'] + ring_radius = net_params.additional_params["radius_ring"] + ring_edgelen = ring_radius * np.pi / 2. + intersection = 2 * ring_radius + junction = 2.9 + 3.3 * net_params.additional_params["lanes"] + inner = 0.28 + + # generate edge starts + edgestarts = { + 'bottom': inner, + 'top': intersection / 2 + junction + inner, + 'upper_ring': intersection + junction + 2 * inner, + 'right': intersection + 3 * ring_edgelen + junction + 3 * inner, + 'left': 1.5*intersection + 3*ring_edgelen + 2*junction + 3*inner, + "lower_ring": 2*intersection + 3*ring_edgelen + 2*junction + 4*inner, + ":bottom_0": 0, + ":center_1": intersection / 2 + inner, + ":top_0": intersection + junction + inner, + ":right_0": intersection + 3 * ring_edgelen + junction + 2 * inner, + ":center_0": 1.5*intersection + 3*ring_edgelen + junction + 3*inner, + ":left_0": 2 * intersection + 3*ring_edgelen + 2*junction + 3*inner, + # for aimsun + 'bottom_to_top': intersection / 2 + inner, + 'right_to_left': junction + 3 * inner, + } + + # compute the absolute position + for veh_id in data.keys(): + data[veh_id]['abs_pos'] = _get_abs_pos(data[veh_id]['edge'], + data[veh_id]['pos'], edgestarts) + + # create the output variables + pos = np.zeros((num_steps, len(data.keys()))) + speed = np.zeros((num_steps, len(data.keys()))) + for i, veh_id in enumerate(data.keys()): + for spd, abs_pos, ti in zip(data[veh_id]['vel'], + data[veh_id]['abs_pos'], + data[veh_id]['time']): + if int(ti * (1 / dt)) >= num_steps: + continue + speed[int(ti * (1 / dt)), i] = spd + pos[int(ti * (1 / dt)), i] = abs_pos + + # reorganize data for space-time plot + figure8_len = 6*ring_edgelen + 2*intersection + 2*junction + 10*inner + intersection_loc = [edgestarts[':center_1'] + intersection / 2, + edgestarts[':center_0'] + intersection / 2] + pos[pos < intersection_loc[0]] += figure8_len + pos[np.logical_and(pos > intersection_loc[0], pos < intersection_loc[1])] \ + += - intersection_loc[1] + pos[pos > intersection_loc[1]] = \ + - pos[pos > intersection_loc[1]] + figure8_len + intersection_loc[0] + + return pos, speed + + +def create_parser(): + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description='[Flow] Generates time space diagrams for flow networks.', + epilog='python time_space_diagram.py .csv ' + '.json') + + # required arguments + parser.add_argument('emission_path', type=str, + help='path to the csv file.') + parser.add_argument('flow_params', type=str, + help='path to the flow_params json file.') + + # optional arguments + parser.add_argument('--steps', type=int, default=1, + help='rate at which steps are plotted.') + parser.add_argument('--title', type=str, default='Time Space Diagram', + help='rate at which steps are plotted.') + parser.add_argument('--max_speed', type=int, default=8, + help='The maximum speed in the color range.') + parser.add_argument('--start', type=float, default=0, + help='initial time (in sec) in the plot.') + parser.add_argument('--stop', type=float, default=float('inf'), + help='final time (in sec) in the plot.') + + return parser + + +def _get_abs_pos(edge, rel_pos, edgestarts): + """Compute the absolute positions from edges and relative positions. + + This is the variable we will ultimately use to plot individual vehicles. + + Parameters + ---------- + edge : list of str + list of edges at every time step + rel_pos : list of float + list of relative positions at every time step + edgestarts : dict + the absolute starting position of every edge + + Returns + ------- + list of float + the absolute positive for every sample + """ + ret = [] + for edge_i, pos_i in zip(edge, rel_pos): + ret.append(pos_i + edgestarts[edge_i]) + return ret + + +if __name__ == '__main__': + # import parser arguments + parser = create_parser() + args = parser.parse_args() + + # flow_params is imported as a dictionary + flow_params = get_flow_params(args.flow_params) + + # import data from the emission.csv file + emission_data = import_data_from_emission(args.emission_path) + + # compute the position and speed for all vehicles at all times + pos, speed = get_time_space_data(emission_data, flow_params) + + # simulation step size + sim_step = flow_params['sim'].sim_step + + # total time period + total_time = pos.shape[0] * sim_step + + # some plotting parameters + cdict = { + 'red': ((0, 0, 0), (0.2, 1, 1), (0.6, 1, 1), (1, 0, 0)), + 'green': ((0, 0, 0), (0.2, 0, 0), (0.6, 1, 1), (1, 1, 1)), + 'blue': ((0, 0, 0), (0.2, 0, 0), (0.6, 0, 0), (1, 0, 0)) + } + my_cmap = colors.LinearSegmentedColormap('my_colormap', cdict, 1024) + + # perform plotting operation + fig = plt.figure(figsize=(16, 9)) + ax = plt.axes() + norm = plt.Normalize(0, args.max_speed) + cols = [] + + xmin = max(0, args.start) + xmax = min(total_time, args.stop) + xbuffer = (xmax - xmin) * 0.025 # 2.5% of range + ymin, ymax = np.amin(pos), np.amax(pos) + ybuffer = (ymax - ymin) * 0.025 # 2.5% of range + + ax.set_xlim(xmin - xbuffer, xmax + xbuffer) + ax.set_ylim(ymin - ybuffer, ymax + ybuffer) + + time = np.arange(xmin, xmax, sim_step) + + for indx_car in range(pos.shape[1]): + unique_car_pos = pos[:, indx_car] + + # discontinuity from wraparound + disc = np.where(np.abs(np.diff(unique_car_pos)) >= 10)[0] + 1 + unique_car_time = np.insert(time, disc, np.nan) + unique_car_pos = np.insert(unique_car_pos, disc, np.nan) + unique_car_speed = np.insert(speed[:, indx_car], disc, np.nan) + + points = np.array( + [unique_car_time, unique_car_pos]).T.reshape(-1, 1, 2) + segments = np.concatenate([points[:-1], points[1:]], axis=1) + lc = LineCollection(segments, cmap=my_cmap, norm=norm) + + # Set the values used for color mapping + lc.set_array(unique_car_speed) + lc.set_linewidth(1.75) + cols.append(lc) + + plt.title(args.title, fontsize=25) + plt.ylabel('Position (m)', fontsize=20) + plt.xlabel('Time (s)', fontsize=20) + + for col in cols: + line = ax.add_collection(col) + cbar = plt.colorbar(line, ax=ax) + cbar.set_label('Velocity (m/s)', fontsize=20) + cbar.ax.tick_params(labelsize=18) + + plt.xticks(fontsize=18) + plt.yticks(fontsize=18) + + ########################################################################### + # Note: For MergeScenario only # + if flow_params['scenario'] == 'MergeScenario': # + plt.plot(time, [0] * pos.shape[0], linewidth=3, color="white") # + plt.plot(time, [-0.1] * pos.shape[0], linewidth=3, color="white") # + ########################################################################### + + plt.show() From bcc511cc3eb81b660faebd262ffd7f1d8cd0293e Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Sun, 5 May 2019 09:36:59 -0700 Subject: [PATCH 2/9] modified figure eight exps to improve behavior in new sumo --- examples/rllab/figure_eight.py | 2 ++ examples/rllib/figure_eight.py | 2 ++ examples/sumo/figure_eight.py | 1 + flow/benchmarks/figureeight0.py | 1 + flow/benchmarks/figureeight1.py | 1 + flow/utils/registry.py | 1 + flow/utils/rllib.py | 30 +++++++++++++++++++++++++----- 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/examples/rllab/figure_eight.py b/examples/rllab/figure_eight.py index d54eddb48..1fdb99dfb 100644 --- a/examples/rllab/figure_eight.py +++ b/examples/rllab/figure_eight.py @@ -27,6 +27,7 @@ def run_task(*_): routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), num_vehicles=1) vehicles.add( @@ -37,6 +38,7 @@ def run_task(*_): routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), num_vehicles=13) diff --git a/examples/rllib/figure_eight.py b/examples/rllib/figure_eight.py index ad107bef1..e676a9848 100644 --- a/examples/rllib/figure_eight.py +++ b/examples/rllib/figure_eight.py @@ -35,6 +35,7 @@ routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), num_vehicles=13) vehicles.add( @@ -43,6 +44,7 @@ routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), num_vehicles=1) diff --git a/examples/sumo/figure_eight.py b/examples/sumo/figure_eight.py index 96d1b7e36..8eb74b4bb 100755 --- a/examples/sumo/figure_eight.py +++ b/examples/sumo/figure_eight.py @@ -41,6 +41,7 @@ def figure_eight_example(render=None): routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), initial_speed=0, num_vehicles=14) diff --git a/flow/benchmarks/figureeight0.py b/flow/benchmarks/figureeight0.py index 3b1ed8243..29c922c34 100644 --- a/flow/benchmarks/figureeight0.py +++ b/flow/benchmarks/figureeight0.py @@ -29,6 +29,7 @@ routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), num_vehicles=13) vehicles.add( diff --git a/flow/benchmarks/figureeight1.py b/flow/benchmarks/figureeight1.py index 0d991c9b5..d52e09216 100644 --- a/flow/benchmarks/figureeight1.py +++ b/flow/benchmarks/figureeight1.py @@ -30,6 +30,7 @@ routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", + decel=1.5, ), num_vehicles=1) vehicles.add( diff --git a/flow/utils/registry.py b/flow/utils/registry.py index f2925c58c..0a15e777a 100644 --- a/flow/utils/registry.py +++ b/flow/utils/registry.py @@ -32,6 +32,7 @@ def make_create_env(params, version=0, render=None): - exp_tag: name of the experiment - env_name: name of the flow environment the experiment is running on - scenario: name of the scenario class the experiment uses + - simulator: simulator that is used by the experiment (e.g. aimsun) - sim: simulation-related parameters (see flow.core.params.SimParams) - env: environment related parameters (see flow.core.params.EnvParams) - net: network-related parameters (see flow.core.params.NetParams and diff --git a/flow/utils/rllib.py b/flow/utils/rllib.py index 27460ce2e..0847e6dba 100644 --- a/flow/utils/rllib.py +++ b/flow/utils/rllib.py @@ -57,17 +57,37 @@ def get_flow_params(config): Parameters ---------- - config : dict - stored RLlib configuration dict + config : dict < dict > or str + May be one of two things: + + * If it is a dict, then it is the stored RLlib configuration dict. + * If it is a string, then it is the path to a flow_params json file. Returns ------- dict - Dict of flow parameters, like net_params, env_params, vehicle - characteristics, etc + flow-related parameters, consisting of the following keys: + + * exp_tag: name of the experiment + * env_name: name of the flow environment the experiment is running on + * scenario: name of the scenario class the experiment uses + * simulator: simulator that is used by the experiment (e.g. aimsun) + * sim: simulation-related parameters (see flow.core.params.SimParams) + * env: environment related parameters (see flow.core.params.EnvParams) + * net: network-related parameters (see flow.core.params.NetParams and + the scenario's documentation or ADDITIONAL_NET_PARAMS component) + * veh: vehicles to be placed in the network at the start of a rollout + (see flow.core.params.VehicleParams) + * initial: parameters affecting the positioning of vehicles upon + initialization/reset (see flow.core.params.InitialConfig) + * tls: traffic lights to be introduced to specific nodes (see + flow.core.params.TrafficLightParams) """ # collect all data from the json file - flow_params = json.loads(config['env_config']['flow_params']) + if type(config) == dict: + flow_params = json.loads(config['env_config']['flow_params']) + else: + flow_params = json.load(open(config, 'r')) # reinitialize the vehicles class from stored data veh = VehicleParams() From 04627aeb50c82295bd9873d955b011b780cc8220 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Tue, 7 May 2019 00:16:33 -0700 Subject: [PATCH 3/9] added test for importing emission in time space diagram --- tests/fast_tests/test_files/fig8.json | 151 +++++++++++++++++++ tests/fast_tests/test_files/loop_230.json | 153 +++++++++++++++++++ tests/fast_tests/test_files/loop_260.json | 153 +++++++++++++++++++ tests/fast_tests/test_files/merge.json | 176 ++++++++++++++++++++++ tests/fast_tests/test_visualizers.py | 81 ++++++++++ 5 files changed, 714 insertions(+) create mode 100644 tests/fast_tests/test_files/fig8.json create mode 100644 tests/fast_tests/test_files/loop_230.json create mode 100644 tests/fast_tests/test_files/loop_260.json create mode 100644 tests/fast_tests/test_files/merge.json diff --git a/tests/fast_tests/test_files/fig8.json b/tests/fast_tests/test_files/fig8.json new file mode 100644 index 000000000..a4d9bc603 --- /dev/null +++ b/tests/fast_tests/test_files/fig8.json @@ -0,0 +1,151 @@ +{ + "env": { + "additional_params": { + "max_accel": 3, + "max_decel": 3, + "sort_vehicles": false, + "target_velocity": 20 + }, + "clip_actions": true, + "evaluate": false, + "horizon": 1500, + "sims_per_step": 1, + "warmup_steps": 0 + }, + "env_name": "AccelEnv", + "exp_tag": "figure_eight_0", + "initial": { + "additional_params": {}, + "bunching": 0, + "edges_distribution": "all", + "lanes_distribution": Infinity, + "min_gap": 0, + "perturbation": 0.0, + "shuffle": false, + "spacing": "uniform", + "x0": 0 + }, + "net": { + "additional_params": { + "lanes": 1, + "radius_ring": 30, + "resolution": 40, + "speed_limit": 30 + }, + "inflows": { + "_InFlows__flows": [], + "num_flows": 0 + }, + "no_internal_links": false, + "osm_path": null, + "template": null + }, + "scenario": "Figure8Scenario", + "sim": { + "emission_path": null, + "lateral_resolution": null, + "no_step_log": true, + "num_clients": 1, + "overtake_right": false, + "port": null, + "print_warnings": true, + "pxpm": 2, + "render": false, + "restart_instance": false, + "save_render": false, + "seed": null, + "show_radius": false, + "sight_radius": 25, + "sim_step": 0.1, + "teleport_time": -1 + }, + "simulator": "traci", + "veh": [ + { + "acceleration_controller": [ + "IDMController", + { + "noise": 0.2 + } + ], + "car_following_params": { + "controller_params": { + "accel": 2.6, + "carFollowModel": "IDM", + "decel": 4.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 1 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 13, + "routing_controller": [ + "ContinuousRouter", + {} + ], + "veh_id": "human" + }, + { + "acceleration_controller": [ + "RLController", + {} + ], + "car_following_params": { + "controller_params": { + "accel": 2.6, + "carFollowModel": "IDM", + "decel": 4.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 1 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 1, + "routing_controller": [ + "ContinuousRouter", + {} + ], + "veh_id": "rl" + } + ] +} \ No newline at end of file diff --git a/tests/fast_tests/test_files/loop_230.json b/tests/fast_tests/test_files/loop_230.json new file mode 100644 index 000000000..7993a2826 --- /dev/null +++ b/tests/fast_tests/test_files/loop_230.json @@ -0,0 +1,153 @@ +{ + "env": { + "additional_params": { + "max_accel": 1, + "max_decel": 1, + "ring_length": [ + 220, + 270 + ] + }, + "clip_actions": false, + "evaluate": false, + "horizon": 3000, + "sims_per_step": 1, + "warmup_steps": 750 + }, + "env_name": "WaveAttenuationPOEnv", + "exp_tag": "stabilizing_the_ring", + "initial": { + "additional_params": {}, + "bunching": 0, + "edges_distribution": "all", + "lanes_distribution": Infinity, + "min_gap": 0, + "perturbation": 0.0, + "shuffle": false, + "spacing": "uniform", + "x0": 0 + }, + "net": { + "additional_params": { + "lanes": 1, + "length": 230, + "resolution": 40, + "speed_limit": 30 + }, + "inflows": { + "_InFlows__flows": [], + "num_flows": 0 + }, + "no_internal_links": true, + "osm_path": null, + "template": null + }, + "scenario": "LoopScenario", + "sim": { + "emission_path": null, + "lateral_resolution": null, + "no_step_log": true, + "num_clients": 1, + "overtake_right": false, + "port": null, + "print_warnings": true, + "pxpm": 2, + "render": false, + "restart_instance": false, + "save_render": false, + "seed": null, + "show_radius": false, + "sight_radius": 25, + "sim_step": 0.1, + "teleport_time": -1 + }, + "simulator": "traci", + "veh": [ + { + "acceleration_controller": [ + "IDMController", + { + "noise": 0.2 + } + ], + "car_following_params": { + "controller_params": { + "accel": 1.0, + "carFollowModel": "IDM", + "decel": 1.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 25 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 21, + "routing_controller": [ + "ContinuousRouter", + {} + ], + "veh_id": "human" + }, + { + "acceleration_controller": [ + "RLController", + {} + ], + "car_following_params": { + "controller_params": { + "accel": 1.0, + "carFollowModel": "IDM", + "decel": 1.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 25 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 1, + "routing_controller": [ + "ContinuousRouter", + {} + ], + "veh_id": "rl" + } + ] +} \ No newline at end of file diff --git a/tests/fast_tests/test_files/loop_260.json b/tests/fast_tests/test_files/loop_260.json new file mode 100644 index 000000000..dd5f34a4b --- /dev/null +++ b/tests/fast_tests/test_files/loop_260.json @@ -0,0 +1,153 @@ +{ + "env": { + "additional_params": { + "max_accel": 1, + "max_decel": 1, + "ring_length": [ + 220, + 270 + ] + }, + "clip_actions": false, + "evaluate": false, + "horizon": 3000, + "sims_per_step": 1, + "warmup_steps": 750 + }, + "env_name": "WaveAttenuationPOEnv", + "exp_tag": "stabilizing_the_ring", + "initial": { + "additional_params": {}, + "bunching": 0, + "edges_distribution": "all", + "lanes_distribution": Infinity, + "min_gap": 0, + "perturbation": 0.0, + "shuffle": false, + "spacing": "uniform", + "x0": 0 + }, + "net": { + "additional_params": { + "lanes": 1, + "length": 260, + "resolution": 40, + "speed_limit": 30 + }, + "inflows": { + "_InFlows__flows": [], + "num_flows": 0 + }, + "no_internal_links": true, + "osm_path": null, + "template": null + }, + "scenario": "LoopScenario", + "sim": { + "emission_path": null, + "lateral_resolution": null, + "no_step_log": true, + "num_clients": 1, + "overtake_right": false, + "port": null, + "print_warnings": true, + "pxpm": 2, + "render": false, + "restart_instance": false, + "save_render": false, + "seed": null, + "show_radius": false, + "sight_radius": 25, + "sim_step": 0.1, + "teleport_time": -1 + }, + "simulator": "traci", + "veh": [ + { + "acceleration_controller": [ + "IDMController", + { + "noise": 0.2 + } + ], + "car_following_params": { + "controller_params": { + "accel": 1.0, + "carFollowModel": "IDM", + "decel": 1.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 25 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 21, + "routing_controller": [ + "ContinuousRouter", + {} + ], + "veh_id": "human" + }, + { + "acceleration_controller": [ + "RLController", + {} + ], + "car_following_params": { + "controller_params": { + "accel": 1.0, + "carFollowModel": "IDM", + "decel": 1.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 25 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 1, + "routing_controller": [ + "ContinuousRouter", + {} + ], + "veh_id": "rl" + } + ] +} \ No newline at end of file diff --git a/tests/fast_tests/test_files/merge.json b/tests/fast_tests/test_files/merge.json new file mode 100644 index 000000000..655a58baf --- /dev/null +++ b/tests/fast_tests/test_files/merge.json @@ -0,0 +1,176 @@ +{ + "env": { + "additional_params": { + "max_accel": 1.5, + "max_decel": 1.5, + "num_rl": 5, + "target_velocity": 20 + }, + "clip_actions": true, + "evaluate": false, + "horizon": 750, + "sims_per_step": 2, + "warmup_steps": 0 + }, + "env_name": "WaveAttenuationMergePOEnv", + "exp_tag": "merge_0", + "initial": { + "additional_params": {}, + "bunching": 0, + "edges_distribution": "all", + "lanes_distribution": Infinity, + "min_gap": 0, + "perturbation": 0.0, + "shuffle": false, + "spacing": "uniform", + "x0": 0 + }, + "net": { + "additional_params": { + "highway_lanes": 1, + "merge_lanes": 1, + "merge_length": 100, + "post_merge_length": 100, + "pre_merge_length": 500, + "speed_limit": 30 + }, + "inflows": { + "_InFlows__flows": [ + { + "begin": 1, + "departLane": "free", + "departSpeed": 10, + "edge": "inflow_highway", + "end": 2000000.0, + "name": "flow_0", + "vehsPerHour": 1800.0, + "vtype": "human" + }, + { + "begin": 1, + "departLane": "free", + "departSpeed": 10, + "edge": "inflow_highway", + "end": 2000000.0, + "name": "flow_1", + "vehsPerHour": 200.0, + "vtype": "rl" + }, + { + "begin": 1, + "departLane": "free", + "departSpeed": 7.5, + "edge": "inflow_merge", + "end": 2000000.0, + "name": "flow_2", + "vehsPerHour": 100, + "vtype": "human" + } + ], + "num_flows": 3 + }, + "no_internal_links": false, + "osm_path": null, + "template": null + }, + "scenario": "MergeScenario", + "sim": { + "emission_path": null, + "lateral_resolution": null, + "no_step_log": true, + "num_clients": 1, + "overtake_right": false, + "port": null, + "print_warnings": true, + "pxpm": 2, + "render": false, + "restart_instance": true, + "save_render": false, + "seed": null, + "show_radius": false, + "sight_radius": 25, + "sim_step": 0.5, + "teleport_time": -1 + }, + "simulator": "traci", + "veh": [ + { + "acceleration_controller": [ + "SimCarFollowingController", + {} + ], + "car_following_params": { + "controller_params": { + "accel": 1.0, + "carFollowModel": "IDM", + "decel": 1.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 1 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 5, + "routing_controller": null, + "veh_id": "human" + }, + { + "acceleration_controller": [ + "RLController", + {} + ], + "car_following_params": { + "controller_params": { + "accel": 1.0, + "carFollowModel": "IDM", + "decel": 1.5, + "impatience": 0.5, + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "speed_mode": 1 + }, + "initial_speed": 0, + "lane_change_controller": [ + "SimLaneChangeController", + {} + ], + "lane_change_params": { + "controller_params": { + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0" + }, + "lane_change_mode": 512 + }, + "num_vehicles": 0, + "routing_controller": null, + "veh_id": "rl" + } + ] +} \ No newline at end of file diff --git a/tests/fast_tests/test_visualizers.py b/tests/fast_tests/test_visualizers.py index c2b34c09d..0e7551086 100644 --- a/tests/fast_tests/test_visualizers.py +++ b/tests/fast_tests/test_visualizers.py @@ -3,6 +3,7 @@ from flow.visualize import visualizer_rllib as vs_rllib from flow.visualize.visualizer_rllib import visualizer_rllib import flow.visualize.capacity_diagram_generator as cdg +import flow.visualize.time_space_diagram as tsd import os import unittest @@ -101,6 +102,86 @@ def test_capacity_diagram_generator(self): np.testing.assert_array_almost_equal(mean_outflows, expected_means) np.testing.assert_array_almost_equal(std_outflows, expected_stds) + def test_time_space_diagram_figure_eight(self): + # check that the exported data matches the expected emission file data + fig8_emission_data = { + 'idm_3': {'pos': [27.25, 28.25, 30.22, 33.17], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['upper_ring', 'upper_ring', 'upper_ring', + 'upper_ring']}, + 'idm_4': {'pos': [56.02, 57.01, 58.99, 61.93], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['upper_ring', 'upper_ring', 'upper_ring', + 'upper_ring']}, + 'idm_5': {'pos': [84.79, 85.78, 87.76, 90.7], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['upper_ring', 'upper_ring', 'upper_ring', + 'upper_ring']}, + 'idm_2': {'pos': [28.77, 29.76, 1.63, 4.58], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.97, 2.95], + 'edge': ['top', 'top', 'upper_ring', 'upper_ring']}, + 'idm_13': {'pos': [106.79, 107.79, 109.77, 112.74], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.96], + 'edge': ['lower_ring', 'lower_ring', 'lower_ring', + 'lower_ring']}, + 'idm_9': {'pos': [22.01, 23.0, 24.97, 27.92], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.97, 2.95], + 'edge': ['left', 'left', 'left', 'left']}, + 'idm_6': {'pos': [113.56, 114.55, 116.52, 119.47], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.97, 2.95], + 'edge': ['upper_ring', 'upper_ring', 'upper_ring', + 'upper_ring']}, + 'idm_8': {'pos': [29.44, 0.28, 2.03, 4.78], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.84, 1.76, 2.75], + 'edge': ['right', ':center_0', ':center_0', + ':center_0']}, + 'idm_12': {'pos': [78.03, 79.02, 80.99, 83.94], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['lower_ring', 'lower_ring', 'lower_ring', + 'lower_ring']}, + 'idm_10': {'pos': [20.49, 21.48, 23.46, 26.41], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['lower_ring', 'lower_ring', 'lower_ring', + 'lower_ring']}, + 'idm_11': {'pos': [49.26, 50.25, 52.23, 55.17], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['lower_ring', 'lower_ring', 'lower_ring', + 'lower_ring']}, + 'idm_1': {'pos': [0.0, 0.99, 2.97, 5.91], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.98, 2.95], + 'edge': ['top', 'top', 'top', 'top']}, + 'idm_7': {'pos': [0.67, 1.66, 3.64, 6.58], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 0.99, 1.97, 2.94], + 'edge': ['right', 'right', 'right', 'right']}, + 'idm_0': {'pos': [0.0, 1.0, 2.98, 5.95], + 'time': [1.0, 2.0, 3.0, 4.0], + 'vel': [0.0, 1.0, 1.99, 2.97], + 'edge': ['bottom', 'bottom', 'bottom', 'bottom']} + } + dir_path = os.path.dirname(os.path.realpath(__file__)) + actual_emission_data = tsd.import_data_from_emission( + os.path.join(dir_path, 'test_files/fig8_emission.csv')) + self.assertDictEqual(fig8_emission_data, actual_emission_data) + + def test_time_space_diagram_merge(self): + pass + + def test_time_space_diagram_ring_road(self): + pass + if __name__ == '__main__': ray.init(num_cpus=1) From 06fd1942936e95a29f7fe50690f5da8a0fac6db5 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Tue, 7 May 2019 01:12:27 -0700 Subject: [PATCH 4/9] added missing file --- tests/fast_tests/test_files/fig8_emission.csv | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/fast_tests/test_files/fig8_emission.csv diff --git a/tests/fast_tests/test_files/fig8_emission.csv b/tests/fast_tests/test_files/fig8_emission.csv new file mode 100644 index 000000000..c93307019 --- /dev/null +++ b/tests/fast_tests/test_files/fig8_emission.csv @@ -0,0 +1,57 @@ +waiting,relative_position,electricity,eclass,CO,id,edge_id,x,angle,time,type,NOx,lane_number,speed,route,PMx,y,CO2,HC,fuel,noise +0.0,0.0,0.0,HBEFA3/PC_G_EU4,164.78,idm_0,bottom,61.65,5.3,1.0,idm,1.2,0,0.0,routebottom,0.07,30.0,2624.72,0.81,1.13,55.94 +0.0,1.0,0.0,HBEFA3/PC_G_EU4,150.41,idm_0,bottom,61.65,3.35,2.0,idm,1.24,0,1.0,routebottom,0.06,30.89,2761.71,0.75,1.19,60.7 +0.0,2.98,0.0,HBEFA3/PC_G_EU4,137.21,idm_0,bottom,61.65,1.49,3.0,idm,1.28,0,1.99,routebottom,0.06,32.68,2911.41,0.69,1.25,61.08 +0.0,5.95,0.0,HBEFA3/PC_G_EU4,125.13,idm_0,bottom,61.65,0.0,4.0,idm,1.33,0,2.97,routebottom,0.06,35.35,3070.28,0.64,1.32,61.46 +0.0,0.0,0.0,HBEFA3/PC_G_EU4,164.78,idm_1,top,61.65,0.0,1.0,idm,1.2,0,0.0,routetop,0.07,66.35,2624.72,0.81,1.13,55.94 +0.0,0.99,0.0,HBEFA3/PC_G_EU4,150.45,idm_1,top,61.65,0.0,2.0,idm,1.24,0,0.99,routetop,0.06,67.13,2760.22,0.75,1.19,60.68 +0.0,2.97,0.0,HBEFA3/PC_G_EU4,137.27,idm_1,top,61.65,0.0,3.0,idm,1.28,0,1.98,routetop,0.06,68.69,2905.25,0.69,1.25,61.04 +0.0,5.91,0.0,HBEFA3/PC_G_EU4,125.21,idm_1,top,61.65,0.0,4.0,idm,1.33,0,2.95,routetop,0.06,71.01,3056.31,0.64,1.31,61.39 +0.0,20.49,0.0,HBEFA3/PC_G_EU4,164.78,idm_10,lower_ring,9.99,235.56,1.0,idm,1.2,0,0.0,routelower_ring,0.07,54.47,2624.72,0.81,1.13,55.94 +0.0,21.48,0.0,HBEFA3/PC_G_EU4,150.45,idm_10,lower_ring,9.17,234.19,2.0,idm,1.24,0,0.99,routelower_ring,0.06,53.83,2760.22,0.75,1.19,60.68 +0.0,23.46,0.0,HBEFA3/PC_G_EU4,137.27,idm_10,lower_ring,7.68,229.52,3.0,idm,1.28,0,1.98,routelower_ring,0.06,52.37,2905.25,0.69,1.25,61.04 +0.0,26.41,0.0,HBEFA3/PC_G_EU4,125.21,idm_10,lower_ring,5.6,223.86,4.0,idm,1.33,0,2.95,routelower_ring,0.06,50.09,3056.31,0.64,1.31,61.39 +0.0,49.26,0.0,HBEFA3/PC_G_EU4,164.78,idm_11,lower_ring,-1.51,180.46,1.0,idm,1.2,0,0.0,routelower_ring,0.07,27.72,2624.72,0.81,1.13,55.94 +0.0,50.25,0.0,HBEFA3/PC_G_EU4,150.45,idm_11,lower_ring,-1.45,179.09,2.0,idm,1.24,0,0.99,routelower_ring,0.06,26.68,2760.22,0.75,1.19,60.68 +0.0,52.23,0.0,HBEFA3/PC_G_EU4,137.27,idm_11,lower_ring,-1.14,174.51,3.0,idm,1.28,0,1.98,routelower_ring,0.06,24.62,2905.25,0.69,1.25,61.04 +0.0,55.17,0.0,HBEFA3/PC_G_EU4,125.21,idm_11,lower_ring,-0.48,169.34,4.0,idm,1.33,0,2.95,routelower_ring,0.06,21.6,3056.31,0.64,1.31,61.39 +0.0,78.03,0.0,HBEFA3/PC_G_EU4,164.78,idm_12,lower_ring,13.73,125.36,1.0,idm,1.2,0,0.0,routelower_ring,0.07,2.92,2624.72,0.81,1.13,55.94 +0.0,79.02,0.0,HBEFA3/PC_G_EU4,150.45,idm_12,lower_ring,14.63,123.99,2.0,idm,1.24,0,0.99,routelower_ring,0.06,2.38,2760.22,0.75,1.19,60.68 +0.0,80.99,0.0,HBEFA3/PC_G_EU4,137.27,idm_12,lower_ring,16.48,119.61,3.0,idm,1.28,0,1.98,routelower_ring,0.06,1.44,2905.26,0.69,1.25,61.04 +0.0,83.94,0.0,HBEFA3/PC_G_EU4,125.21,idm_12,lower_ring,19.33,114.72,4.0,idm,1.33,0,2.95,routelower_ring,0.06,0.23,3056.43,0.64,1.31,61.39 +0.0,106.79,0.0,HBEFA3/PC_G_EU4,164.78,idm_13,lower_ring,42.79,70.36,1.0,idm,1.2,0,0.0,routelower_ring,0.07,1.11,2624.72,0.81,1.13,55.94 +0.0,107.79,0.0,HBEFA3/PC_G_EU4,150.42,idm_13,lower_ring,43.74,68.95,2.0,idm,1.24,0,0.99,routelower_ring,0.06,1.54,2761.24,0.75,1.19,60.69 +0.0,109.77,0.0,HBEFA3/PC_G_EU4,137.23,idm_13,lower_ring,45.59,64.86,3.0,idm,1.28,0,1.98,routelower_ring,0.06,2.51,2909.47,0.69,1.25,61.06 +0.0,112.74,0.0,HBEFA3/PC_G_EU4,125.16,idm_13,lower_ring,48.24,59.92,4.0,idm,1.33,0,2.96,routelower_ring,0.06,4.15,3067.11,0.64,1.32,61.45 +0.0,28.77,0.0,HBEFA3/PC_G_EU4,164.78,idm_2,top,61.65,0.0,1.0,idm,1.2,0,0.0,routetop,0.07,89.03,2624.72,0.81,1.13,55.94 +0.0,29.76,0.0,HBEFA3/PC_G_EU4,150.45,idm_2,top,61.65,0.0,2.0,idm,1.24,0,0.99,routetop,0.06,89.81,2760.17,0.75,1.19,60.68 +0.0,1.63,0.0,HBEFA3/PC_G_EU4,137.27,idm_2,upper_ring,61.74,1.31,3.0,idm,1.28,0,1.97,routetop,0.06,91.44,2905.07,0.69,1.25,61.03 +0.0,4.58,0.0,HBEFA3/PC_G_EU4,125.22,idm_2,upper_ring,62.01,4.56,4.0,idm,1.33,0,2.95,routetop,0.06,94.21,3055.86,0.64,1.31,61.39 +0.0,27.25,0.0,HBEFA3/PC_G_EU4,164.78,idm_3,upper_ring,72.55,47.49,1.0,idm,1.2,0,0.0,routeupper_ring,0.07,112.27,2624.72,0.81,1.13,55.94 +0.0,28.25,0.0,HBEFA3/PC_G_EU4,150.45,idm_3,upper_ring,73.29,48.85,2.0,idm,1.24,0,0.99,routeupper_ring,0.06,112.85,2760.22,0.75,1.19,60.68 +0.0,30.22,0.0,HBEFA3/PC_G_EU4,137.27,idm_3,upper_ring,74.84,53.19,3.0,idm,1.28,0,1.98,routeupper_ring,0.06,113.9,2905.25,0.69,1.25,61.04 +0.0,33.17,0.0,HBEFA3/PC_G_EU4,125.21,idm_3,upper_ring,77.25,58.29,4.0,idm,1.33,0,2.95,routeupper_ring,0.06,115.29,3056.31,0.64,1.31,61.39 +0.0,56.02,0.0,HBEFA3/PC_G_EU4,164.78,idm_4,upper_ring,98.25,102.69,1.0,idm,1.2,0,0.0,routeupper_ring,0.07,117.06,2624.72,0.81,1.13,55.94 +0.0,57.01,0.0,HBEFA3/PC_G_EU4,150.45,idm_4,upper_ring,99.14,104.05,2.0,idm,1.24,0,0.99,routeupper_ring,0.06,116.78,2760.22,0.75,1.19,60.68 +0.0,58.99,0.0,HBEFA3/PC_G_EU4,137.27,idm_4,upper_ring,100.89,108.1,3.0,idm,1.28,0,1.98,routeupper_ring,0.06,116.12,2905.25,0.69,1.25,61.04 +0.0,61.93,0.0,HBEFA3/PC_G_EU4,125.21,idm_4,upper_ring,103.41,113.11,4.0,idm,1.33,0,2.95,routeupper_ring,0.06,114.95,3056.31,0.64,1.31,61.39 +0.0,84.79,0.0,HBEFA3/PC_G_EU4,164.78,idm_5,upper_ring,116.9,157.8,1.0,idm,1.2,0,0.0,routeupper_ring,0.07,98.75,2624.72,0.81,1.13,55.94 +0.0,85.78,0.0,HBEFA3/PC_G_EU4,150.45,idm_5,upper_ring,117.18,159.16,2.0,idm,1.24,0,0.99,routeupper_ring,0.06,97.86,2760.22,0.75,1.19,60.68 +0.0,87.76,0.0,HBEFA3/PC_G_EU4,137.27,idm_5,upper_ring,117.65,162.93,3.0,idm,1.28,0,1.98,routeupper_ring,0.06,96.05,2905.25,0.69,1.25,61.04 +0.0,90.7,0.0,HBEFA3/PC_G_EU4,125.21,idm_5,upper_ring,118.15,167.95,4.0,idm,1.33,0,2.95,routeupper_ring,0.06,93.31,3056.31,0.64,1.31,61.39 +0.0,113.56,0.0,HBEFA3/PC_G_EU4,164.78,idm_6,upper_ring,112.6,212.7,1.0,idm,1.2,0,0.0,routeupper_ring,0.07,72.97,2624.72,0.81,1.13,55.94 +0.0,114.55,0.0,HBEFA3/PC_G_EU4,150.45,idm_6,upper_ring,112.02,214.26,2.0,idm,1.24,0,0.99,routeupper_ring,0.06,72.23,2760.17,0.75,1.19,60.68 +0.0,116.52,0.0,HBEFA3/PC_G_EU4,137.27,idm_6,upper_ring,110.82,217.85,3.0,idm,1.28,0,1.97,routeupper_ring,0.06,70.81,2905.07,0.69,1.25,61.03 +0.0,119.47,0.0,HBEFA3/PC_G_EU4,125.22,idm_6,upper_ring,108.85,223.0,4.0,idm,1.33,0,2.95,routeupper_ring,0.06,68.84,3055.85,0.64,1.31,61.39 +0.0,0.67,0.0,HBEFA3/PC_G_EU4,164.78,idm_7,right,89.47,266.17,1.0,idm,1.2,0,0.0,routeright,0.07,61.65,2624.72,0.81,1.13,55.94 +0.0,1.66,0.0,HBEFA3/PC_G_EU4,150.45,idm_7,right,88.69,267.55,2.0,idm,1.24,0,0.99,routeright,0.06,61.65,2760.22,0.75,1.19,60.68 +0.0,3.64,0.0,HBEFA3/PC_G_EU4,137.27,idm_7,right,87.13,268.97,3.0,idm,1.28,0,1.97,routeright,0.06,61.65,2904.65,0.69,1.25,61.03 +0.0,6.58,0.0,HBEFA3/PC_G_EU4,125.21,idm_7,right,84.81,270.0,4.0,idm,1.33,0,2.94,routeright,0.06,61.65,3052.93,0.64,1.31,61.38 +0.0,29.44,0.0,HBEFA3/PC_G_EU4,164.78,idm_8,right,66.79,270.0,1.0,idm,1.2,0,0.0,routeright,0.07,61.65,2624.72,0.81,1.13,55.94 +0.0,0.28,0.0,HBEFA3/PC_G_EU4,151.92,idm_8,:center_0,66.07,270.0,2.0,idm,1.22,0,0.84,routeright,0.06,61.65,2704.13,0.75,1.16,59.94 +0.0,2.03,0.0,HBEFA3/PC_G_EU4,139.49,idm_8,:center_0,64.32,270.0,3.0,idm,1.26,0,1.76,routeright,0.06,61.65,2843.47,0.7,1.22,60.68 +0.0,4.78,0.0,HBEFA3/PC_G_EU4,127.84,idm_8,:center_0,61.57,270.0,4.0,idm,1.32,0,2.75,routeright,0.06,61.65,3038.88,0.65,1.31,61.4 +0.0,22.01,0.0,HBEFA3/PC_G_EU4,164.78,idm_9,left,37.18,270.0,1.0,idm,1.2,0,0.0,routeleft,0.07,61.65,2624.72,0.81,1.13,55.94 +0.0,23.0,0.0,HBEFA3/PC_G_EU4,150.45,idm_9,left,36.29,270.0,2.0,idm,1.24,0,0.99,routeleft,0.06,61.65,2760.17,0.75,1.19,60.68 +0.0,24.97,0.0,HBEFA3/PC_G_EU4,137.27,idm_9,left,34.52,270.0,3.0,idm,1.28,0,1.97,routeleft,0.06,61.65,2905.07,0.69,1.25,61.03 +0.0,27.92,0.0,HBEFA3/PC_G_EU4,125.22,idm_9,left,31.87,270.0,4.0,idm,1.33,0,2.95,routeleft,0.06,61.65,3055.86,0.64,1.31,61.39 From e0499db7264a785d94556c0f15e056b9956ece12 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Sun, 19 May 2019 17:25:08 -0700 Subject: [PATCH 5/9] tests for the time space diagram visualizer and some cleanup --- flow/visualize/time_space_diagram.py | 121 ++++++++--------- tests/fast_tests/test_files/fig8.json | 2 +- tests/fast_tests/test_files/loop_260.json | 153 ---------------------- tests/fast_tests/test_files/merge.json | 2 +- tests/fast_tests/test_visualizers.py | 102 ++++++++++++++- 5 files changed, 160 insertions(+), 220 deletions(-) delete mode 100644 tests/fast_tests/test_files/loop_260.json diff --git a/flow/visualize/time_space_diagram.py b/flow/visualize/time_space_diagram.py index 873b9b1f0..2dff7949e 100644 --- a/flow/visualize/time_space_diagram.py +++ b/flow/visualize/time_space_diagram.py @@ -123,12 +123,12 @@ def get_time_space_data(data, params): } # simulation step size - dt = flow_params['sim'].sim_step + dt = params['sim'].sim_step # number of simulation steps max_time = max(max(data[veh_id]['time']) for veh_id in data.keys()) min_time = min(min(data[veh_id]['time']) for veh_id in data.keys()) - num_steps = int((max_time - min_time)/dt) + 1 + num_steps = int((max_time - min_time)/dt) # Get the function from switcher dictionary func = switcher[params['scenario']] @@ -177,15 +177,15 @@ def _merge(data, params, dt, num_steps): # generate edge starts edgestarts = { - "inflow_highway": 0, - "left": inflow_edge_len + 0.1, - "center": inflow_edge_len + premerge + 8.1, - "inflow_merge": inflow_edge_len + premerge + postmerge + 8.1, - "bottom": 2 * inflow_edge_len + premerge + postmerge + 8.2, - ":left_0": inflow_edge_len, - ":center_0": inflow_edge_len + premerge + 0.1, - ":center_1": inflow_edge_len + premerge + 0.1, - ":bottom_0": 2 * inflow_edge_len + premerge + postmerge + 8.1 + 'inflow_highway': 0, + 'left': inflow_edge_len + 0.1, + 'center': inflow_edge_len + premerge + 8.1, + 'inflow_merge': inflow_edge_len + premerge + postmerge + 8.1, + 'bottom': 2 * inflow_edge_len + premerge + postmerge + 8.2, + ':left_0': inflow_edge_len, + ':center_0': inflow_edge_len + premerge + 0.1, + ':center_1': inflow_edge_len + premerge + 0.1, + ':bottom_0': 2 * inflow_edge_len + premerge + postmerge + 8.1 } # compute the absolute position @@ -197,17 +197,17 @@ def _merge(data, params, dt, num_steps): # the space-time diagram, and compute the number of vehicles at each step pos = np.zeros((num_steps, len(data.keys()))) speed = np.zeros((num_steps, len(data.keys()))) - for i, veh_id in enumerate(data.keys()): + for i, veh_id in enumerate(sorted(data.keys())): for spd, abs_pos, ti, edge in zip(data[veh_id]['vel'], data[veh_id]['abs_pos'], data[veh_id]['time'], data[veh_id]['edge']): # avoid vehicles outside the main highway - if int(ti * (1 / dt)) >= num_steps or \ + if int(ti/dt)-1 >= num_steps or \ edge in ['inflow_merge', 'bottom', ':bottom_0']: continue - speed[int(ti * (1 / dt)), i] = spd - pos[int(ti * (1 / dt)), i] = abs_pos + pos[int(ti/dt)-1, i] = abs_pos + speed[int(ti/dt)-1, i] = spd return pos, speed @@ -264,14 +264,14 @@ def _ring_road(data, params, dt, num_steps): # create the output variables pos = np.zeros((num_steps, len(data.keys()))) speed = np.zeros((num_steps, len(data.keys()))) - for i, veh_id in enumerate(data.keys()): + for i, veh_id in enumerate(sorted(data.keys())): for spd, abs_pos, ti in zip(data[veh_id]['vel'], data[veh_id]['abs_pos'], data[veh_id]['time']): - if int(ti * (1 / dt)) >= num_steps: + if int(ti/dt)-1 >= num_steps: continue - speed[int(ti * (1 / dt)), i] = spd - pos[int(ti * (1 / dt)), i] = abs_pos + pos[int(ti/dt)-1, i] = abs_pos + speed[int(ti/dt)-1, i] = spd return pos, speed @@ -312,10 +312,10 @@ def _figure_eight(data, params, dt, num_steps): """ # import network data from flow params net_params = params['net'] - ring_radius = net_params.additional_params["radius_ring"] + ring_radius = net_params.additional_params['radius_ring'] ring_edgelen = ring_radius * np.pi / 2. intersection = 2 * ring_radius - junction = 2.9 + 3.3 * net_params.additional_params["lanes"] + junction = 2.9 + 3.3 * net_params.additional_params['lanes'] inner = 0.28 # generate edge starts @@ -325,13 +325,13 @@ def _figure_eight(data, params, dt, num_steps): 'upper_ring': intersection + junction + 2 * inner, 'right': intersection + 3 * ring_edgelen + junction + 3 * inner, 'left': 1.5*intersection + 3*ring_edgelen + 2*junction + 3*inner, - "lower_ring": 2*intersection + 3*ring_edgelen + 2*junction + 4*inner, - ":bottom_0": 0, - ":center_1": intersection / 2 + inner, - ":top_0": intersection + junction + inner, - ":right_0": intersection + 3 * ring_edgelen + junction + 2 * inner, - ":center_0": 1.5*intersection + 3*ring_edgelen + junction + 3*inner, - ":left_0": 2 * intersection + 3*ring_edgelen + 2*junction + 3*inner, + 'lower_ring': 2*intersection + 3*ring_edgelen + 2*junction + 4*inner, + ':bottom_0': 0, + ':center_1': intersection / 2 + inner, + ':top_0': intersection + junction + inner, + ':right_0': intersection + 3 * ring_edgelen + junction + 2 * inner, + ':center_0': 1.5*intersection + 3*ring_edgelen + junction + 3*inner, + ':left_0': 2 * intersection + 3*ring_edgelen + 2*junction + 3*inner, # for aimsun 'bottom_to_top': intersection / 2 + inner, 'right_to_left': junction + 3 * inner, @@ -345,14 +345,14 @@ def _figure_eight(data, params, dt, num_steps): # create the output variables pos = np.zeros((num_steps, len(data.keys()))) speed = np.zeros((num_steps, len(data.keys()))) - for i, veh_id in enumerate(data.keys()): + for i, veh_id in enumerate(sorted(data.keys())): for spd, abs_pos, ti in zip(data[veh_id]['vel'], data[veh_id]['abs_pos'], data[veh_id]['time']): - if int(ti * (1 / dt)) >= num_steps: + if int(ti/dt)-1 >= num_steps: continue - speed[int(ti * (1 / dt)), i] = spd - pos[int(ti * (1 / dt)), i] = abs_pos + pos[int(ti/dt)-1, i] = abs_pos + speed[int(ti/dt)-1, i] = spd # reorganize data for space-time plot figure8_len = 6*ring_edgelen + 2*intersection + 2*junction + 10*inner @@ -367,34 +367,6 @@ def _figure_eight(data, params, dt, num_steps): return pos, speed -def create_parser(): - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description='[Flow] Generates time space diagrams for flow networks.', - epilog='python time_space_diagram.py .csv ' - '.json') - - # required arguments - parser.add_argument('emission_path', type=str, - help='path to the csv file.') - parser.add_argument('flow_params', type=str, - help='path to the flow_params json file.') - - # optional arguments - parser.add_argument('--steps', type=int, default=1, - help='rate at which steps are plotted.') - parser.add_argument('--title', type=str, default='Time Space Diagram', - help='rate at which steps are plotted.') - parser.add_argument('--max_speed', type=int, default=8, - help='The maximum speed in the color range.') - parser.add_argument('--start', type=float, default=0, - help='initial time (in sec) in the plot.') - parser.add_argument('--stop', type=float, default=float('inf'), - help='final time (in sec) in the plot.') - - return parser - - def _get_abs_pos(edge, rel_pos, edgestarts): """Compute the absolute positions from edges and relative positions. @@ -421,8 +393,31 @@ def _get_abs_pos(edge, rel_pos, edgestarts): if __name__ == '__main__': - # import parser arguments - parser = create_parser() + # create the parser + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description='[Flow] Generates time space diagrams for flow networks.', + epilog='python time_space_diagram.py .csv ' + '.json') + + # required arguments + parser.add_argument('emission_path', type=str, + help='path to the csv file.') + parser.add_argument('flow_params', type=str, + help='path to the flow_params json file.') + + # optional arguments + parser.add_argument('--steps', type=int, default=1, + help='rate at which steps are plotted.') + parser.add_argument('--title', type=str, default='Time Space Diagram', + help='rate at which steps are plotted.') + parser.add_argument('--max_speed', type=int, default=8, + help='The maximum speed in the color range.') + parser.add_argument('--start', type=float, default=0, + help='initial time (in sec) in the plot.') + parser.add_argument('--stop', type=float, default=float('inf'), + help='final time (in sec) in the plot.') + args = parser.parse_args() # flow_params is imported as a dictionary @@ -454,7 +449,7 @@ def _get_abs_pos(edge, rel_pos, edgestarts): norm = plt.Normalize(0, args.max_speed) cols = [] - xmin = max(0, args.start) + xmin = max(sim_step, args.start) xmax = min(total_time, args.stop) xbuffer = (xmax - xmin) * 0.025 # 2.5% of range ymin, ymax = np.amin(pos), np.amax(pos) diff --git a/tests/fast_tests/test_files/fig8.json b/tests/fast_tests/test_files/fig8.json index a4d9bc603..bd76859d9 100644 --- a/tests/fast_tests/test_files/fig8.json +++ b/tests/fast_tests/test_files/fig8.json @@ -56,7 +56,7 @@ "seed": null, "show_radius": false, "sight_radius": 25, - "sim_step": 0.1, + "sim_step": 1.0, "teleport_time": -1 }, "simulator": "traci", diff --git a/tests/fast_tests/test_files/loop_260.json b/tests/fast_tests/test_files/loop_260.json deleted file mode 100644 index dd5f34a4b..000000000 --- a/tests/fast_tests/test_files/loop_260.json +++ /dev/null @@ -1,153 +0,0 @@ -{ - "env": { - "additional_params": { - "max_accel": 1, - "max_decel": 1, - "ring_length": [ - 220, - 270 - ] - }, - "clip_actions": false, - "evaluate": false, - "horizon": 3000, - "sims_per_step": 1, - "warmup_steps": 750 - }, - "env_name": "WaveAttenuationPOEnv", - "exp_tag": "stabilizing_the_ring", - "initial": { - "additional_params": {}, - "bunching": 0, - "edges_distribution": "all", - "lanes_distribution": Infinity, - "min_gap": 0, - "perturbation": 0.0, - "shuffle": false, - "spacing": "uniform", - "x0": 0 - }, - "net": { - "additional_params": { - "lanes": 1, - "length": 260, - "resolution": 40, - "speed_limit": 30 - }, - "inflows": { - "_InFlows__flows": [], - "num_flows": 0 - }, - "no_internal_links": true, - "osm_path": null, - "template": null - }, - "scenario": "LoopScenario", - "sim": { - "emission_path": null, - "lateral_resolution": null, - "no_step_log": true, - "num_clients": 1, - "overtake_right": false, - "port": null, - "print_warnings": true, - "pxpm": 2, - "render": false, - "restart_instance": false, - "save_render": false, - "seed": null, - "show_radius": false, - "sight_radius": 25, - "sim_step": 0.1, - "teleport_time": -1 - }, - "simulator": "traci", - "veh": [ - { - "acceleration_controller": [ - "IDMController", - { - "noise": 0.2 - } - ], - "car_following_params": { - "controller_params": { - "accel": 1.0, - "carFollowModel": "IDM", - "decel": 1.5, - "impatience": 0.5, - "maxSpeed": 30, - "minGap": 2.5, - "sigma": 0.5, - "speedDev": 0.1, - "speedFactor": 1.0, - "tau": 1.0 - }, - "speed_mode": 25 - }, - "initial_speed": 0, - "lane_change_controller": [ - "SimLaneChangeController", - {} - ], - "lane_change_params": { - "controller_params": { - "laneChangeModel": "LC2013", - "lcCooperative": "1.0", - "lcKeepRight": "1.0", - "lcSpeedGain": "1.0", - "lcStrategic": "1.0" - }, - "lane_change_mode": 512 - }, - "num_vehicles": 21, - "routing_controller": [ - "ContinuousRouter", - {} - ], - "veh_id": "human" - }, - { - "acceleration_controller": [ - "RLController", - {} - ], - "car_following_params": { - "controller_params": { - "accel": 1.0, - "carFollowModel": "IDM", - "decel": 1.5, - "impatience": 0.5, - "maxSpeed": 30, - "minGap": 2.5, - "sigma": 0.5, - "speedDev": 0.1, - "speedFactor": 1.0, - "tau": 1.0 - }, - "speed_mode": 25 - }, - "initial_speed": 0, - "lane_change_controller": [ - "SimLaneChangeController", - {} - ], - "lane_change_params": { - "controller_params": { - "laneChangeModel": "LC2013", - "lcCooperative": "1.0", - "lcKeepRight": "1.0", - "lcSpeedGain": "1.0", - "lcStrategic": "1.0" - }, - "lane_change_mode": 512 - }, - "num_vehicles": 1, - "routing_controller": [ - "ContinuousRouter", - {} - ], - "veh_id": "rl" - } - ] -} \ No newline at end of file diff --git a/tests/fast_tests/test_files/merge.json b/tests/fast_tests/test_files/merge.json index 655a58baf..04a993a2b 100644 --- a/tests/fast_tests/test_files/merge.json +++ b/tests/fast_tests/test_files/merge.json @@ -89,7 +89,7 @@ "seed": null, "show_radius": false, "sight_radius": 25, - "sim_step": 0.5, + "sim_step": 0.2, "teleport_time": -1 }, "simulator": "traci", diff --git a/tests/fast_tests/test_visualizers.py b/tests/fast_tests/test_visualizers.py index 0e7551086..efcd7b2b2 100644 --- a/tests/fast_tests/test_visualizers.py +++ b/tests/fast_tests/test_visualizers.py @@ -176,11 +176,109 @@ def test_time_space_diagram_figure_eight(self): os.path.join(dir_path, 'test_files/fig8_emission.csv')) self.assertDictEqual(fig8_emission_data, actual_emission_data) + # test get_time_space_data for figure eight networks + flow_params = tsd.get_flow_params( + os.path.join(dir_path, 'test_files/fig8.json')) + pos, speed = tsd.get_time_space_data(actual_emission_data, flow_params) + + expected_pos = np.array( + [[60, 23.8, 182.84166941, 154.07166941, 125.30166941, 96.54166941, + -203.16166941, -174.40166941, -145.63166941, -116.86166941, + -88.09166941, -59.33, -30.56, -1.79], + [59, 22.81, 181.85166941, 153.08166941, 124.31166941, 95.54166941, + -202.17166941, -173.40166941, -144.64166941, -115.87166941, + -87.10166941, -58.34, -29.72, -0.8], + [57.02, 20.83, 179.87166941, 151.10166941, 122.34166941, + 93.56166941, -200.02166941, -171.43166941, -142.66166941, + -113.89166941, -85.13166941, -56.36, -27.97, 208.64166941]] + ) + expected_speed = np.array([ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, 0.99, + 0.99, 0.84, 0.99], + [1.99, 1.98, 1.98, 1.98, 1.98, 1.98, 1.97, 1.98, 1.98, 1.98, 1.97, + 1.97, 1.76, 1.97] + ]) + + np.testing.assert_array_almost_equal(pos, expected_pos) + np.testing.assert_array_almost_equal(speed, expected_speed) + def test_time_space_diagram_merge(self): - pass + dir_path = os.path.dirname(os.path.realpath(__file__)) + emission_data = tsd.import_data_from_emission( + os.path.join(dir_path, 'test_files/merge_emission.csv')) + + flow_params = tsd.get_flow_params( + os.path.join(dir_path, 'test_files/merge.json')) + pos, speed = tsd.get_time_space_data(emission_data, flow_params) + + expected_pos = np.array( + [[4.86, 180.32, 361.32, 547.77, 0], + [4.95, 180.43, 361.44, 547.87, 0], + [0, 0, 0, 0, 0], + [5.06, 180.54, 361.56, 547.98, 0], + [5.4, 180.86, 361.72, 548.12, 0]] + ) + expected_speed = np.array( + [[0, 0, 0, 0, 0], + [0.35, 0.37, 0.39, 0.34, 0.], + [0, 0, 0, 0, 0], + [0.54, 0.57, 0.59, 0.54, 0], + [0.94, 0.9, 0.79, 0.71, 0]] + ) + + np.testing.assert_array_almost_equal(pos, expected_pos) + np.testing.assert_array_almost_equal(speed, expected_speed) def test_time_space_diagram_ring_road(self): - pass + dir_path = os.path.dirname(os.path.realpath(__file__)) + emission_data = tsd.import_data_from_emission( + os.path.join(dir_path, 'test_files/loop_230_emission.csv')) + + flow_params = tsd.get_flow_params( + os.path.join(dir_path, 'test_files/loop_230.json')) + pos, speed = tsd.get_time_space_data(emission_data, flow_params) + + expected_pos = np.array([ + [0.0000e+00, 9.5500e+00, 9.5450e+01, 1.0500e+02, 1.1455e+02, + 1.2409e+02, 1.3364e+02, 1.4318e+02, 1.5273e+02, 1.6227e+02, + 1.7182e+02, 1.8136e+02, 1.9090e+01, 1.9091e+02, 2.0045e+02, + 2.8640e+01, 3.8180e+01, 4.7730e+01, 5.7270e+01, 6.6820e+01, + 7.6360e+01, 8.5910e+01], + [2.0000e-02, 9.5700e+00, 9.5480e+01, 1.0502e+02, 1.1457e+02, + 1.2411e+02, 1.3366e+02, 1.4321e+02, 1.5275e+02, 1.6230e+02, + 1.7184e+02, 1.8139e+02, 1.9110e+01, 1.9093e+02, 2.0048e+02, + 2.8660e+01, 3.8210e+01, 4.7750e+01, 5.7300e+01, 6.6840e+01, + 7.6390e+01, 8.5930e+01], + [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00], + [5.0000e-02, 9.5900e+00, 9.5500e+01, 1.0505e+02, 1.1459e+02, + 1.2414e+02, 1.3368e+02, 1.4323e+02, 1.5277e+02, 1.6232e+02, + 1.7187e+02, 1.8141e+02, 1.9140e+01, 1.9096e+02, 2.0051e+02, + 2.8680e+01, 3.8230e+01, 4.7770e+01, 5.7320e+01, 6.6870e+01, + 7.6410e+01, 8.5960e+01], + [1.2000e-01, 9.6600e+00, 9.5570e+01, 1.0512e+02, 1.1466e+02, + 1.2421e+02, 1.3371e+02, 1.4326e+02, 1.5281e+02, 1.6235e+02, + 1.7190e+02, 1.8144e+02, 1.9170e+01, 1.9099e+02, 2.0055e+02, + 2.8710e+01, 3.8260e+01, 4.7810e+01, 5.7350e+01, 6.6900e+01, + 7.6440e+01, 8.5990e+01] + ]) + expected_speed = np.array([ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, + 0.16, 0.16, 0.16, 0.2, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, + 0.23, 0.23, 0.23, 0.29, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23], + [0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.31, 0.31, 0.31, 0.31, 0.31, + 0.31, 0.31, 0.31, 0.39, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31] + ]) + + np.testing.assert_array_almost_equal(pos, expected_pos) + np.testing.assert_array_almost_equal(speed, expected_speed) if __name__ == '__main__': From 0fd1da4f52b776cd23fe32912007233dd568a845 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 20 May 2019 13:07:18 -0700 Subject: [PATCH 6/9] bug fixes --- .../test_files/loop_230_emission.csv | 117 ++++++++++++++++++ .../fast_tests/test_files/merge_emission.csv | 28 +++++ 2 files changed, 145 insertions(+) create mode 100644 tests/fast_tests/test_files/loop_230_emission.csv create mode 100644 tests/fast_tests/test_files/merge_emission.csv diff --git a/tests/fast_tests/test_files/loop_230_emission.csv b/tests/fast_tests/test_files/loop_230_emission.csv new file mode 100644 index 000000000..9051074c8 --- /dev/null +++ b/tests/fast_tests/test_files/loop_230_emission.csv @@ -0,0 +1,117 @@ +speed,CO,electricity,x,NOx,id,fuel,angle,time,edge_id,eclass,route,waiting,CO2,lane_number,PMx,type,noise,relative_position,HC,y +0.0,164.78,0.0,36.64,1.2,idm_0,1.13,94.02,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,0.0,0.81,-1.65 +0.08,163.5,0.0,36.65,1.21,idm_0,1.13,94.01,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,0.01,0.81,-1.65 +0.16,162.24,0.0,36.66,1.21,idm_0,1.13,93.98,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,0.02,0.8,-1.65 +0.23,161.0,0.0,36.69,1.21,idm_0,1.14,93.94,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,0.05,0.79,-1.65 +0.31,159.78,0.0,36.72,1.21,idm_0,1.14,93.88,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,0.08,0.79,-1.65 +0.41,158.73,0.0,36.76,1.22,idm_0,1.15,93.8,0.6,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2679.14,0,0.07,idm,60.47,0.12,0.79,-1.65 +0.0,164.78,0.0,46.49,1.2,idm_1,1.13,78.81,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,9.55,0.81,-0.34 +0.08,163.5,0.0,46.5,1.21,idm_1,1.13,78.8,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,9.55,0.81,-0.33 +0.16,162.24,0.0,46.51,1.21,idm_1,1.13,78.78,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,9.57,0.8,-0.33 +0.23,161.0,0.0,46.54,1.21,idm_1,1.14,78.74,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,9.59,0.79,-0.32 +0.31,159.78,0.0,46.57,1.21,idm_1,1.14,78.7,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,9.62,0.79,-0.31 +0.41,158.73,0.0,46.61,1.22,idm_1,1.15,78.64,0.6,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2679.14,0,0.07,idm,60.47,9.66,0.79,-0.3 +0.0,164.78,0.0,56.08,1.2,idm_10,1.13,304.55,0.1,right,HBEFA3/PC_G_EU4,routeright,0.0,2624.72,0,0.07,idm,55.94,37.95,0.81,69.53 +0.08,163.5,0.0,56.08,1.21,idm_10,1.13,304.54,0.2,right,HBEFA3/PC_G_EU4,routeright,0.1,2631.03,0,0.07,idm,59.48,37.96,0.81,69.53 +0.16,162.24,0.0,56.06,1.21,idm_10,1.13,304.52,0.3,right,HBEFA3/PC_G_EU4,routeright,0.0,2636.67,0,0.07,idm,59.44,37.98,0.8,69.54 +0.23,161.0,0.0,56.04,1.21,idm_10,1.14,304.48,0.4,right,HBEFA3/PC_G_EU4,routeright,0.0,2641.63,0,0.07,idm,59.4,38.0,0.79,69.55 +0.31,159.78,0.0,56.01,1.21,idm_10,1.14,304.44,0.5,right,HBEFA3/PC_G_EU4,routeright,0.0,2645.91,0,0.06,idm,59.36,38.03,0.79,69.57 +0.41,158.73,0.0,55.98,1.22,idm_10,1.15,304.38,0.6,right,HBEFA3/PC_G_EU4,routeright,0.0,2679.14,0,0.07,idm,60.47,38.07,0.79,69.59 +0.0,164.78,0.0,46.95,1.2,idm_11,1.13,289.47,0.1,right,HBEFA3/PC_G_EU4,routeright,0.0,2624.72,0,0.07,idm,55.94,47.5,0.81,73.43 +0.08,163.5,0.0,46.94,1.21,idm_11,1.13,289.45,0.2,right,HBEFA3/PC_G_EU4,routeright,0.1,2631.03,0,0.07,idm,59.48,47.51,0.81,73.43 +0.16,162.24,0.0,46.92,1.21,idm_11,1.13,289.42,0.3,right,HBEFA3/PC_G_EU4,routeright,0.0,2636.67,0,0.07,idm,59.44,47.52,0.8,73.44 +0.23,161.0,0.0,46.9,1.21,idm_11,1.14,289.38,0.4,right,HBEFA3/PC_G_EU4,routeright,0.0,2641.63,0,0.07,idm,59.4,47.55,0.79,73.44 +0.31,159.78,0.0,46.87,1.21,idm_11,1.14,289.32,0.5,right,HBEFA3/PC_G_EU4,routeright,0.0,2645.91,0,0.06,idm,59.36,47.58,0.79,73.45 +0.41,158.73,0.0,46.83,1.22,idm_11,1.15,289.24,0.6,right,HBEFA3/PC_G_EU4,routeright,0.0,2679.14,0,0.07,idm,60.47,47.62,0.79,73.46 +0.0,164.78,0.0,37.11,1.2,idm_12,1.13,274.71,0.1,right,HBEFA3/PC_G_EU4,routeright,0.0,2624.72,0,0.07,idm,55.94,57.05,0.81,74.86 +0.08,163.5,0.0,37.11,1.21,idm_12,1.13,274.7,0.2,right,HBEFA3/PC_G_EU4,routeright,0.1,2631.03,0,0.07,idm,59.48,57.05,0.81,74.86 +0.16,162.24,0.0,37.09,1.21,idm_12,1.13,274.68,0.3,right,HBEFA3/PC_G_EU4,routeright,0.0,2636.67,0,0.07,idm,59.44,57.07,0.8,74.86 +0.23,161.0,0.0,37.07,1.21,idm_12,1.14,274.65,0.4,right,HBEFA3/PC_G_EU4,routeright,0.0,2641.63,0,0.07,idm,59.4,57.09,0.79,74.86 +0.31,159.78,0.0,37.03,1.21,idm_12,1.14,274.6,0.5,right,HBEFA3/PC_G_EU4,routeright,0.0,2645.91,0,0.06,idm,59.36,57.12,0.79,74.86 +0.41,158.73,0.0,36.99,1.22,idm_12,1.15,274.55,0.6,right,HBEFA3/PC_G_EU4,routeright,0.0,2679.14,0,0.07,idm,60.47,57.16,0.79,74.86 +0.0,164.78,0.0,27.19,1.2,idm_13,1.13,259.6,0.1,top,HBEFA3/PC_G_EU4,routetop,0.0,2624.72,0,0.07,idm,55.94,9.09,0.81,73.68 +0.08,163.5,0.0,27.18,1.21,idm_13,1.13,259.58,0.2,top,HBEFA3/PC_G_EU4,routetop,0.1,2631.03,0,0.07,idm,59.48,9.1,0.81,73.68 +0.16,162.24,0.0,27.17,1.21,idm_13,1.13,259.55,0.3,top,HBEFA3/PC_G_EU4,routetop,0.0,2636.67,0,0.07,idm,59.44,9.11,0.8,73.67 +0.23,161.0,0.0,27.14,1.21,idm_13,1.14,259.51,0.4,top,HBEFA3/PC_G_EU4,routetop,0.0,2641.63,0,0.07,idm,59.4,9.14,0.79,73.67 +0.31,159.78,0.0,27.11,1.21,idm_13,1.14,259.45,0.5,top,HBEFA3/PC_G_EU4,routetop,0.0,2645.91,0,0.06,idm,59.36,9.17,0.79,73.66 +0.41,158.73,0.0,27.07,1.22,idm_13,1.15,259.37,0.6,top,HBEFA3/PC_G_EU4,routetop,0.0,2679.14,0,0.07,idm,60.47,9.21,0.79,73.65 +0.0,164.78,0.0,17.96,1.2,idm_14,1.13,244.67,0.1,top,HBEFA3/PC_G_EU4,routetop,0.0,2624.72,0,0.07,idm,55.94,18.64,0.81,70.0 +0.08,163.5,0.0,17.95,1.21,idm_14,1.13,244.66,0.2,top,HBEFA3/PC_G_EU4,routetop,0.1,2631.03,0,0.07,idm,59.48,18.64,0.81,70.0 +0.16,162.24,0.0,17.94,1.21,idm_14,1.13,244.63,0.3,top,HBEFA3/PC_G_EU4,routetop,0.0,2636.67,0,0.07,idm,59.44,18.66,0.8,69.99 +0.23,161.0,0.0,17.92,1.21,idm_14,1.14,244.6,0.4,top,HBEFA3/PC_G_EU4,routetop,0.0,2641.63,0,0.07,idm,59.4,18.68,0.79,69.98 +0.31,159.78,0.0,17.89,1.21,idm_14,1.14,244.55,0.5,top,HBEFA3/PC_G_EU4,routetop,0.0,2645.91,0,0.06,idm,59.36,18.71,0.79,69.96 +0.0,164.78,0.0,9.98,1.2,idm_15,1.13,229.84,0.1,top,HBEFA3/PC_G_EU4,routetop,0.0,2624.72,0,0.07,idm,55.94,28.18,0.81,64.07 +0.08,163.5,0.0,9.98,1.21,idm_15,1.13,229.83,0.2,top,HBEFA3/PC_G_EU4,routetop,0.1,2631.03,0,0.07,idm,59.48,28.19,0.81,64.07 +0.16,162.24,0.0,9.97,1.21,idm_15,1.13,229.8,0.3,top,HBEFA3/PC_G_EU4,routetop,0.0,2636.67,0,0.07,idm,59.44,28.21,0.8,64.06 +0.23,161.0,0.0,9.95,1.21,idm_15,1.14,229.76,0.4,top,HBEFA3/PC_G_EU4,routetop,0.0,2641.63,0,0.07,idm,59.4,28.23,0.79,64.04 +0.31,159.78,0.0,9.93,1.21,idm_15,1.14,229.7,0.5,top,HBEFA3/PC_G_EU4,routetop,0.0,2645.91,0,0.06,idm,59.36,28.26,0.79,64.02 +0.0,164.78,0.0,3.81,1.2,idm_16,1.13,214.88,0.1,top,HBEFA3/PC_G_EU4,routetop,0.0,2624.72,0,0.07,idm,55.94,37.73,0.81,56.29 +0.08,163.5,0.0,3.81,1.21,idm_16,1.13,214.87,0.2,top,HBEFA3/PC_G_EU4,routetop,0.1,2631.03,0,0.07,idm,59.48,37.74,0.81,56.28 +0.16,162.24,0.0,3.8,1.21,idm_16,1.13,214.85,0.3,top,HBEFA3/PC_G_EU4,routetop,0.0,2636.67,0,0.07,idm,59.44,37.75,0.8,56.27 +0.23,161.0,0.0,3.79,1.21,idm_16,1.14,214.81,0.4,top,HBEFA3/PC_G_EU4,routetop,0.0,2641.63,0,0.07,idm,59.4,37.77,0.79,56.24 +0.31,159.78,0.0,3.77,1.21,idm_16,1.14,214.77,0.5,top,HBEFA3/PC_G_EU4,routetop,0.0,2645.91,0,0.06,idm,59.36,37.81,0.79,56.22 +0.0,164.78,0.0,-0.15,1.2,idm_17,1.13,199.9,0.1,top,HBEFA3/PC_G_EU4,routetop,0.0,2624.72,0,0.07,idm,55.94,47.27,0.81,47.18 +0.08,163.5,0.0,-0.15,1.21,idm_17,1.13,199.88,0.2,top,HBEFA3/PC_G_EU4,routetop,0.1,2631.03,0,0.07,idm,59.48,47.28,0.81,47.17 +0.16,162.24,0.0,-0.16,1.21,idm_17,1.13,199.85,0.3,top,HBEFA3/PC_G_EU4,routetop,0.0,2636.67,0,0.07,idm,59.44,47.3,0.8,47.15 +0.23,161.0,0.0,-0.16,1.21,idm_17,1.14,199.81,0.4,top,HBEFA3/PC_G_EU4,routetop,0.0,2641.63,0,0.07,idm,59.4,47.32,0.79,47.13 +0.31,159.78,0.0,-0.17,1.21,idm_17,1.14,199.75,0.5,top,HBEFA3/PC_G_EU4,routetop,0.0,2645.91,0,0.06,idm,59.36,47.35,0.79,47.1 +0.0,164.78,0.0,-1.64,1.2,idm_18,1.13,185.04,0.1,top,HBEFA3/PC_G_EU4,routetop,0.0,2624.72,0,0.07,idm,55.94,56.82,0.81,37.35 +0.08,163.5,0.0,-1.64,1.21,idm_18,1.13,185.03,0.2,top,HBEFA3/PC_G_EU4,routetop,0.1,2631.03,0,0.07,idm,59.48,56.83,0.81,37.34 +0.16,162.24,0.0,-1.64,1.21,idm_18,1.13,185.0,0.3,top,HBEFA3/PC_G_EU4,routetop,0.0,2636.67,0,0.07,idm,59.44,56.84,0.8,37.33 +0.23,161.0,0.0,-1.64,1.21,idm_18,1.14,184.97,0.4,top,HBEFA3/PC_G_EU4,routetop,0.0,2641.63,0,0.07,idm,59.4,56.87,0.79,37.3 +0.31,159.78,0.0,-1.64,1.21,idm_18,1.14,184.93,0.5,top,HBEFA3/PC_G_EU4,routetop,0.0,2645.91,0,0.06,idm,59.36,56.9,0.79,37.27 +0.0,164.78,0.0,-0.52,1.2,idm_19,1.13,170.03,0.1,left,HBEFA3/PC_G_EU4,routeleft,0.0,2624.72,0,0.07,idm,55.94,8.86,0.81,27.42 +0.08,163.5,0.0,-0.52,1.21,idm_19,1.13,170.01,0.2,left,HBEFA3/PC_G_EU4,routeleft,0.1,2631.03,0,0.07,idm,59.48,8.87,0.81,27.41 +0.16,162.24,0.0,-0.51,1.21,idm_19,1.13,169.98,0.3,left,HBEFA3/PC_G_EU4,routeleft,0.0,2636.67,0,0.07,idm,59.44,8.89,0.8,27.39 +0.23,161.0,0.0,-0.51,1.21,idm_19,1.14,169.94,0.4,left,HBEFA3/PC_G_EU4,routeleft,0.0,2641.63,0,0.07,idm,59.4,8.91,0.79,27.37 +0.31,159.78,0.0,-0.5,1.21,idm_19,1.14,169.88,0.5,left,HBEFA3/PC_G_EU4,routeleft,0.0,2645.91,0,0.06,idm,59.36,8.94,0.79,27.34 +0.0,164.78,0.0,55.68,1.2,idm_2,1.13,64.0,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,19.09,0.81,3.45 +0.08,163.5,0.0,55.68,1.21,idm_2,1.13,63.99,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,19.1,0.81,3.45 +0.16,162.24,0.0,55.7,1.21,idm_2,1.13,63.97,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,19.11,0.8,3.46 +0.23,161.0,0.0,55.72,1.21,idm_2,1.14,63.93,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,19.14,0.79,3.47 +0.31,159.78,0.0,55.75,1.21,idm_2,1.14,63.88,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,19.17,0.79,3.49 +0.0,164.78,0.0,3.11,1.2,idm_20,1.13,155.0,0.1,left,HBEFA3/PC_G_EU4,routeleft,0.0,2624.72,0,0.07,idm,55.94,18.41,0.81,18.17 +0.08,163.5,0.0,3.11,1.21,idm_20,1.13,154.99,0.2,left,HBEFA3/PC_G_EU4,routeleft,0.1,2631.03,0,0.07,idm,59.48,18.42,0.81,18.16 +0.16,162.24,0.0,3.12,1.21,idm_20,1.13,154.96,0.3,left,HBEFA3/PC_G_EU4,routeleft,0.0,2636.68,0,0.07,idm,59.44,18.43,0.8,18.15 +0.23,161.0,0.0,3.13,1.21,idm_20,1.14,154.93,0.4,left,HBEFA3/PC_G_EU4,routeleft,0.0,2641.7,0,0.07,idm,59.41,18.46,0.79,18.12 +0.31,159.77,0.0,3.15,1.21,idm_20,1.14,154.89,0.5,left,HBEFA3/PC_G_EU4,routeleft,0.0,2646.14,0,0.06,idm,59.37,18.49,0.79,18.1 +0.0,164.78,0.0,8.98,1.2,idm_21,1.13,140.22,0.1,left,HBEFA3/PC_G_EU4,routeleft,0.0,2624.72,0,0.07,idm,55.94,27.95,0.81,10.15 +0.1,163.3,0.0,8.99,1.21,idm_21,1.13,140.21,0.2,left,HBEFA3/PC_G_EU4,routeleft,0.1,2637.25,0,0.07,idm,60.3,27.96,0.81,10.15 +0.2,161.84,0.0,9.0,1.21,idm_21,1.14,140.18,0.3,left,HBEFA3/PC_G_EU4,routeleft,0.0,2649.89,0,0.07,idm,60.34,27.98,0.8,10.13 +0.29,160.38,0.0,9.02,1.21,idm_21,1.14,140.14,0.4,left,HBEFA3/PC_G_EU4,routeleft,0.0,2662.63,0,0.07,idm,60.37,28.01,0.79,10.11 +0.39,158.94,0.0,9.05,1.22,idm_21,1.15,140.07,0.5,left,HBEFA3/PC_G_EU4,routeleft,0.0,2675.48,0,0.07,idm,60.41,28.05,0.79,10.08 +0.0,164.78,0.0,63.57,1.2,idm_3,1.13,49.05,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,28.64,0.81,9.48 +0.08,163.5,0.0,63.58,1.21,idm_3,1.13,49.04,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,28.64,0.81,9.49 +0.16,162.24,0.0,63.59,1.21,idm_3,1.13,49.02,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,28.66,0.8,9.5 +0.23,161.0,0.0,63.61,1.21,idm_3,1.14,48.99,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,28.68,0.79,9.52 +0.31,159.78,0.0,63.63,1.21,idm_3,1.14,48.94,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,28.71,0.79,9.54 +0.0,164.78,0.0,69.65,1.2,idm_4,1.13,34.22,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,38.18,0.81,17.34 +0.08,163.5,0.0,69.65,1.21,idm_4,1.13,34.21,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,38.19,0.81,17.35 +0.16,162.24,0.0,69.66,1.21,idm_4,1.13,34.19,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,38.21,0.8,17.36 +0.23,161.0,0.0,69.68,1.21,idm_4,1.14,34.15,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,38.23,0.79,17.38 +0.31,159.78,0.0,69.69,1.21,idm_4,1.14,34.11,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,38.26,0.79,17.41 +0.0,164.78,0.0,73.49,1.2,idm_5,1.13,19.04,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,47.73,0.81,26.5 +0.08,163.5,0.0,73.5,1.21,idm_5,1.13,19.02,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,47.74,0.81,26.51 +0.16,162.24,0.0,73.5,1.21,idm_5,1.13,18.99,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,47.75,0.8,26.53 +0.23,161.0,0.0,73.51,1.21,idm_5,1.14,18.95,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,47.77,0.79,26.55 +0.31,159.78,0.0,73.52,1.21,idm_5,1.14,18.91,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,47.81,0.79,26.58 +0.0,164.78,0.0,74.87,1.2,idm_6,1.13,4.39,0.1,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2624.72,0,0.07,idm,55.94,57.27,0.81,36.34 +0.08,163.5,0.0,74.87,1.21,idm_6,1.13,4.38,0.2,bottom,HBEFA3/PC_G_EU4,routebottom,0.1,2631.03,0,0.07,idm,59.48,57.28,0.81,36.35 +0.16,162.24,0.0,74.87,1.21,idm_6,1.13,4.36,0.3,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2636.67,0,0.07,idm,59.44,57.3,0.8,36.37 +0.23,161.0,0.0,74.87,1.21,idm_6,1.14,4.32,0.4,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2641.63,0,0.07,idm,59.4,57.32,0.79,36.39 +0.31,159.78,0.0,74.87,1.21,idm_6,1.14,4.28,0.5,bottom,HBEFA3/PC_G_EU4,routebottom,0.0,2645.91,0,0.06,idm,59.36,57.35,0.79,36.42 +0.0,164.78,0.0,73.62,1.2,idm_7,1.13,349.16,0.1,right,HBEFA3/PC_G_EU4,routeright,0.0,2624.72,0,0.07,idm,55.94,9.32,0.81,46.26 +0.08,163.5,0.0,73.62,1.21,idm_7,1.13,349.15,0.2,right,HBEFA3/PC_G_EU4,routeright,0.1,2631.03,0,0.07,idm,59.48,9.33,0.81,46.27 +0.16,162.24,0.0,73.61,1.21,idm_7,1.13,349.12,0.3,right,HBEFA3/PC_G_EU4,routeright,0.0,2636.67,0,0.07,idm,59.44,9.34,0.8,46.28 +0.23,161.0,0.0,73.6,1.21,idm_7,1.14,349.07,0.4,right,HBEFA3/PC_G_EU4,routeright,0.0,2641.63,0,0.07,idm,59.4,9.37,0.79,46.31 +0.31,159.78,0.0,73.6,1.21,idm_7,1.14,349.01,0.5,right,HBEFA3/PC_G_EU4,routeright,0.0,2645.91,0,0.06,idm,59.36,9.4,0.79,46.34 +0.0,164.78,0.0,69.89,1.2,idm_8,1.13,334.33,0.1,right,HBEFA3/PC_G_EU4,routeright,0.0,2624.72,0,0.07,idm,55.94,18.86,0.81,55.47 +0.08,163.5,0.0,69.88,1.21,idm_8,1.13,334.32,0.2,right,HBEFA3/PC_G_EU4,routeright,0.1,2631.03,0,0.07,idm,59.48,18.87,0.81,55.47 +0.16,162.24,0.0,69.87,1.21,idm_8,1.13,334.3,0.3,right,HBEFA3/PC_G_EU4,routeright,0.0,2636.67,0,0.07,idm,59.44,18.89,0.8,55.49 +0.23,161.0,0.0,69.86,1.21,idm_8,1.14,334.27,0.4,right,HBEFA3/PC_G_EU4,routeright,0.0,2641.63,0,0.07,idm,59.4,18.91,0.79,55.51 +0.31,159.78,0.0,69.85,1.21,idm_8,1.14,334.22,0.5,right,HBEFA3/PC_G_EU4,routeright,0.0,2645.91,0,0.06,idm,59.36,18.94,0.79,55.54 +0.0,164.78,0.0,63.91,1.2,idm_9,1.13,319.44,0.1,right,HBEFA3/PC_G_EU4,routeright,0.0,2624.72,0,0.07,idm,55.94,28.41,0.81,63.4 +0.08,163.5,0.0,63.9,1.21,idm_9,1.13,319.42,0.2,right,HBEFA3/PC_G_EU4,routeright,0.1,2631.03,0,0.07,idm,59.48,28.42,0.81,63.41 +0.16,162.24,0.0,63.89,1.21,idm_9,1.13,319.39,0.3,right,HBEFA3/PC_G_EU4,routeright,0.0,2636.67,0,0.07,idm,59.44,28.43,0.8,63.42 +0.23,161.0,0.0,63.87,1.21,idm_9,1.14,319.35,0.4,right,HBEFA3/PC_G_EU4,routeright,0.0,2641.63,0,0.07,idm,59.4,28.46,0.79,63.44 +0.31,159.78,0.0,63.85,1.21,idm_9,1.14,319.3,0.5,right,HBEFA3/PC_G_EU4,routeright,0.0,2645.91,0,0.06,idm,59.36,28.49,0.79,63.46 diff --git a/tests/fast_tests/test_files/merge_emission.csv b/tests/fast_tests/test_files/merge_emission.csv new file mode 100644 index 000000000..25ed80e57 --- /dev/null +++ b/tests/fast_tests/test_files/merge_emission.csv @@ -0,0 +1,28 @@ +angle,edge_id,NOx,type,CO,CO2,relative_position,time,HC,fuel,speed,electricity,noise,eclass,id,PMx,waiting,y,route,x,lane_number +90.0,inflow_highway,1.2,human,164.78,2624.72,4.86,0.2,0.81,1.13,0.0,0.0,55.94,HBEFA3/PC_G_EU4,human_0,0.07,0.0,139.77,routeinflow_highway,4.86,0 +90.0,inflow_highway,1.2,human,162.37,2634.17,4.88,0.4,0.8,1.13,0.15,0.0,59.25,HBEFA3/PC_G_EU4,human_0,0.07,0.0,139.77,routeinflow_highway,4.88,0 +90.0,inflow_highway,1.22,human,159.64,2671.19,4.95,0.6,0.79,1.15,0.35,0.0,60.47,HBEFA3/PC_G_EU4,human_0,0.07,0.0,139.77,routeinflow_highway,4.95,0 +90.0,inflow_highway,1.22,human,156.75,2694.62,5.06,0.8,0.78,1.16,0.54,0.0,60.44,HBEFA3/PC_G_EU4,human_0,0.06,0.0,139.77,routeinflow_highway,5.06,0 +90.0,inflow_highway,1.23,human,153.97,2726.3,5.21,1.0,0.76,1.17,0.74,0.0,60.62,HBEFA3/PC_G_EU4,human_0,0.06,0.0,139.77,routeinflow_highway,5.21,0 +90.0,inflow_highway,1.24,human,151.17,2755.12,5.4,1.2,0.75,1.18,0.94,0.0,60.7,HBEFA3/PC_G_EU4,human_0,0.06,0.0,139.77,routeinflow_highway,5.4,0 +90.0,left,1.2,human,164.78,2624.72,80.22,0.2,0.81,1.13,0.0,0.0,55.94,HBEFA3/PC_G_EU4,human_1,0.07,0.0,139.77,routeleft,179.47,0 +90.0,left,1.21,human,162.08,2641.47,80.26,0.4,0.8,1.14,0.17,0.0,59.81,HBEFA3/PC_G_EU4,human_1,0.07,0.0,139.77,routeleft,179.5,0 +90.0,left,1.22,human,159.28,2673.68,80.33,0.6,0.79,1.15,0.37,0.0,60.45,HBEFA3/PC_G_EU4,human_1,0.07,0.0,139.77,routeleft,179.58,0 +90.0,left,1.23,human,156.41,2702.08,80.44,0.8,0.78,1.16,0.57,0.0,60.55,HBEFA3/PC_G_EU4,human_1,0.06,0.0,139.77,routeleft,179.69,0 +90.0,left,1.2,human,153.24,2655.58,80.58,1.0,0.76,1.14,0.7,0.0,59.05,HBEFA3/PC_G_EU4,human_1,0.06,0.0,139.77,routeleft,179.83,0 +90.0,left,1.24,human,151.76,2748.97,80.76,1.2,0.76,1.18,0.9,0.0,60.68,HBEFA3/PC_G_EU4,human_1,0.06,0.0,139.77,routeleft,180.01,0 +90.0,left,1.2,human,164.78,2624.72,261.22,0.2,0.81,1.13,0.0,0.0,55.94,HBEFA3/PC_G_EU4,human_2,0.07,0.0,139.77,routeleft,358.78,0 +90.0,left,1.21,human,161.88,2648.18,261.26,0.4,0.8,1.14,0.19,0.0,60.24,HBEFA3/PC_G_EU4,human_2,0.07,0.0,139.77,routeleft,358.82,0 +90.0,left,1.22,human,158.99,2677.26,261.34,0.6,0.79,1.15,0.39,0.0,60.49,HBEFA3/PC_G_EU4,human_2,0.07,0.0,139.77,routeleft,358.9,0 +90.0,left,1.23,human,156.11,2704.99,261.46,0.8,0.77,1.16,0.59,0.0,60.56,HBEFA3/PC_G_EU4,human_2,0.06,0.0,139.77,routeleft,359.01,0 +90.0,left,1.23,human,153.28,2733.34,261.62,1.0,0.76,1.18,0.79,0.0,60.64,HBEFA3/PC_G_EU4,human_2,0.06,0.0,139.77,routeleft,359.17,0 +90.0,left,1.2,human,164.78,2624.72,447.67,0.2,0.81,1.13,0.0,0.0,55.94,HBEFA3/PC_G_EU4,human_3,0.07,0.0,139.77,routeleft,543.48,0 +90.0,left,1.2,human,162.46,2632.41,447.7,0.4,0.8,1.13,0.14,0.0,59.09,HBEFA3/PC_G_EU4,human_3,0.07,0.0,139.77,routeleft,543.51,0 +90.0,left,1.22,human,159.74,2670.23,447.77,0.6,0.79,1.15,0.34,0.0,60.47,HBEFA3/PC_G_EU4,human_3,0.07,0.0,139.77,routeleft,543.58,0 +90.0,left,1.22,human,156.85,2697.8,447.88,0.8,0.78,1.16,0.54,0.0,60.54,HBEFA3/PC_G_EU4,human_3,0.06,0.0,139.77,routeleft,543.68,0 +90.0,left,1.22,human,153.85,2692.25,448.02,1.0,0.76,1.16,0.71,0.0,59.91,HBEFA3/PC_G_EU4,human_3,0.06,0.0,139.77,routeleft,543.82,0 +45.0,inflow_merge,1.2,human,164.78,2624.72,6.89,0.2,0.81,1.13,0.0,0.0,55.94,HBEFA3/PC_G_EU4,human_4,0.07,0.0,3.7,routeinflow_merge,464.62,0 +45.0,inflow_merge,1.21,human,161.8,2651.22,6.93,0.4,0.8,1.14,0.2,0.0,60.41,HBEFA3/PC_G_EU4,human_4,0.07,0.0,3.73,routeinflow_merge,464.65,0 +45.0,inflow_merge,1.22,human,158.88,2678.34,7.01,0.6,0.79,1.15,0.4,0.0,60.49,HBEFA3/PC_G_EU4,human_4,0.07,0.0,3.78,routeinflow_merge,464.7,0 +45.0,inflow_merge,1.23,human,156.0,2706.1,7.13,0.8,0.77,1.16,0.6,0.0,60.57,HBEFA3/PC_G_EU4,human_4,0.06,0.0,3.87,routeinflow_merge,464.79,0 +45.0,inflow_merge,1.23,human,153.07,2719.03,7.28,1.0,0.76,1.17,0.79,0.0,60.35,HBEFA3/PC_G_EU4,human_4,0.06,0.0,3.98,routeinflow_merge,464.9,0 From 6a98de289a02db6bd0c715affac9242a52c633e3 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 10 Jun 2019 16:48:36 +0300 Subject: [PATCH 7/9] bug fix to visualizers --- flow/visualize/time_space_diagram.py | 94 +++++++++++++--------------- tests/fast_tests/test_visualizers.py | 91 +++++++++++++++------------ 2 files changed, 93 insertions(+), 92 deletions(-) diff --git a/flow/visualize/time_space_diagram.py b/flow/visualize/time_space_diagram.py index 2dff7949e..905a6a4a5 100644 --- a/flow/visualize/time_space_diagram.py +++ b/flow/visualize/time_space_diagram.py @@ -105,6 +105,9 @@ def get_time_space_data(data, params): n_steps x n_veh matrix specifying the speed of every vehicle at every time step. Set to zero if the vehicle is not present in the network at that time step. + as_array + a (n_steps,) vector representing the unique time steps in the + simulation Raises ------ @@ -122,22 +125,22 @@ def get_time_space_data(data, params): 'Figure8Scenario': _figure_eight } - # simulation step size - dt = params['sim'].sim_step - - # number of simulation steps - max_time = max(max(data[veh_id]['time']) for veh_id in data.keys()) - min_time = min(min(data[veh_id]['time']) for veh_id in data.keys()) - num_steps = int((max_time - min_time)/dt) + # Collect a list of all the unique times. + all_time = [] + for veh_id in data.keys(): + all_time.extend(data[veh_id]['time']) + all_time = np.sort(np.unique(all_time)) # Get the function from switcher dictionary func = switcher[params['scenario']] # Execute the function - return func(data, params, dt, num_steps) + pos, speed = func(data, params, all_time) + return pos, speed, all_time -def _merge(data, params, dt, num_steps): + +def _merge(data, params, all_time): """Generate position and speed data for the merge. This only include vehicles on the main highway, and not on the adjacent @@ -154,10 +157,9 @@ def _merge(data, params, dt, num_steps): * "vel": speed at every sample params : dict flow-specific parameters - dt : float - simulation step size - num_steps : int - number of simulation steps + all_time : array_like + a (n_steps,) vector representing the unique time steps in the + simulation Returns ------- @@ -195,24 +197,24 @@ def _merge(data, params, dt, num_steps): # prepare the speed and absolute position in a way that is compatible with # the space-time diagram, and compute the number of vehicles at each step - pos = np.zeros((num_steps, len(data.keys()))) - speed = np.zeros((num_steps, len(data.keys()))) + pos = np.zeros((all_time.shape[0], len(data.keys()))) + speed = np.zeros((all_time.shape[0], len(data.keys()))) for i, veh_id in enumerate(sorted(data.keys())): for spd, abs_pos, ti, edge in zip(data[veh_id]['vel'], data[veh_id]['abs_pos'], data[veh_id]['time'], data[veh_id]['edge']): # avoid vehicles outside the main highway - if int(ti/dt)-1 >= num_steps or \ - edge in ['inflow_merge', 'bottom', ':bottom_0']: + if edge in ['inflow_merge', 'bottom', ':bottom_0']: continue - pos[int(ti/dt)-1, i] = abs_pos - speed[int(ti/dt)-1, i] = spd + ind = np.where(ti == all_time)[0] + pos[ind, i] = abs_pos + speed[ind, i] = spd return pos, speed -def _ring_road(data, params, dt, num_steps): +def _ring_road(data, params, all_time): """Generate position and speed data for the ring road. Vehicles that reach the top of the plot simply return to the bottom and @@ -229,10 +231,9 @@ def _ring_road(data, params, dt, num_steps): * "vel": speed at every sample params : dict flow-specific parameters - dt : float - simulation step size - num_steps : int - number of simulation steps + all_time : array_like + a (n_steps,) vector representing the unique time steps in the + simulation Returns ------- @@ -262,21 +263,20 @@ def _ring_road(data, params, dt, num_steps): data[veh_id]['pos'], edgestarts) # create the output variables - pos = np.zeros((num_steps, len(data.keys()))) - speed = np.zeros((num_steps, len(data.keys()))) + pos = np.zeros((all_time.shape[0], len(data.keys()))) + speed = np.zeros((all_time.shape[0], len(data.keys()))) for i, veh_id in enumerate(sorted(data.keys())): for spd, abs_pos, ti in zip(data[veh_id]['vel'], data[veh_id]['abs_pos'], data[veh_id]['time']): - if int(ti/dt)-1 >= num_steps: - continue - pos[int(ti/dt)-1, i] = abs_pos - speed[int(ti/dt)-1, i] = spd + ind = np.where(ti == all_time)[0] + pos[ind, i] = abs_pos + speed[ind, i] = spd return pos, speed -def _figure_eight(data, params, dt, num_steps): +def _figure_eight(data, params, all_time): """Generate position and speed data for the figure eight. The vehicles traveling towards the intersection from one side will be @@ -294,10 +294,9 @@ def _figure_eight(data, params, dt, num_steps): * "vel": speed at every sample params : dict flow-specific parameters - dt : float - simulation step size - num_steps : int - number of simulation steps + all_time : array_like + a (n_steps,) vector representing the unique time steps in the + simulation Returns ------- @@ -343,16 +342,15 @@ def _figure_eight(data, params, dt, num_steps): data[veh_id]['pos'], edgestarts) # create the output variables - pos = np.zeros((num_steps, len(data.keys()))) - speed = np.zeros((num_steps, len(data.keys()))) + pos = np.zeros((all_time.shape[0], len(data.keys()))) + speed = np.zeros((all_time.shape[0], len(data.keys()))) for i, veh_id in enumerate(sorted(data.keys())): for spd, abs_pos, ti in zip(data[veh_id]['vel'], data[veh_id]['abs_pos'], data[veh_id]['time']): - if int(ti/dt)-1 >= num_steps: - continue - pos[int(ti/dt)-1, i] = abs_pos - speed[int(ti/dt)-1, i] = spd + ind = np.where(ti == all_time)[0] + pos[ind, i] = abs_pos + speed[ind, i] = spd # reorganize data for space-time plot figure8_len = 6*ring_edgelen + 2*intersection + 2*junction + 10*inner @@ -427,13 +425,7 @@ def _get_abs_pos(edge, rel_pos, edgestarts): emission_data = import_data_from_emission(args.emission_path) # compute the position and speed for all vehicles at all times - pos, speed = get_time_space_data(emission_data, flow_params) - - # simulation step size - sim_step = flow_params['sim'].sim_step - - # total time period - total_time = pos.shape[0] * sim_step + pos, speed, time = get_time_space_data(emission_data, flow_params) # some plotting parameters cdict = { @@ -449,8 +441,8 @@ def _get_abs_pos(edge, rel_pos, edgestarts): norm = plt.Normalize(0, args.max_speed) cols = [] - xmin = max(sim_step, args.start) - xmax = min(total_time, args.stop) + xmin = max(time[0], args.start) + xmax = min(time[-1], args.stop) xbuffer = (xmax - xmin) * 0.025 # 2.5% of range ymin, ymax = np.amin(pos), np.amax(pos) ybuffer = (ymax - ymin) * 0.025 # 2.5% of range @@ -458,8 +450,6 @@ def _get_abs_pos(edge, rel_pos, edgestarts): ax.set_xlim(xmin - xbuffer, xmax + xbuffer) ax.set_ylim(ymin - ybuffer, ymax + ybuffer) - time = np.arange(xmin, xmax, sim_step) - for indx_car in range(pos.shape[1]): unique_car_pos = pos[:, indx_car] diff --git a/tests/fast_tests/test_visualizers.py b/tests/fast_tests/test_visualizers.py index efcd7b2b2..017c3cec5 100644 --- a/tests/fast_tests/test_visualizers.py +++ b/tests/fast_tests/test_visualizers.py @@ -179,7 +179,8 @@ def test_time_space_diagram_figure_eight(self): # test get_time_space_data for figure eight networks flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/fig8.json')) - pos, speed = tsd.get_time_space_data(actual_emission_data, flow_params) + pos, speed, _ = tsd.get_time_space_data( + actual_emission_data, flow_params) expected_pos = np.array( [[60, 23.8, 182.84166941, 154.07166941, 125.30166941, 96.54166941, @@ -200,8 +201,8 @@ def test_time_space_diagram_figure_eight(self): 1.97, 1.76, 1.97] ]) - np.testing.assert_array_almost_equal(pos, expected_pos) - np.testing.assert_array_almost_equal(speed, expected_speed) + np.testing.assert_array_almost_equal(pos[:-1, :], expected_pos) + np.testing.assert_array_almost_equal(speed[:-1, :], expected_speed) def test_time_space_diagram_merge(self): dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -210,21 +211,23 @@ def test_time_space_diagram_merge(self): flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/merge.json')) - pos, speed = tsd.get_time_space_data(emission_data, flow_params) + pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) expected_pos = np.array( [[4.86, 180.32, 361.32, 547.77, 0], + [4.88, 180.36, 361.36, 547.8, 0], [4.95, 180.43, 361.44, 547.87, 0], - [0, 0, 0, 0, 0], [5.06, 180.54, 361.56, 547.98, 0], - [5.4, 180.86, 361.72, 548.12, 0]] + [5.21, 180.68, 361.72, 548.12, 0], + [5.4, 180.86, 0, 0, 0]] ) expected_speed = np.array( [[0, 0, 0, 0, 0], - [0.35, 0.37, 0.39, 0.34, 0.], - [0, 0, 0, 0, 0], + [0.15, 0.17, 0.19, 0.14, 0], + [0.35, 0.37, 0.39, 0.34, 0], [0.54, 0.57, 0.59, 0.54, 0], - [0.94, 0.9, 0.79, 0.71, 0]] + [0.74, 0.7, 0.79, 0.71, 0], + [0.94, 0.9, 0, 0, 0]] ) np.testing.assert_array_almost_equal(pos, expected_pos) @@ -237,44 +240,52 @@ def test_time_space_diagram_ring_road(self): flow_params = tsd.get_flow_params( os.path.join(dir_path, 'test_files/loop_230.json')) - pos, speed = tsd.get_time_space_data(emission_data, flow_params) + pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) - expected_pos = np.array([ - [0.0000e+00, 9.5500e+00, 9.5450e+01, 1.0500e+02, 1.1455e+02, - 1.2409e+02, 1.3364e+02, 1.4318e+02, 1.5273e+02, 1.6227e+02, - 1.7182e+02, 1.8136e+02, 1.9090e+01, 1.9091e+02, 2.0045e+02, - 2.8640e+01, 3.8180e+01, 4.7730e+01, 5.7270e+01, 6.6820e+01, - 7.6360e+01, 8.5910e+01], - [2.0000e-02, 9.5700e+00, 9.5480e+01, 1.0502e+02, 1.1457e+02, - 1.2411e+02, 1.3366e+02, 1.4321e+02, 1.5275e+02, 1.6230e+02, - 1.7184e+02, 1.8139e+02, 1.9110e+01, 1.9093e+02, 2.0048e+02, - 2.8660e+01, 3.8210e+01, 4.7750e+01, 5.7300e+01, 6.6840e+01, - 7.6390e+01, 8.5930e+01], - [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, - 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, - 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, - 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, - 0.0000e+00, 0.0000e+00], - [5.0000e-02, 9.5900e+00, 9.5500e+01, 1.0505e+02, 1.1459e+02, - 1.2414e+02, 1.3368e+02, 1.4323e+02, 1.5277e+02, 1.6232e+02, - 1.7187e+02, 1.8141e+02, 1.9140e+01, 1.9096e+02, 2.0051e+02, - 2.8680e+01, 3.8230e+01, 4.7770e+01, 5.7320e+01, 6.6870e+01, - 7.6410e+01, 8.5960e+01], - [1.2000e-01, 9.6600e+00, 9.5570e+01, 1.0512e+02, 1.1466e+02, - 1.2421e+02, 1.3371e+02, 1.4326e+02, 1.5281e+02, 1.6235e+02, - 1.7190e+02, 1.8144e+02, 1.9170e+01, 1.9099e+02, 2.0055e+02, - 2.8710e+01, 3.8260e+01, 4.7810e+01, 5.7350e+01, 6.6900e+01, - 7.6440e+01, 8.5990e+01] - ]) + expected_pos = np.array( + [[0.0000e+00, 9.5500e+00, 9.5450e+01, 1.0500e+02, 1.1455e+02, + 1.2409e+02, 1.3364e+02, 1.4318e+02, 1.5273e+02, 1.6227e+02, + 1.7182e+02, 1.8136e+02, 1.9090e+01, 1.9091e+02, 2.0045e+02, + 2.8640e+01, 3.8180e+01, 4.7730e+01, 5.7270e+01, 6.6820e+01, + 7.6360e+01, 8.5910e+01], + [1.0000e-02, 9.5500e+00, 9.5460e+01, 1.0501e+02, 1.1455e+02, + 1.2410e+02, 1.3364e+02, 1.4319e+02, 1.5274e+02, 1.6228e+02, + 1.7183e+02, 1.8137e+02, 1.9100e+01, 1.9092e+02, 2.0046e+02, + 2.8640e+01, 3.8190e+01, 4.7740e+01, 5.7280e+01, 6.6830e+01, + 7.6370e+01, 8.5920e+01], + [2.0000e-02, 9.5700e+00, 9.5480e+01, 1.0502e+02, 1.1457e+02, + 1.2411e+02, 1.3366e+02, 1.4321e+02, 1.5275e+02, 1.6230e+02, + 1.7184e+02, 1.8139e+02, 1.9110e+01, 1.9093e+02, 2.0048e+02, + 2.8660e+01, 3.8210e+01, 4.7750e+01, 5.7300e+01, 6.6840e+01, + 7.6390e+01, 8.5930e+01], + [5.0000e-02, 9.5900e+00, 9.5500e+01, 1.0505e+02, 1.1459e+02, + 1.2414e+02, 1.3368e+02, 1.4323e+02, 1.5277e+02, 1.6232e+02, + 1.7187e+02, 1.8141e+02, 1.9140e+01, 1.9096e+02, 2.0051e+02, + 2.8680e+01, 3.8230e+01, 4.7770e+01, 5.7320e+01, 6.6870e+01, + 7.6410e+01, 8.5960e+01], + [8.0000e-02, 9.6200e+00, 9.5530e+01, 1.0508e+02, 1.1462e+02, + 1.2417e+02, 1.3371e+02, 1.4326e+02, 1.5281e+02, 1.6235e+02, + 1.7190e+02, 1.8144e+02, 1.9170e+01, 1.9099e+02, 2.0055e+02, + 2.8710e+01, 3.8260e+01, 4.7810e+01, 5.7350e+01, 6.6900e+01, + 7.6440e+01, 8.5990e+01], + [1.2000e-01, 9.6600e+00, 9.5570e+01, 1.0512e+02, 1.1466e+02, + 1.2421e+02, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, + 0.0000e+00, 0.0000e+00]] + ) expected_speed = np.array([ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, + 0.08, 0.08, 0.08, 0.1, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08], [0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.2, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.29, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23, 0.23], - [0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0.31, 0.31, 0.31, 0.31, 0.31, - 0.31, 0.31, 0.31, 0.39, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31] + [0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, + 0.31, 0.31, 0.31, 0.39, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31, 0.31], + [0.41, 0.41, 0.41, 0.41, 0.41, 0.41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0] ]) np.testing.assert_array_almost_equal(pos, expected_pos) From bb00df455d394ec9c95af16e825a613d0f3b0e64 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 10 Jun 2019 18:11:24 +0300 Subject: [PATCH 8/9] updated merge scenario so that it's behavior will still work with new sumo --- flow/scenarios/merge.py | 11 ++++++----- flow/visualize/time_space_diagram.py | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/flow/scenarios/merge.py b/flow/scenarios/merge.py index 2ccc9590d..f34124ac3 100644 --- a/flow/scenarios/merge.py +++ b/flow/scenarios/merge.py @@ -99,7 +99,8 @@ def specify_nodes(self, net_params): { "id": "center", "y": 0, - "x": premerge + "x": premerge, + "radius": 10 }, { "id": "right", @@ -196,11 +197,11 @@ def specify_edge_starts(self): postmerge = self.net_params.additional_params["post_merge_length"] edgestarts = [("inflow_highway", 0), ("left", INFLOW_EDGE_LEN + 0.1), - ("center", INFLOW_EDGE_LEN + premerge + 8.1), + ("center", INFLOW_EDGE_LEN + premerge + 22.6), ("inflow_merge", - INFLOW_EDGE_LEN + premerge + postmerge + 8.1), + INFLOW_EDGE_LEN + premerge + postmerge + 22.6), ("bottom", - 2 * INFLOW_EDGE_LEN + premerge + postmerge + 8.2)] + 2 * INFLOW_EDGE_LEN + premerge + postmerge + 22.7)] return edgestarts @@ -212,7 +213,7 @@ def specify_internal_edge_starts(self): internal_edgestarts = [ (":left", INFLOW_EDGE_LEN), (":center", INFLOW_EDGE_LEN + premerge + 0.1), - (":bottom", 2 * INFLOW_EDGE_LEN + premerge + postmerge + 8.1) + (":bottom", 2 * INFLOW_EDGE_LEN + premerge + postmerge + 22.6) ] return internal_edgestarts diff --git a/flow/visualize/time_space_diagram.py b/flow/visualize/time_space_diagram.py index 905a6a4a5..c1c8a20aa 100644 --- a/flow/visualize/time_space_diagram.py +++ b/flow/visualize/time_space_diagram.py @@ -181,13 +181,13 @@ def _merge(data, params, all_time): edgestarts = { 'inflow_highway': 0, 'left': inflow_edge_len + 0.1, - 'center': inflow_edge_len + premerge + 8.1, - 'inflow_merge': inflow_edge_len + premerge + postmerge + 8.1, - 'bottom': 2 * inflow_edge_len + premerge + postmerge + 8.2, + 'center': inflow_edge_len + premerge + 22.6, + 'inflow_merge': inflow_edge_len + premerge + postmerge + 22.6, + 'bottom': 2 * inflow_edge_len + premerge + postmerge + 22.7, ':left_0': inflow_edge_len, ':center_0': inflow_edge_len + premerge + 0.1, ':center_1': inflow_edge_len + premerge + 0.1, - ':bottom_0': 2 * inflow_edge_len + premerge + postmerge + 8.1 + ':bottom_0': 2 * inflow_edge_len + premerge + postmerge + 22.6 } # compute the absolute position From 748a67ba895887246f56a616882c1fba5cbf3a80 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Tue, 11 Jun 2019 09:42:35 +0300 Subject: [PATCH 9/9] updated version number --- flow/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow/version.py b/flow/version.py index 404712661..49b5c3528 100644 --- a/flow/version.py +++ b/flow/version.py @@ -1,3 +1,3 @@ """Specifies the current version number of Flow.""" -__version__ = "0.3.0" +__version__ = "0.3.1"