Skip to content

Commit

Permalink
Merge pull request #137 from flow-project/inflows_reset_warning
Browse files Browse the repository at this point in the history
added warning about inflows
  • Loading branch information
AboudyKreidieh committed Sep 8, 2018
2 parents 09ee2d6 + 468bbd0 commit 32fd868
Show file tree
Hide file tree
Showing 35 changed files with 67 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/rllab/green_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_flow_params(v_enter, vehs_per_hour, col_num, row_num,
departSpeed=v_enter)

net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion examples/rllab/stabilizing_highway.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run_task(_):
additional_net_params["highway_lanes"] = 1
additional_net_params["pre_merge_length"] = 500
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion examples/rllab/velocity_bottleneck.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

additional_net_params = {"scaling": SCALING}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion examples/rllib/green_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_flow_params(col_num, row_num, additional_net_params):
departSpeed=20)

net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion examples/rllib/stabilizing_highway.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
4 changes: 2 additions & 2 deletions examples/rllib/velocity_bottleneck.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

additional_net_params = {"scaling": SCALING}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down Expand Up @@ -128,7 +128,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
2 changes: 1 addition & 1 deletion examples/sumo/bay_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def bay_bridge_example(sumo_binary=None,
departLane="0",
departSpeed=20) # no data for this

net_params = NetParams(in_flows=inflow, no_internal_links=False)
net_params = NetParams(inflows=inflow, no_internal_links=False)
net_params.netfile = NETFILE

# download the netfile from AWS
Expand Down
2 changes: 1 addition & 1 deletion examples/sumo/bay_bridge_toll.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def bay_bridge_bottleneck_example(sumo_binary=None, use_traffic_lights=False):
departSpeed=10)

net_params = NetParams(
in_flows=inflow, no_internal_links=False, netfile=NETFILE)
inflows=inflow, no_internal_links=False, netfile=NETFILE)

# download the netfile from AWS
if use_traffic_lights:
Expand Down
2 changes: 1 addition & 1 deletion examples/sumo/bottleneck.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def bottleneck_example(flow_rate, horizon, sumo_binary=None):

additional_net_params = {"scaling": SCALING}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion examples/sumo/highway.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def highway_example(sumo_binary=None):

additional_net_params = ADDITIONAL_NET_PARAMS.copy()
net_params = NetParams(
in_flows=inflow, additional_params=additional_net_params)
inflows=inflow, additional_params=additional_net_params)

initial_config = InitialConfig(spacing="uniform", shuffle=True)

Expand Down
2 changes: 1 addition & 1 deletion examples/sumo/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def merge_example(sumo_binary=None):
additional_net_params["highway_lanes"] = 1
additional_net_params["pre_merge_length"] = 500
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/baselines/bottleneck0.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class needed to run simulations
traffic_lights.add(node_id="3")

