I would like the agents to move to the highest quality plot that is above a threshold. At the moment the code does not work, I would like if the good_plots are !nil then find one of the best ones, else do wander. It does not seem to be doing the else statement.
There are parts of the map there will be plots that have a low quality and so the list of good_plots will be nil.
Here is a summary of my code and I have attached the map.
model ifelsemovement
global {
int nb_fly <- 3;
float speed_value <- 1.0;
float sensing_radius <- 15#m;
float plot_tolerance <- 0.3;
file map_init <- image_file("C:/.../mod_raster2_50px.png");
init {
create fly number: nb_fly{
ask plot {
color <- rgb (map_init at {grid_x,grid_y}) ;
plot_quality <- 1 - (((color as list) at 0) / 255) ;
}
}
}
}
species fly skills: [moving] control: fsm {
plot myPlot <- plot grid_at {0, 0};
float maturation_rate <- 0.15;
float maturation <- maturation_rate update: maturation_rate + maturation;
list<plot> plots_nearby <- plot at_distance sensing_radius update: plot at_distance sensing_radius;
list<plot> good_plots <- plots_nearby where(each.plot_quality >= plot_tolerance) update: plots_nearby where(each.plot_quality >= plot_tolerance);
init {
location <- myPlot.location;
}
action basic_wander {
do wander speed: speed_value *2;
}
action directed_move {
// if good_plots = !nil { } this code does not work
if state = "adult" { // this code works but I would like if the plots = !nil then do the following, else just do wander.
plot maxplot <- (good_plots - myPlot) with_max_of (each.plot_quality);
float maxquality <- maxplot.plot_quality;
myPlot <- one_of(good_plots where(each.plot_quality = maxquality));
location <- myPlot.location;
write "directed move";
} else {
do wander speed: speed_value * 2;
write "wander";
}
}
state young initial: true {
do basic_wander;
transition to: adult when: maturation >= 1.0;
}
state adult {
do basic_wander;
do directed_move;
}
aspect default {
draw circle(sensing_radius) color: #thistle empty: true;
draw circle(0.5) color: #brown rotate: 90 + my heading;
}
}
grid plot width: 50 height: 50 neighbors: 8 {
float plot_quality <- plot_quality ;
aspect default {
draw circle(0.4) color: color border: #black;
}
}
experiment my_experiment {
float minimum_cycle_duration <- 0.15;
parameter "initial nb flies" var: nb_fly;
output {
display myDisplay {
grid plot lines: #white;
species fly aspect: default;
}
}
}