Skip to content

Commit

Permalink
Compute and display inflows and throughput efficiency (#632)
Browse files Browse the repository at this point in the history
Introduces an efficiency metric (between 0 and 1) which can be used to assess the optimality of our experiments. Efficiency of 1 means that the outflow (throughput) is as high as the inflow. We can't do much better than that. This is displayed when with the rllib visualizer.

* compute and display inflows and throughput efficiency

* fix: div/0 error

* efficiency computation bug
  • Loading branch information
cathywu committed Jul 16, 2019
1 parent a5072eb commit 84da0db
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions flow/visualize/visualizer_rllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def visualizer_rllib(args):

# Simulate and collect metrics
final_outflows = []
final_inflows = []
mean_speed = []
std_speed = []
for i in range(args.num_rollouts):
Expand Down Expand Up @@ -239,6 +240,13 @@ def visualizer_rllib(args):
rets.append(ret)
outflow = vehicles.get_outflow_rate(500)
final_outflows.append(outflow)
inflow = vehicles.get_inflow_rate(500)
final_inflows.append(inflow)
if np.all(np.array(final_inflows) > 1e-5):
throughput_efficiency = [x / y for x, y in
zip(final_outflows, final_inflows)]
else:
throughput_efficiency = [0] * len(final_inflows)
mean_speed.append(np.mean(vel))
std_speed.append(np.std(vel))
if multiagent:
Expand Down Expand Up @@ -276,6 +284,16 @@ def visualizer_rllib(args):
print(final_outflows)
print('Average, std: {}, {}'.format(np.mean(final_outflows),
np.std(final_outflows)))
# Compute departure rate of vehicles in the last 500 sec of the run
print("Inflows (veh/hr):")
print(final_inflows)
print('Average, std: {}, {}'.format(np.mean(final_inflows),
np.std(final_inflows)))
# Compute throughput efficiency in the last 500 sec of the
print("Throughput efficiency (veh/hr):")
print(throughput_efficiency)
print('Average, std: {}, {}'.format(np.mean(throughput_efficiency),
np.std(throughput_efficiency)))

# terminate the environment
env.unwrapped.terminate()
Expand Down

0 comments on commit 84da0db

Please sign in to comment.