additional_net_params = {"scaling": SCALING}
net_params = NetParams(in_flows=inflow,
net_params = NetParams(inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/baselines/bottleneck1.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class needed to run simulations
traffic_lights.add(node_id="3")

additional_net_params = {"scaling": SCALING}
net_params = NetParams(in_flows=inflow,
net_params = NetParams(inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/baselines/bottleneck2.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class needed to run simulations
traffic_lights.add(node_id="3")

additional_net_params = {"scaling": SCALING}
net_params = NetParams(in_flows=inflow,
net_params = NetParams(inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/baselines/grid0.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class needed to run simulations
programID=1)

net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params={
"speed_limit": V_ENTER + 5,
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/baselines/grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class needed to run simulations
programID=1)

net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params={
"speed_limit": V_ENTER + 5,
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/baselines/merge012.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class needed to run simulations
initial_config = InitialConfig()

net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
)
Expand Down
4 changes: 2 additions & 2 deletions flow/benchmarks/bottleneck0.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

additional_net_params = {"scaling": SCALING}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down Expand Up @@ -119,7 +119,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
4 changes: 2 additions & 2 deletions flow/benchmarks/bottleneck1.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

additional_net_params = {"scaling": SCALING}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down Expand Up @@ -120,7 +120,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
4 changes: 2 additions & 2 deletions flow/benchmarks/bottleneck2.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

additional_net_params = {"scaling": SCALING}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down Expand Up @@ -120,7 +120,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/grid0.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params={
"speed_limit": V_ENTER + 5,
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params={
"speed_limit": V_ENTER + 5,
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/merge0.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/merge1.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
2 changes: 1 addition & 1 deletion flow/benchmarks/merge2.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# network-related parameters (see flow.core.params.NetParams and the
# scenario's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params,
),
Expand Down
4 changes: 2 additions & 2 deletions flow/core/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ def make_routes(self, scenario, positions, lanes, shuffle):
departLane=str(lane)))

# add the in-flows from various edges to the xml file
if self.net_params.in_flows is not None:
total_inflows = self.net_params.in_flows.get()
if self.net_params.inflows is not None:
total_inflows = self.net_params.inflows.get()
for inflow in total_inflows:
for key in inflow:
if not isinstance(inflow[key], str):
Expand Down
9 changes: 6 additions & 3 deletions flow/core/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class NetParams:

def __init__(self,
no_internal_links=True,
in_flows=None,
inflows=None,
osm_path=None,
netfile=None,
additional_params=None):
Expand All @@ -176,7 +176,7 @@ def __init__(self,
no_internal_links : bool, optional
determines whether the space between edges is finite. Important
when using networks with intersections; default is False
in_flows : InFlows type, optional
inflows : InFlows type, optional
specifies the inflows of specific edges and the types of vehicles
entering the network from these edges
osm_path : str, optional
Expand All @@ -193,7 +193,10 @@ def __init__(self,
what is needed
"""
self.no_internal_links = no_internal_links
self.in_flows = in_flows
if inflows is None:
self.inflows = InFlows()
else:
self.inflows = inflows
self.osm_path = osm_path
self.netfile = netfile
self.additional_params = additional_params or {}
Expand Down
6 changes: 3 additions & 3 deletions flow/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def eval_net_params(flow_params):
better_params = flow_params.copy()
inflow = InFlows()
new_inflow_list = []
if 'in_flows' in flow_params['net']:
inflow_obj = flow_params['net']['in_flows']['_InFlows__flows']
if 'inflows' in flow_params['net']:
inflow_obj = flow_params['net']['inflows']['_InFlows__flows']
for obj in inflow_obj:
temp = {}
for key in obj.keys():
Expand All @@ -127,7 +127,7 @@ def eval_net_params(flow_params):
temp[key] = obj[key]
new_inflow_list.append(temp)
[inflow.add(**inflow_i) for inflow_i in new_inflow_list]
better_params['net']['in_flows'] = inflow
better_params['net']['inflows'] = inflow

return better_params['net']

Expand Down
15 changes: 15 additions & 0 deletions flow/envs/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,21 @@ def reset(self):
# reset the time counter
self.time_counter = 0

# warn about not using restart_instance when using inflows
if len(self.scenario.net_params.inflows.get()) > 0 and \
not self.sumo_params.restart_instance:
print(
"**********************************************************\n"
"**********************************************************\n"
"**********************************************************\n"
"WARNING: Inflows will cause computational performance to\n"
"significantly decrease after large number of rollouts. In \n"
"order to avoid this, set SumoParams(restart_instance=True).\n"
"**********************************************************\n"
"**********************************************************\n"
"**********************************************************"
)

if self.sumo_params.restart_instance or self.step_counter > 2e6:
self.step_counter = 0
# issue a random seed to induce randomness into the next rollout
Expand Down
2 changes: 1 addition & 1 deletion flow/envs/bottleneck_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ def reset(self):

additional_net_params = {"scaling": self.scaling}
net_params = NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params=additional_net_params)

Expand Down
6 changes: 3 additions & 3 deletions flow/utils/rllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def get_flow_params(config):

net = NetParams()
net.__dict__ = flow_params["net"].copy()
net.in_flows = InFlows()
if flow_params["net"]["in_flows"]:
net.in_flows.__dict__ = flow_params["net"]["in_flows"].copy()
net.inflows = InFlows()
if flow_params["net"]["inflows"]:
net.inflows.__dict__ = flow_params["net"]["inflows"].copy()

env = EnvParams()
env.__dict__ = flow_params["env"].copy()
Expand Down
2 changes: 1 addition & 1 deletion tests/fast_tests/test_collisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_collide_inflows(self):

net_params = NetParams(
no_internal_links=False,
in_flows=inflows,
inflows=inflows,
additional_params=additional_net_params)

self.env, self.scenario = grid_mxn_exp_setup(
Expand Down
10 changes: 5 additions & 5 deletions tests/fast_tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_encoder_and_get_flow_params(self):
},
),
net=NetParams(
in_flows=inflow,
inflows=inflow,
no_internal_links=False,
additional_params={
"merge_length": 100,
Expand Down Expand Up @@ -272,11 +272,11 @@ def test_encoder_and_get_flow_params(self):
os.remove(os.path.expanduser('params.json'))

# test that this inflows are correct
self.assertTrue(imported_flow_params["net"].in_flows.__dict__ ==
flow_params["net"].in_flows.__dict__)
self.assertTrue(imported_flow_params["net"].inflows.__dict__ ==
flow_params["net"].inflows.__dict__)

imported_flow_params["net"].in_flows = None
flow_params["net"].in_flows = None
imported_flow_params["net"].inflows = None
flow_params["net"].inflows = None

# make sure the rest of the imported flow_params match the originals
self.assertTrue(imported_flow_params["env"].__dict__ == flow_params[
Expand Down

0 comments on commit 32fd868

Please sign in to comment.