Skip to content

Commit

Permalink
Fix #3410
Browse files Browse the repository at this point in the history
  • Loading branch information
tnguyenh committed May 8, 2022
1 parent aabf346 commit dac13ed
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 209 deletions.
Expand Up @@ -18,9 +18,22 @@ model GeneralizedLotkaVolterra

global {
int max_species <- 8;
list<list<string>> animal_names <- [["Goé","land"],["Ga","zelle"],["Tama","noir"],["La","pin"],["Cou","cou"],["Ca","nard"],["Cha","mois"],["Ecu","reuil"],["Elé","phant"],
string dummy <- '';

string language <- "english" among: ["french","english"];

map<string,list<list<string>>> animal_names <- map(
"french"::[["Goé","land"],["Ga","zelle"],["Tama","noir"],["La","pin"],["Cou","cou"],["Ca","nard"],["Cha","mois"],["Ecu","reuil"],["Elé","phant"],
["Droma","daire"],["Pé","lican"],["Sou","ris"],["Pou","let"],["Perro","quet"],["Rossi","gnol"],["Gre","nouille"],["Phaco","chère"],["Maque","reau"],
["Sar","dine"],["Mou","ton"],["Ser","pent"],["Tor","tue"],["Pu","tois"]];
["Sar","dine"],["Mou","ton"],["Ser","pent"],["Tor","tue"],["Pu","tois"]],
"english"::[["Chee","tah"],["Gi","raffe"],["Ele","phant"],["Ra","bbit"],["Squi","rrel"],
["Chame","leon"],["Bumble","bee"],["Bu","ffalo"],["Ze","bra"],
["Rattle","snake"],["Bea","ver"],["Sala","mander"],["Hippo","potamus"],["Pa","rrot"],
["Rhino","ceros"],["Kanga","roo"],["Leo","pard"],["Alli","gator"],
["Go","rilla"],["Croco","dile"],["Platy","pus"],["Octo","pus"],["Porcu","pine"]]
);


list<string> possible_type <-["neutral","positive","negative"];
map<string,rgb> type_color <- ["neutral"::rgb(240,240,240),"negative"::rgb(250,65,65),"positive"::rgb(150,217,100)];

Expand All @@ -35,7 +48,7 @@ global {
float hKR4 <- 0.01;

init{
create population_count;
// create population_count;
loop i from: 0 to: max_species-1{
color_list[i] <- rgb(int(240/max_species*i),int(240/max_species*i),255);
}
Expand All @@ -56,15 +69,6 @@ global {
}
}

species population_count{
list<float> pop <- list_with(max_species,0.0);

reflex update_count{
loop i from: 0 to: max_species-1{
pop[i] <- (species_list[i] != nil)?species_list[i].pop:0;
}
}
}

species animal{
float t;
Expand Down Expand Up @@ -130,7 +134,7 @@ species solver_and_scheduler{
}else{
// add a new animal species
create animal{
name <- animal_names[rnd(length(animal_names)-1)][0]+animal_names[rnd(length(animal_names)-1)][1];
name <- animal_names[language][rnd(length(animal_names[language])-1)][0]+animal_names[language][rnd(length(animal_names[language])-1)][1];
species_list[selected_button.grid_y - 1] <- self;
r <- rnd(100)/100;
k <- 30.0+rnd(50);
Expand Down Expand Up @@ -229,23 +233,26 @@ grid button width:max_species+1 height:max_species+1



experiment simulation type: gui autorun: true {
experiment simulation type: gui autorun: true {
float minimum_cycle_duration <- 0.1;
parameter "Language for animal names" var: language category: "language";
parameter "Click on '?'s to add animal species, then click on grey squares to change types of interactions.\n'+' means that the upper species has a positive impact on the left species (e.g. the left one eats the top one). '-' is for negative impact and grey for neutral. The interaction graph is shown in the lower-right corner."
var: dummy category: "Help";

output {
layout value: horizontal([0::50,vertical([1::50,2::50])::50]) tabs:true;
display action_button name:"Interaction matrix" {
species button aspect:modern ;
event mouse_down action:activate_act;
}
display LV name: "Time series" refresh: every(1#cycle) {
chart "Population" type: series background: rgb('white') x_range: 200 {
display LV name: "Time series" refresh: every(1#cycle) type: java2D {
chart "Population size" type: series background: rgb('white') x_range: 200 x_tick_line_visible: false{
loop i from: 0 to: max_species-1{
data "espèce "+i value: first(population_count).pop[i] color: (species_list[i] != nil)?color_list[i]:rgb(0,0,0,0) marker: false;
data "espèce "+i value: first(solver_and_scheduler).pop[i] color: (species_list[i] != nil)?color_list[i]:rgb(0,0,0,0) marker: false;
data "Species "+i value: first(solver_and_scheduler).pop[i] color: (species_list[i] != nil)?color_list[i]:rgb(0,0,0,0) marker: false;
}
}
}
display "Interaction graph" {
display "Interaction graph" type: java2D {
graphics "edges" {
loop edge over: the_graph.edges {
float angle <- (pair<animal,animal>(edge)).key towards (pair<animal,animal>(edge)).value;
Expand Down
Expand Up @@ -40,13 +40,20 @@ species agent_with_SIR_dynamic {
}


experiment maths type: gui {
experiment Simulation type: gui {
float minimum_cycle_duration <- 0.1#s;
output {
layout #vertical;
display display_charts {
chart "SIR_agent" type: series background: #white {
data 'S' value: first(agent_with_SIR_dynamic).S color: #green ;
data 'I' value: first(agent_with_SIR_dynamic).I color: #red ;
data 'R' value: first(agent_with_SIR_dynamic).R color: #blue ;
chart "Time series" type: series background: #white {
data 'S' value: first(agent_with_SIR_dynamic).S color: rgb(46,204,113) ;
data 'I' value: first(agent_with_SIR_dynamic).I color: rgb(231,76,60) ;
data 'R' value: first(agent_with_SIR_dynamic).R color: rgb(52,152,219) ;
}
}
display display_phase_portrait {
chart "Phase portrait" type: xy background: #white x_label:"S" y_label:"Y" x_range: {0,1600} y_range: {0,700}{
data 'I vs S' value: [first(agent_with_SIR_dynamic).S,first(agent_with_SIR_dynamic).I] color: rgb(243,156,18) ;
}
}
}
Expand Down

This file was deleted.

@@ -0,0 +1,75 @@
/**
* continuous curves
* Author: Tri and Nghi
* Description:
*
* This model illustrates different displays for a Lotka-Volterra model. ABMs usually only require a discrete
* visualization of the results (one value per cycle). EBMs compute a continuous solution, and thus require
* a continuous display. The syntax is shown below.
*
* Phase portraits are very common in mathematics, and can be displayed with the 'type: xy' facet.
*/


model Displays


global {
init {
create LV_model with: [x::2.0, y::2.0];
}
}

species LV_model {
float t;
float x;
float y;
float h <- 0.1;
float alpha <- 0.8;
float beta <- 0.3;
float gamma <- 0.2;
float delta <- 0.85;

equation eqLV {
diff(x, t) = x * (alpha - beta * y);
diff(y, t) = -y * (delta - gamma * x);
}

reflex solving {
solve eqLV method: #rk4 step_size: h;
}
}

experiment Displays type: gui {
float minimum_cycle_duration <- 0.1#s;
output {
layout #split;
display D1 synchronized:false {
chart 'Time series' type: series background: #white y_label:"pop" x_tick_line_visible: false{
data "x" value: first(LV_model).x color: rgb(52,152,219);
data "y" value: first(LV_model).y color: rgb(41,128,185);
}
}
display D2 synchronized:false {
chart 'Time series - continuous display' type: series background: #white y_label:"pop" x_tick_line_visible: false{
// chart 'Time series - continuous display' type: series x_serie: first(LV_model).t[] background: #white y_label:"pop"{
data "x" value: first(LV_model).x[] color: rgb(52,152,219) marker: false;
data "y" value: first(LV_model).y[] color: rgb(41,128,185) marker: false;
}
}
display D3 name: "Phase Portrait " synchronized:false {
chart 'Phase Portrait' type: xy background: #white x_label: "x" y_label:"y"{
// Continuous display requires to pass a list of two values x and y
data "y(x(t))" value: [first(LV_model).x,first(LV_model).y] color: rgb(243,156,18);
}
}
display D4 name: "Phase Portrait - continuous display" synchronized:false {
chart 'Phase Portrait - continuous display' type: xy background: #white x_label: "x" y_label:"y"{
// Continuous display requires to pass a list of two values x and y
data "y(x(t))" value: rows_list(matrix(first(LV_model).x[],first(LV_model).y[])) color: rgb(243,156,18) marker: false;
}
}

}

}

This file was deleted.

0 comments on commit dac13ed

Please sign in to comment.