Locate 900 agents on a 30x30 grid

31 views
Skip to first unread message

Benoit Gaudou

unread,
Feb 20, 2019, 6:48:37 AM2/20/19
to gama-p...@googlegroups.com
Dear all,

I have below a model where I want to locate goats on a grid, 1 goat per cell.
I use agents_inside to identify cell that are empty or not:

my_plot <- one_of(plot where(empty(agents_inside(each))));


When I create 899, everything is fine. I have 1 plot empty.
When I want to create 900, I have a NPE : GAMA cannot find the last empty cell.

An issue of mine or a bug of GAMA ?

Cheers

Benoit




global {

int init_goat_population <- 899;

init {

create goat number: init_goat_population;

}

}


grid plot height: 30 width: 30 {

}


species goat {

plot my_plot;

init {

my_plot <- one_of(plot where(empty(agents_inside(each))));

location <- my_plot.location;

}

aspect default {

draw circle(1.0) color: #blue;

}

}


experiment e {

output {

display biomass {

grid plot lines: #black;

species goat;

}

}

}

Patrick Taillandier

unread,
Feb 20, 2019, 7:19:03 AM2/20/19
to gama-p...@googlegroups.com
Hi,

I found the problem: it is due to the fact that when creating agents, the first thing that GAMA does is to give them a default value for their attributes before executing what is inside the "init" block. The default value for the location is a random value inside the world, so it means that even before trying to set the goat to an empty cell, many cells are not empty. 

If you remove the init block of the goat and change a bit the code by first setting to all goat agents a location outside the grid before trying to find an empty cell, it is going to work:

init {
create goat number: init_goat_population with: [location::{-1,-1}];
ask goat {
my_plot <- one_of(plot where (empty(agents_inside(each))));
location <- my_plot.location;
}
}

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 https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages