Skip to content

Commit

Permalink
Fixed Aimsun Bugs (#750)
Browse files Browse the repository at this point in the history
* Fix bugs in utils/aimsun/load.py

1. Updated the path to data.json
2. Added a check before querying centroid_config.origin_centroids and centroid_config.destination_centroids to prevent erroring out when the model doesn't have origin or destination centroids set.

* Fixed bug

* bug fixed

* deleted the json files

* PR fixes
  • Loading branch information
Yasharzf authored and AboudyKreidieh committed Oct 8, 2019
1 parent 67d1a52 commit 5eaa30e
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 22 deletions.
10 changes: 5 additions & 5 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A few points of clarification:

* Occasionally we describe environments as *fully observed*. By this we mean that all relevant pieces of information (speed, relative positions, traffic light states) of the system are available to the controller. *Partially observed* refers to only a subset being available. This is the default configuration of the environment and the set of observations can be customized.

* Each environment has customizable environment/network parameters that can be used to configure it beyond what is described here. Particularly pertinent parameters are described. Additional parameters can be found by examining the documentation in the relevant scenario and environment files.
* Each environment has customizable environment/network parameters that can be used to configure it beyond what is described here. Particularly pertinent parameters are described. Additional parameters can be found by examining the documentation in the relevant network and environment files.

* In the figures below, the following key is used for vehicle colors, where AV stands for autonomous vehicle.

Expand All @@ -22,12 +22,12 @@ Figure Eight
The figure-eight is a closed-ring version of an intersection. The goal is to maximize
the system-wide velocity for fourteen vehicles,
which necessitates spacing the vehicles so that they don't
run into conflicts at the merging points. The scenario is fully observed: all vehicles
run into conflicts at the merging points. The network is fully observed: all vehicles
speeds and positions are visible to the controller.
This scenario is also a benchmark, and has been
This network is also a benchmark, and has been
extensively tested at three penetration rates: 1 AV 13 humans, 7 AVs 7 humans, 14 AVs.

The scenario, pictured below,
The network, pictured below,
is relatively light-weight and can be trained the quickest. It can serve both as a test
that the training process is working correctly and as a study of the difficulty of controlling
many vehicles simultaneously.
Expand All @@ -51,7 +51,7 @@ and the speed of the leading vehicle.

To make this task more difficult, the environment has a configurable parameter, `ring_length`, which
can be set to a list containing the minimum and maximum ring-size. The autonomous vehicle must
learn to distinguish these scenarios from each other and pick the appropriate driving behavior.
learn to distinguish these networks from each other and pick the appropriate driving behavior.

.. image:: ../img/stabilizing_the_ring.png
:width: 400
Expand Down
2 changes: 1 addition & 1 deletion docs/source/flow_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ The latter command should return an output similar to:

/path/to/envs/aimsun_flow/bin/python

Copy the path up until right before /bin (i.e. /path/to/envs/aimsun_flow) and
Copy the path up until right before /lib (i.e. /path/to/envs/aimsun_flow/bin/python) and
place it under the `AIMSUN_SITEPACKAGES` variable in your bashrc, like this:

::
Expand Down
7 changes: 6 additions & 1 deletion flow/core/kernel/network/aimsun.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def generate_network(self, network):
'render': self.sim_params.render,
"sim_step": self.sim_params.sim_step,
"traffic_lights": None,
"scenario_name": self.sim_params.scenario_name,
"network_name": self.sim_params.network_name,
"experiment_name": self.sim_params.experiment_name,
"replication_name": self.sim_params.replication_name,
"centroid_config_name": self.sim_params.centroid_config_name,
Expand Down Expand Up @@ -276,6 +276,11 @@ def length(self):
return sum(self.edge_length(edge_id)
for edge_id in self.get_edge_list())

def non_internal_length(self):
"""See parent class."""
return sum(self.edge_length(edge_id)
for edge_id in self.get_edge_list())

def speed_limit(self, edge_id):
"""See parent class."""
try:
Expand Down
Empty file.
8 changes: 4 additions & 4 deletions flow/core/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,15 @@ class AimsunParams(SimParams):
specifies whether to render the radius of RL observation
pxpm : int, optional
specifies rendering resolution (pixel / meter)
scenario_name : str, optional
network_name : str, optional
name of the network generated in Aimsun.
experiment_name : str, optional
name of the experiment generated in Aimsun
replication_name : str, optional
name of the replication generated in Aimsun. When loading
an Aimsun template, this parameter must be set to the name
of the replication to be run by the simulation; in this case,
the scenario_name and experiment_name parameters are not
the network_name and experiment_name parameters are not
necessary as they will be obtained from the replication name.
centroid_config_name : str, optional
name of the centroid configuration to load in Aimsun. This
Expand All @@ -477,7 +477,7 @@ def __init__(self,
show_radius=False,
pxpm=2,
# set to match Flow_Aimsun.ang's scenario name
scenario_name="Dynamic Scenario 866",
network_name="Dynamic Scenario 866",
# set to match Flow_Aimsun.ang's experiment name
experiment_name="Micro SRC Experiment 867",
# set to match Flow_Aimsun.ang's replication name
Expand All @@ -488,7 +488,7 @@ def __init__(self,
super(AimsunParams, self).__init__(
sim_step, render, restart_instance, emission_path, save_render,
sight_radius, show_radius, pxpm)
self.scenario_name = scenario_name
self.network_name = network_name
self.experiment_name = experiment_name
self.replication_name = replication_name
self.centroid_config_name = centroid_config_name
Expand Down
2 changes: 1 addition & 1 deletion flow/core/rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def penalize_near_standstill(env, thresh=0.3, gain=1):
This reward function is used to penalize vehicles below a
specified threshold. This assists with discouraging RL from
gamifying a scenario, which can result in standstill behavior
gamifying a network, which can result in standstill behavior
or similarly bad, near-zero velocities.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion flow/networks/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Contains the base scenario class."""
"""Contains the base network class."""

from flow.core.params import InitialConfig
from flow.core.params import TrafficLightParams
Expand Down
2 changes: 1 addition & 1 deletion flow/scenarios/multi_loop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Pending deprecation file.
To view the actual content, go to: flow/scenarios/multi_ring.py
To view the actual content, go to: flow/networks/multi_ring.py
"""
from flow.utils.flow_warnings import deprecated
from flow.networks.multi_ring import MultiRingNetwork
Expand Down
8 changes: 4 additions & 4 deletions flow/utils/aimsun/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def generate_net(nodes,
set_vehicles_color(model)

# set API
scenario_name = data["scenario_name"]
network_name = data["network_name"]
scenario = model.getCatalog().findByName(
scenario_name, model.getType("GKScenario")) # find scenario
network_name, model.getType("GKScenario")) # find scenario
scenario_data = scenario.getInputData()
scenario_data.addExtension(os.path.join(
config.PROJECT_PATH, "flow/utils/aimsun/run.py"), True)
Expand Down Expand Up @@ -366,9 +366,9 @@ def generate_net_osm(file_name, inflows, veh_types):
set_vehicles_color(model)

# set API
scenario_name = data["scenario_name"]
network_name = data["network_name"]
scenario = model.getCatalog().findByName(
scenario_name, model.getType("GKScenario")) # find scenario
network_name, model.getType("GKScenario")) # find scenario
scenario_data = scenario.getInputData()
scenario_data.addExtension(os.path.join(
config.PROJECT_PATH, "flow/utils/aimsun/run.py"), True)
Expand Down
4 changes: 2 additions & 2 deletions flow/utils/aimsun/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_dict_from_objects(sections, nodes, turnings, cen_connections):
scenario_data = load_network()

# save template's scenario into a file to be loaded into Flow's scenario
scenario_data_file = 'flow/core/kernel/network/scenario_data.json'
scenario_data_file = 'flow/core/kernel/network/network_data.json'
scenario_data_path = os.path.join(config.PROJECT_PATH, scenario_data_file)
with open(scenario_data_path, 'w') as f:
json.dump(scenario_data, f, sort_keys=True, indent=4)
Expand All @@ -183,7 +183,7 @@ def get_dict_from_objects(sections, nodes, turnings, cen_connections):

# create a check file to announce that we are done
# writing all the network data into the .json file
check_file = 'flow/core/kernel/network/scenario_data_check'
check_file = 'flow/core/kernel/network/network_data_check'
check_file_path = os.path.join(config.PROJECT_PATH, check_file)
open(check_file_path, 'a').close()

Expand Down
Binary file modified flow/utils/aimsun/small_template.ang
Binary file not shown.
File renamed without changes
2 changes: 1 addition & 1 deletion tutorials/tutorial05_networks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"In this exercise, we will recreate the ring road network, seen in the figure below.\n",
"\n",
"<img src=\"img/ring_scenario.png\">\n",
"<img src=\"img/ring_network.png\">\n",
"\n",
"In order to recreate this network, we will design a *network* class. This class creates the configuration files needed to produce a transportation network within the simulator. It also specifies the location of edge nodes in the network, as well as the positioning of vehicles at the start of a run.\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion tutorials/tutorial10_traffic_lights.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"\n",
"* Experiment script for RL version of traffic lights in grid: `examples/rllib/traffic_light_grid.py`\n",
"* Experiment script for non-RL version of traffic lights in grid: `examples/sumo/traffic_light_grid.py`\n",
"* Network: `traffic_light_grid.py` (class TrafficLightGridScenario)\n",
"* Network: `traffic_light_grid.py` (class TrafficLightGridNetwork)\n",
"* Environment for RL version of traffic lights in grid: (class TrafficLightGridEnv)\n",
"* Environment for non-RL version of traffic lights in grid: (class AccelEnv)\n",
"\n",
Expand Down

0 comments on commit 5eaa30e

Please sign in to comment.