Skip to content

Instantly share code, notes, and snippets.

@RCura
Created September 24, 2015 12:47
Show Gist options
  • Save RCura/c1458ce6997da3cdca1a to your computer and use it in GitHub Desktop.
Save RCura/c1458ce6997da3cdca1a to your computer and use it in GitHub Desktop.
Gama : batch mode errors
model si
// A simple infection spreading model
global {
int number_people <- 300; // The init number of people
int number_I <- 1 ; // The init number of infected
float infection_rate <- 0.1 ; // The infection rate
float infection_distance <- 5.0 ; // infection distance (in meters)
int immune_step <- 30 ; // number of steps before becoming immune after infection
int end_immunity_step <-50; // number of steps before not being immune anymore
float speed_people <- 5.0 ; // speed of the Host
int nb_infected <- 0;
init {
create people number: number_people ;
ask (number_I among people) {
is_infected <- true;
color <- #red;
}
}
}
species people skills:[moving] {
bool is_infected <- false;
bool is_immune <- false;
rgb color <- #green;
int cpt <- 0;
reflex basic_move {
do wander speed: speed_people;
}
reflex end_of_immunity when: is_immune {
if (cpt > end_immunity_step) {
cpt <- 0;
is_immune <- false;
color <- #green;
} else {
cpt <- cpt + 1;
}
}
reflex become_immune when: is_infected {
if (cpt > immune_step) {
cpt <- 0;
is_immune <- true;
is_infected <- false;
color <- #blue;
} else {
cpt <- cpt + 1;
}
}
reflex become_infected when: not is_infected and not is_immune{
if (flip(infection_rate) and not empty(people at_distance infection_distance where each.is_infected)) {
is_infected <- true;
color <- #red;
nb_infected <- nb_infected + 1;
}
}
aspect default {
draw circle(1) color: color;
}
}
experiment "GUI" type:gui {
parameter number_people var: number_people min: 100 max: 400 step: 50;
output {
display "GUI" refresh: every(1) {
chart "PPl" type: series {
data "Infected" value: people count (each.is_immune) color: #red;
}
}
}
}
experiment 'Bugged' type: batch repeat: 5 keep_seed: true until: ( time > 1000 ) {
parameter number_people var: number_people min: 100 max: 400 step: 50;
permanent {
display "Bugged" refresh: every(1) {
chart "PPl" type: series {
data "Infected" value: people count (each.is_immune) color: #red;
}
}
}
}
experiment 'Working' type: batch repeat: 5 keep_seed: true until: ( time > 1000 ) {
parameter number_people var: number_people min: 100 max: 400 step: 50;
permanent {
display "Working" refresh: every(1) {
chart "PPl" type: series {
data "Infected" value: nb_infected color: #red;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment