Created
October 30, 2015 16:43
-
-
Save RCura/c95a2e34579a9f7b901f to your computer and use it in GitHub Desktop.
Wrong performances of the closest_to operator in Gama 1.7 (dev)
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
/** | |
* closest_to | |
* Author: Robin Cura | |
* Description: | |
*/ | |
model closest_to | |
global { | |
reflex HighCallerLowCalled { | |
create agent1 number: 10000{ set location <- any_location_in(world);} | |
create agent2 number: 100 {set location <- any_location_in(world);} | |
write("HighCallerLowCalled"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo; do reset;} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo; do reset;} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance; do reset;} | |
float time3 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3)); | |
} | |
reflex LowCallerHighCalled { | |
create agent1 number: 100{ set location <- any_location_in(world);} | |
create agent2 number: 10000 {set location <- any_location_in(world);} | |
write("LowCallerHighCalled"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo; do reset;} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo; do reset;} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance; do reset;} | |
float time3 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3)); | |
} | |
reflex HighCallerHighCalled { | |
create agent1 number: 10000{ set location <- any_location_in(world);} | |
create agent2 number: 10000 {set location <- any_location_in(world);} | |
write("HighCallerHighCalled"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo; do reset;} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo; do reset;} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance; do reset;} | |
float time3 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3)); | |
} | |
reflex LowCallerLowCalled { | |
create agent1 number: 100{ set location <- any_location_in(world);} | |
create agent2 number: 100 {set location <- any_location_in(world);} | |
write("LowCallerLowCalled"); | |
float thisTime1 <- machine_time; | |
ask agent1 {do closestTo; do reset;} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 {do optimClosestTo; do reset;} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 {do minDistance; do reset;} | |
float time3 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3)); | |
} | |
reflex sameCallerSameCalledLow { | |
create agent1 number: 100{ set location <- any_location_in(world);} | |
write("sameCallerSameCalledLow"); | |
float thisTime1 <- machine_time; | |
ask agent1 { | |
set closestNeighbor <- agent1 closest_to self; | |
do reset; | |
} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 { | |
set closestNeighbor <- (agent1 at_distance 30) closest_to self; | |
if (closestNeighbor = nil){set closestNeighbor <- agent1 closest_to self;} | |
do reset; | |
} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 { | |
set closestNeighbor <- one_of( agent1 at_distance min(agent1 collect (each distance_to self))); | |
do reset; | |
} | |
float time3 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3)); | |
} | |
reflex sameCallerSameCalledHigh { | |
create agent1 number: 10000{ set location <- any_location_in(world);} | |
write("sameCallerSameCalledHigh"); | |
float thisTime1 <- machine_time; | |
ask agent1 { | |
set closestNeighbor <- agent1 closest_to self; | |
do reset; | |
} | |
float time1 <- machine_time; | |
float thisTime2 <- machine_time; | |
ask agent1 { | |
set closestNeighbor <- (agent1 at_distance 30) closest_to self; | |
if (closestNeighbor = nil){set closestNeighbor <- agent1 closest_to self;} | |
do reset; | |
} | |
float time2 <- machine_time; | |
float thisTime3 <- machine_time; | |
ask agent1 { | |
set closestNeighbor <- one_of( agent1 at_distance min(agent1 collect (each distance_to self))); | |
do reset; | |
} | |
float time3 <- machine_time; | |
ask agent1 {do die;} | |
ask agent2 {do die;} | |
write("closestTo : " + round(time1 - thisTime1) + | |
" / OptimClosestTo : "+round(time2 - thisTime2) + | |
" / minDistance : " + round(time3 - thisTime3)); | |
} | |
} | |
entities { | |
species agent1 { | |
agent closestNeighbor; | |
action closestTo { | |
set closestNeighbor <- agent2 closest_to self; | |
} | |
action optimClosestTo{ | |
set closestNeighbor <- (agent2 at_distance 30) closest_to self; | |
if (closestNeighbor = nil){set closestNeighbor <- agent2 closest_to self;} | |
} | |
action minDistance{ | |
set closestNeighbor <- one_of( agent2 at_distance min(agent2 collect (each distance_to self))); | |
} | |
action reset { set closestNeighbor <- nil;} | |
} | |
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