move to highest cell value within radius

40 views
Skip to first unread message

Jaye Newman

unread,
Feb 5, 2020, 12:49:21 AM2/5/20
to gama-p...@googlegroups.com
Hi GAMA people,

I have what I think should be a simple piece of code, but it is eluding me.

A beast (agent) has a sensing_radius, a list is made of all the grid values within the beasts sensing_radius, cells_nearby. I want the beast to move to the closest highest value within its sensing_radius from the list of cells_nearby.
Please let me know if you would like this code attached as a GAMA file. 
Also, if there is a way to code the attached image(.png) in GAMA please let me know (or head me in the right direction).
Thanks so much,
Jaye

This is the code:

model sensingradiustest

global {
float sensing_radius <- 20#m;
float age <- 1.0 update: age + step;
file map_init <- image_file("...mod_raster_50px.png");

init {
create beast number: 3 {
ask cell {
color <- rgb (map_init at {grid_x,grid_y}) ;
cell_value <- 1 - (((color as list) at 0) / 255) ;
}
}
}
}

species beast skills: [moving] control: fsm {
cell myCell <- one_of (cell);
list<cell> list_target_cell <- cells_nearby where(each.cell_value > 0.4);
list<cell> cells_nearby <- cell at_distance sensing_radius update: cells_nearby;

aspect default {
draw circle(sensing_radius) color: # lightpink empty: true;
draw circle(1.0) color: #black;
}

init {
location <- myCell.location;
}

cell target_cell {
return (cells_nearby) with_max_of (each.cell_value);
}

action basic_wander {
do wander speed: 5.0;
}

action move {
if age >= 5.0 {
myCell <- target_cell ();
write self.name + "" + target_cell ;
location <- myCell.location;
} else {
do wander speed: 10.0;
}
}
state immature_beast initial: true {
enter {
location <- myCell.location;
do basic_wander;
}
transition to: naive_beast when: age >= 5.0;
}

state naive_beast {
do move;
}
}

grid cell width: 50 height: 50 neighbors: 8 {
list<cell> neighbors <- self neighbors_at 1;
float cell_value <- cell_value ;
}

experiment my_experiment {
output {
display myDisplay {
grid cell lines: #white;
species beast aspect: default;
}
}

mod_raster_50px.png

Srirama Bhamidipati

unread,
Feb 5, 2020, 5:04:41 AM2/5/20
to GAMA
Hi

Are you able to get a list of neighbors? If yes, then you can use the operator with_max_of.


Srirama

Benoit Gaudou

unread,
Feb 5, 2020, 5:19:05 AM2/5/20
to gama-p...@googlegroups.com
Dear Jaye,

Looking at your code, I am surprised by the update of the cells_nearby ... 
I have modified a little bit, as below and it seems to work...

species beast skills: [moving] control: fsm {

list<cell> cells_nearby <- cell at_distance sensing_radius // update: cells_nearby;

update: cell at_distance sensing_radius;


}


In addition, looking at the target_cell action, you could remove the current cell of the agent from the cells list, so that the agent has to change at eahc step.

cell target_cell {

return (cells_nearby - myCell) with_max_of (each.cell_value);

}



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 on the web visit https://groups.google.com/d/msgid/gama-platform/5f4ff91c-fdb7-42a3-8230-a34ef1e2b99d%40googlegroups.com.

Jaye Newman

unread,
Feb 5, 2020, 9:43:35 PM2/5/20
to gama-p...@googlegroups.com
Hi Benoit,

Those modifications now work, thanks so much

Cheers,
Jaye

Reply all
Reply to author
Forward
0 new messages