Create a certain number of agents at certain cycles and certain position due to loaded matrix

55 views
Skip to first unread message

Benjamin Mewes

unread,
Oct 30, 2015, 8:46:27 AM10/30/15
to GAMA
Hi all,

as my model is developing right now, I want to ask for your opinion on how to set it up:

Problem:

After the initialisation of the model (which works) I want to create agents in a certain manner:

1. at give timesteps I want to load an ascii grid which contain certain patterns where agents appear

2. as long as a grid is loaded (for example from timestep 100 to timestep 200) I want to create agents on the positions given by the ascii grid

The grid is set up with the same spatial resolution as the loaded grid. Do you have recommendatios how to implement these functions without stressing memory and the CPU?

Thanks for advice!

Patrick Taillandier

unread,
Oct 30, 2015, 10:18:31 AM10/30/15
to gama-p...@googlegroups.com
Hi,

The easiest way for me is just to load your second file as a matrix and used it to create your agents.  

matrix new_agents <- matrix (csv_file("../includes/my_files.csv"));


Note that if you choose this solution, you should save your second asc file as a csv file (just remove the header) 
Cheers,

Patrick

--
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 post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Benjamin Mewes

unread,
Oct 30, 2015, 10:29:35 AM10/30/15
to GAMA
Hi Patrick,

okay, just I thought :) Fine!

From a performance point of view: Where should I declare:

reflex create_newAgents

It is part of global{} but not in the init but as a normal reflex, or is there another clean solution?

Benjamin Mewes

unread,
Nov 11, 2015, 7:33:52 AM11/11/15
to GAMA
One more question on that Patrick:

I loaded the matrix as a global matrix. Imagine the dimensions are the same with the grid. Now I want to create N agents where the matrix value N > 0. How would I do that?


Am Freitag, 30. Oktober 2015 15:18:31 UTC+1 schrieb Patrick Taillandier:

Patrick Taillandier

unread,
Nov 11, 2015, 7:50:46 AM11/11/15
to gama-p...@googlegroups.com
Hi,

In the global init or in a global reflex, you can just write make a loop on the rows and the columns of the matrix.


Model example:

model createfrommatrix


global {

init {

  matrix new_agents <- create_a_matrix();

loop i from: 0 to: new_agents.rows -1{

loop j from: 0 to: new_agents.columns -1 {

int val <- int(new_agents[i,j]);

if (val > 0) {

cell my_cell <- cell[i,j];

create dummy number: val {

location <- any_location_in(my_cell);

}

}

}

}

}

matrix create_a_matrix {

matrix mat <- 0 as_matrix {10,10};

loop i from: 0 to: mat.rows - 1{

loop j from: 0 to: mat.columns -1 {

mat[i,j] <- rnd(3);

}

write mat;

return mat;

}

}


species dummy {

aspect default {draw circle(0.5) color: #red;} 

}


grid cell width: 10 height: 10 ;


experiment createfrommatrix type: gui {

output {

display map {

grid cell lines: #black;

species dummy;

}

}

}

Cheers,

Patrick

Benjamin Mewes

unread,
Nov 12, 2015, 2:39:30 AM11/12/15
to GAMA
That did it :) Thanks a lot!
Reply all
Reply to author
Forward
0 new messages