Skip to content

Commit

Permalink
Merge pull request #620 from flow-project/aimsun-load
Browse files Browse the repository at this point in the history
Aimsun load template
  • Loading branch information
nathanlct committed Jul 21, 2019
2 parents 1f68535 + 4623221 commit f7c9797
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ debug/
.vs/**

# Custom for Aimsun
flow.ang
*.ang.lck
*flow.sqlite
*.sqlite
*.ang.old
*.sang

36 changes: 36 additions & 0 deletions examples/aimsun/small_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Load an already existing Aimsun template and run the simulation."""

from flow.core.experiment import Experiment
from flow.core.params import AimsunParams, EnvParams, NetParams
from flow.core.params import VehicleParams
from flow.envs import TestEnv
from flow.scenarios.loop import Scenario
from flow.core.params import InFlows
import flow.config as config
import os

sim_params = AimsunParams(
sim_step=0.1,
render=True,
emission_path='data',
replication_name="Replication 930",
centroid_config_name="Centroid Configuration 910")

env_params = EnvParams()
vehicles = VehicleParams()

template_path = os.path.join(config.PROJECT_PATH,
"flow/utils/aimsun/small_template.ang")

scenario = Scenario(
name="aimsun_small_template",
vehicles=vehicles,
net_params=NetParams(
inflows=InFlows(),
template=template_path
)
)

env = TestEnv(env_params, sim_params, scenario, simulator='aimsun')
exp = Experiment(env)
exp.run(1, 3000)
74 changes: 39 additions & 35 deletions flow/core/kernel/vehicle/aimsun.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,46 +319,50 @@ def _add_departed(self, aimsun_id):
# store an empty tracking info object
self.__vehicles[veh_id]['tracking_info'] = InfVeh()

# TODO Nathan
# specify the acceleration controller class
accel_controller = \
self.type_parameters[type_id]["acceleration_controller"]
car_following_params = \
self.type_parameters[type_id]["car_following_params"]
self.__vehicles[veh_id]["acc_controller"] = \
accel_controller[0](veh_id,
car_following_params=car_following_params,
**accel_controller[1])

# specify the lane-changing controller class
lc_controller = \
self.type_parameters[type_id]["lane_change_controller"]
self.__vehicles[veh_id]["lane_changer"] = \
lc_controller[0](veh_id=veh_id, **lc_controller[1])

# specify the routing controller class
rt_controller = self.type_parameters[type_id]["routing_controller"]
if rt_controller is not None:
self.__vehicles[veh_id]["router"] = \
rt_controller[0](veh_id=veh_id, router_params=rt_controller[1])
else:
self.__vehicles[veh_id]["router"] = None
if type_id in self.type_parameters:
# specify the acceleration controller class
accel_controller = \
self.type_parameters[type_id]["acceleration_controller"]
car_following_params = \
self.type_parameters[type_id]["car_following_params"]
self.__vehicles[veh_id]["acc_controller"] = \
accel_controller[0](veh_id,
car_following_params=car_following_params,
**accel_controller[1])

# specify the lane-changing controller class
lc_controller = \
self.type_parameters[type_id]["lane_change_controller"]
self.__vehicles[veh_id]["lane_changer"] = \
lc_controller[0](veh_id=veh_id, **lc_controller[1])

# specify the routing controller class
rt_controller = self.type_parameters[type_id]["routing_controller"]
if rt_controller is not None:
self.__vehicles[veh_id]["router"] = \
rt_controller[0](veh_id=veh_id,
router_params=rt_controller[1])
else:
self.__vehicles[veh_id]["router"] = None

# add the vehicle's id to the list of vehicle ids
if accel_controller[0] == RLController:
self.__rl_ids.append(veh_id)
self.num_rl_vehicles += 1
else:
self.__human_ids.append(veh_id)
if accel_controller[0] != SimCarFollowingController:
self.__controlled_ids.append(veh_id)
if lc_controller[0] != SimLaneChangeController:
self.__controlled_lc_ids.append(veh_id)
# FIXME should add RL controller to RL vehicle added by Aimsun via
# load.py

# add the vehicle's id to the list of vehicle ids
if accel_controller[0] == RLController:
self.__rl_ids.append(veh_id)
self.num_rl_vehicles += 1
else:
self.__human_ids.append(veh_id)
if accel_controller[0] != SimCarFollowingController:
self.__controlled_ids.append(veh_id)
if lc_controller[0] != SimLaneChangeController:
self.__controlled_lc_ids.append(veh_id)

# set the "last_lc" parameter of the vehicle
self.__vehicles[veh_id]["last_lc"] = -float("inf")

self.__human_ids.append(veh_id) # FIXME
self.__human_ids.append(veh_id) # FIXME not true for RL vehicles

# make sure that the order of rl_ids is kept sorted
self.__rl_ids.sort()
Expand Down
Binary file added flow/utils/aimsun/small_template.ang
Binary file not shown.

0 comments on commit f7c9797

Please sign in to comment.