Export a Matrix of the agents movement

39 views
Skip to first unread message
Assigned to youce...@gmail.com by me

zaatour wajdy

unread,
Jan 16, 2019, 6:35:34 AM1/16/19
to GAMA
Hi everyone!

I want to ask how can I have a matrich which describe the number of moving from cell to another. In my case, I have 400 cell so I am looking for a matrix (400x400) which the values are the number of moving of all the agents from a cell i to a cell j devided by the number of moving in cell i (a kind of probability).

Thank u!

Wajdi

youce...@gmail.com

unread,
Jan 16, 2019, 3:26:34 PM1/16/19
to GAMA
Hi,

I'm not sure that I've well understood your question, but I tried to make a short model where each cell of the grid has an attribute (of type:  matrix) in which the moves from that cell to all the other cells are stored. Bellow is the code. 


model NewModel



global{

int grid_size <- 15 min: 5 max: 100 parameter: true;

init{

create people number: 350{

current_cell <- one_of(cell);

location <- current_cell.location;

}

}

reflex printAllCellMemo{

loop i from: 0 to: grid_size {

loop j from: 0 to: grid_size {

write ""+ i + " , " + j + " -> " + cell[i,j].mat2;

}

}

}

}


species people{

rgb color <- rnd_color(255);

cell current_cell;


reflex move {

cell c <- (one_of (cell));

if((current_cell.grid_x != c.grid_x)  and (current_cell.grid_y != c.grid_y)){

current_cell.mat2[c.grid_x,c.grid_y] <- (current_cell.mat2[c.grid_x,c.grid_y] + 1);

current_cell <- c;

location <- c.location;

}

}

aspect default {

draw sphere(1) at: {location.x,location.y,2} color: color;

}

}


grid cell width: grid_size height: grid_size {

matrix mat2 <- 0.0 as_matrix({grid_size,grid_size}); 

} 


experiment goto_grid type: gui {

output {

display objects_display type: opengl{

grid cell lines: #black;

species people;

}

}

}




So, for the cell [i,j] , the values in the matrix mat2 represents how many times agents have moved from cell [i,j] to each cell[x,y].

If that is the idea, the code can be used as a basis for your question.

Cheers, 
Youcef

zaatour wajdy

unread,
Jan 17, 2019, 7:33:24 AM1/17/19
to gama-p...@googlegroups.com
Hi and thank u for your answer.
Actually, I am looking for a Matrix contains the values of how many times agents have moved from cell [i,j] to each cell [x,y] devided by how many times agents stay in cell [i,j]. So the values are between 0 and 1. And I want to export the matrix as a CSV file.

Cheers,

Wajdi

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/kWhT7nI2Zzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

youce...@gmail.com

unread,
Jan 17, 2019, 9:23:37 AM1/17/19
to GAMA

Yes. To get the probability as you say, you have to divide each value of the matrix by the sum of all the values of the same matrix. Bellow is an example how to compute and save the result at cycle = 100: 


model NewModel



global{

int grid_size <- 5 min5 max100 parameter: true;

init{

create people number10{

current_cell <- one_of(cell);

location <- current_cell.location;

}

}

// reflex printAllCellMemo when: cycle<100{

// loop i from: 0 to: grid_size {

// loop j from: 0 to: grid_size {

// write ""+ i + " , " + j + " -> " + cell[i,j].mat2;

// }

// }

reflex computeProba whencycle=100{

loop i from0 togrid_size - 1 {

loop j from0 togrid_size - 1 {

int sum <- cell[i,j].mat2 sum_of( each );

if(sum > 0){

loop k from0 togrid_size - 1 {

loop l from0 togrid_size - 1 {

cell[i,j].mat2[k,l<- cell[i,j].mat2[k,l/ sum;

}

}

}

write ""+ i + " , " + j + " -> " + cell[i,j].mat2;

}

save cell to"../results/cell_Proba.csv" type:"csv" rewritetrue;

do pause;

}


}


species people{

rgb color <- rnd_color(255);

cell current_cell;


reflex move {

cell c <- (one_of (cell));

if((current_cell.grid_x != c.grid_x)  and (current_cell.grid_y != c.grid_y)){

current_cell.mat2[c.grid_x,c.grid_y<- (current_cell.mat2[c.grid_x,c.grid_y+ 1);

current_cell <- c;

location <- c.location;

}

}

aspect default {

draw sphere(1at: {location.x,location.y,2colorcolor;

}

}


}


grid cell widthgrid_size heightgrid_size {

matrix mat2 <- 0.0 as_matrix({grid_size,grid_size}); 

} 



experiment goto_grid type: gui {

output {

display objects_display type: opengl{

grid cell lines: #black;

species people;

}

}

}


-----
To unsubscribe from this group and all its topics, send an email to gama-platform+unsubscribe@googlegroups.com.

zaatour wajdy

unread,
Jan 18, 2019, 5:05:12 AM1/18/19
to gama-p...@googlegroups.com
Thank u Youcef !

I tried the code but I found the file empty (cell_proba)!

To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.

To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/kWhT7nI2Zzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages