Dynamically creating agents from csv

22 views
Skip to first unread message

Oscar Rojo Avila

unread,
Feb 17, 2025, 8:25:54 PMFeb 17
to GAMA
Dear Gamma Community,I have a question regarding creating agents from a csv file.  In particular, I have a csv with locations of charging stations, and I want to be able to dynamically add or remove stations depending on the number of bicycles in the system, which is a parameter in the simulation.Currently, I start the simulation with a stationary number of stations which is imported with the following function:‘’'
create chargingStation from: chargingStations_csv with: [
      lat:: float(get(“center_y”)),
      lon:: float(get(“center_x”))
]
‘’'
Is there a way to specify which rows from the csv to use? For example, if I start the simulation with 10 stations, I want to read the first 10 rows from the csv, if then I need to add 3 stations more,  I want the create function to read the 11-13th rows.If this isn’t possible, or if there is a better way of doing this, I´d really appreciate your feedback.

Benoit Gaudou

unread,
Feb 21, 2025, 3:52:27 AMFeb 21
to gama-p...@googlegroups.com
Dear,

To answer the first part of your question: "For example, if I start the simulation with 10 stations, I want to read the first 10 rows from the csv"
you can specify the number of agents you want to create. The following will create only 10 agents from the 10 first rows:
create chargingStation number: 10 from: chargingStations_csv with: [

      lat:: float(get(“center_y”)),
      lon:: float(get(“center_x”))
]

For the next step (if then I need to add 3 stations more,  I want the create function to read the 11-13th rows.), I think the simplest way is to take the rows of the chargingStations_csv.contents matrix between 11 and 13, and loop over these lines creating 1 agent for each row. You cannot rely on column names, but rather on indexes... Below an example of getting the rows between 11 and 13 of your file.

rows_list(chargingStations_csv.contents) copy_between(11,13)

Cheers
Benoit

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/gama-platform/c5771722-f556-4740-891a-db6c05e822a5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages