Created
October 31, 2015 18:40
-
-
Save RCura/de70ab070f96fd7c413f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model closest_to | |
global { | |
int nb_agents_min <- 50; | |
int nb_agents_max <- 5000; | |
bool agent1_use_geom <- false; | |
bool agent2_use_geom <- false; | |
geometry agent1_geom <- circle(3); | |
geometry agent2_geom <- circle(5); | |
reflex init_cycle { | |
write "\n ---------------------------------------"; | |
write("******* CYCLE:" + cycle +" ******"); | |
if cycle =1 { | |
agent1_use_geom <- true; | |
agent2_use_geom <- false; | |
} else if cycle = 2 { | |
agent1_use_geom <- false; | |
agent2_use_geom <- true; | |
}else if cycle = 3 { | |
agent1_use_geom <- true; | |
agent2_use_geom <- true; | |
} else if cycle > 3 { | |
do pause; | |
} | |
} | |
reflex HighCallerLowCalled { | |
create agent1 number: nb_agents_max { | |
if agent1_use_geom {shape <- copy(agent1_geom) at_location location;} | |
} | |
create agent2 number: nb_agents_min { | |
if agent2_use_geom {shape <- copy(agent2_geom) at_location location;} | |
} | |
write("\n******* HighCallerLowCalled ******"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo(false); } | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo(false);} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance(false);} | |
float time3 <- machine_time; | |
float thisTime4 <- machine_time; | |
ask agent1 {do basicClosestTo(false);} | |
float time4 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3) + | |
" / basicClosestTo : " + round(time4 - thisTime4)); | |
} | |
reflex LowCallerHighCalled { | |
create agent1 number: nb_agents_min { | |
if agent1_use_geom {shape <- copy(agent1_geom) at_location location;} | |
} | |
create agent2 number: nb_agents_max { | |
if agent2_use_geom {shape <- copy(agent2_geom) at_location location;} | |
} | |
write("\n******* LowCallerHighCalled ******"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo(false);} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo(false);} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance(false);} | |
float time3 <- machine_time; | |
float thisTime4 <- machine_time; | |
ask agent1 {do basicClosestTo(false);} | |
float time4 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3) + | |
" / basicClosestTo : " + round(time4 - thisTime4)); | |
} | |
reflex HighCallerHighCalled { | |
create agent1 number: nb_agents_max { | |
if agent1_use_geom {shape <- copy(agent1_geom) at_location location;} | |
} | |
create agent2 number: nb_agents_max { | |
if agent2_use_geom {shape <- copy(agent2_geom) at_location location;} | |
} | |
write("\n******* HighCallerHighCalled ******"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo(false); } | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo(false);} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance(false); } | |
float time3 <- machine_time; | |
float thisTime4 <- machine_time; | |
ask agent1 {do basicClosestTo(false);} | |
float time4 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3) + | |
" / basicClosestTo : " + round(time4 - thisTime4)); | |
} | |
reflex LowCallerLowCalled { | |
create agent1 number: nb_agents_min { | |
if agent1_use_geom {shape <- copy(agent1_geom) at_location location;} | |
} | |
create agent2 number: nb_agents_min { | |
if agent2_use_geom {shape <- copy(agent2_geom) at_location location;} | |
} | |
write("\n******* LowCallerLowCalled ******"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo(true); } | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo(true); } | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance(true); } | |
float time3 <- machine_time; | |
float thisTime4 <- machine_time; | |
ask agent1 {do basicClosestTo(true); } | |
float time4 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3) + | |
" / basicClosestTo : " + round(time4 - thisTime4)); | |
} | |
reflex sameCallerSameCalledLow { | |
create agent1 number: nb_agents_min { | |
if agent1_use_geom {shape <- copy(agent1_geom) at_location location;} | |
} | |
write("\n******* sameCallerSameCalledLow ******"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo(true); } | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo(true); } | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance(true); } | |
float time3 <- machine_time; | |
float thisTime4 <- machine_time; | |
ask agent1 {do basicClosestTo(true); } | |
float time4 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3) + | |
" / basicClosestTo : " + round(time4 - thisTime4)); | |
} | |
reflex sameCallerSameCalledHigh { | |
create agent1 number: nb_agents_max { | |
if agent1_use_geom {shape <- copy(agent1_geom) at_location location;} | |
} | |
write("\n******* sameCallerSameCalledHigh ******"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo(true); } | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo(true); } | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance(true); } | |
float time3 <- machine_time; | |
float thisTime4 <- machine_time; | |
ask agent1 {do basicClosestTo(true); } | |
float time4 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3) + | |
" / basicClosestTo : " + round(time4 - thisTime4)); | |
} | |
} | |
species agent1 { | |
agent closestNeighbor; | |
action basicClosestTo (bool same_species){ | |
if (same_species) {closestNeighbor <- (agent1 - self) with_min_of (self distance_to each);} | |
else {closestNeighbor <- agent2 with_min_of (self distance_to each);} | |
} | |
action closestTo (bool same_species){ | |
if (same_species) {closestNeighbor <- agent1 closest_to self;} | |
else {closestNeighbor <- agent2 closest_to self;} | |
} | |
action optimClosestTo(bool same_species){ | |
if (same_species) { | |
closestNeighbor <- (agent1 at_distance 30) closest_to self; | |
if (closestNeighbor = nil){ closestNeighbor <- agent1 closest_to self;} | |
} else { | |
closestNeighbor <- (agent2 at_distance 30) closest_to self; | |
if (closestNeighbor = nil){ closestNeighbor <- agent2 closest_to self;} | |
} | |
} | |
action minDistance (bool same_species){ | |
if (same_species) {closestNeighbor <- one_of( agent1 at_distance min(agent1 collect (each distance_to self)));} | |
else {closestNeighbor <- one_of( agent2 at_distance min(agent2 collect (each distance_to self)));} | |
} | |
} | |
species agent2; | |
experiment closest_to type: gui ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment