Skip to content

Commit

Permalink
Fixes issue #117: Add a check for empty agents list
Browse files Browse the repository at this point in the history
  • Loading branch information
mzrghorbani committed Dec 31, 2024
1 parent 84e37de commit 3bc2d01
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions flee/Diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ def write_agents_par(
my_file = None
if time == 0:
my_file = open("agents.out.%s" % rank, "w", encoding="utf-8")
print(
"#time,rank-agentid,original_location,current_location,gps_x,gps_y,is_travelling,distance_travelled,"
"places_travelled,distance_moved_this_timestep,{}".format(print_attribute_keys(agents[0])),
file=my_file,
)

if agents:
print(
"#time,rank-agentid,original_location,current_location,gps_x,gps_y,is_travelling,distance_travelled,"
"places_travelled,distance_moved_this_timestep,{}".format(print_attribute_keys(agents[0])),
file=my_file,
)
else: # Handle the case where agents list is empty
print(
"#time,rank-agentid,original_location,current_location,gps_x,gps_y,is_travelling,distance_travelled,"
"places_travelled,distance_moved_this_timestep",
file=my_file,
)
else:
my_file = open("agents.out.%s" % rank, "a", encoding="utf-8")

Expand Down

0 comments on commit 3bc2d01

Please sign in to comment.