Skip to content

Commit

Permalink
changed _departed_ids, and _arrived_ids in the update function (#926)
Browse files Browse the repository at this point in the history
* changed _departed_ids, and _arrived_ids in the update function

* fixed bug in get_departed_ids and get_arrived_ids
  • Loading branch information
Yasharzf committed May 9, 2020
1 parent 50be2d0 commit 7398f50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
3 changes: 2 additions & 1 deletion flow/core/kernel/simulation/traci.py
Expand Up @@ -52,7 +52,8 @@ def pass_api(self, kernel_api):
tc.VAR_TIME_STEP,
tc.VAR_DELTA_T,
tc.VAR_LOADED_VEHICLES_NUMBER,
tc.VAR_DEPARTED_VEHICLES_NUMBER
tc.VAR_DEPARTED_VEHICLES_NUMBER,
tc.VAR_ARRIVED_VEHICLES_NUMBER
])

def simulation_step(self):
Expand Down
27 changes: 10 additions & 17 deletions flow/core/kernel/vehicle/traci.py
Expand Up @@ -71,11 +71,11 @@ def __init__(self,

# number of vehicles that entered the network for every time-step
self._num_departed = []
self._departed_ids = []
self._departed_ids = 0

# number of vehicles to exit the network for every time-step
self._num_arrived = []
self._arrived_ids = []
self._arrived_ids = 0
self._arrived_rl_ids = []

# whether or not to automatically color vehicles
Expand Down Expand Up @@ -184,8 +184,8 @@ def update(self, reset):
self.prev_last_lc[veh_id] = -float("inf")
self._num_departed.clear()
self._num_arrived.clear()
self._departed_ids.clear()
self._arrived_ids.clear()
self._departed_ids = 0
self._arrived_ids = 0
self._arrived_rl_ids.clear()
self.num_not_departed = 0

Expand All @@ -211,11 +211,10 @@ def update(self, reset):
self.__vehicles[veh_id]["last_lc"] = self.time_counter

# updated the list of departed and arrived vehicles
self._num_departed.append(
len(sim_obs[tc.VAR_DEPARTED_VEHICLES_IDS]))
self._num_arrived.append(len(sim_obs[tc.VAR_ARRIVED_VEHICLES_IDS]))
self._departed_ids.append(sim_obs[tc.VAR_DEPARTED_VEHICLES_IDS])
self._arrived_ids.append(sim_obs[tc.VAR_ARRIVED_VEHICLES_IDS])
self._num_departed.append(sim_obs[tc.VAR_LOADED_VEHICLES_NUMBER])
self._num_arrived.append(sim_obs[tc.VAR_ARRIVED_VEHICLES_NUMBER])
self._departed_ids = sim_obs[tc.VAR_DEPARTED_VEHICLES_IDS]
self._arrived_ids = sim_obs[tc.VAR_ARRIVED_VEHICLES_IDS]

# update the number of not departed vehicles
self.num_not_departed += sim_obs[tc.VAR_LOADED_VEHICLES_NUMBER] - \
Expand Down Expand Up @@ -517,10 +516,7 @@ def get_num_arrived(self):

def get_arrived_ids(self):
"""See parent class."""
if len(self._arrived_ids) > 0:
return self._arrived_ids[-1]
else:
return 0
return self._arrived_ids

def get_arrived_rl_ids(self):
"""See parent class."""
Expand All @@ -531,10 +527,7 @@ def get_arrived_rl_ids(self):

def get_departed_ids(self):
"""See parent class."""
if len(self._departed_ids) > 0:
return self._departed_ids[-1]
else:
return 0
return self._departed_ids

def get_num_not_departed(self):
"""See parent class."""
Expand Down

0 comments on commit 7398f50

Please sign in to comment.