NetLogo: how to make the calculation of turtle movement easier?

 ̄綄美尐妖づ 提交于 2019-12-13 01:28:45

问题


I am working with NetLogo code written with somebody else (freely available to public). I try to understand how the procedure of turtle moving is elaborated and, most important - how make it computationally faster without loosing sensitivity of turtle movement in relation to worlds' patches?

I suppose that the most of the calculation time is used to calculate the distance of each step of turtle movement - I would like to measure only one variable from patch of turtle's origins to last patch where it will stay. I have decoded some of features but I am still not able to reproduce them. I'll really appreciate any help !

My understanding what the procedure could accomplish:

to move-turtles                                                                    
   ifelse perceptdist = 0                                                           
    [ifelse patch-ahead 1 != nobody 
     [rt random moveangle lt random moveangle                                      
      let xcorhere [pxcor] of patch-here                                           
      let ycorhere [pycor] of patch-here                                           
      fd 1
      let xcornext [pxcor] of patch-here                                           
      let ycornext [pycor] of patch-here                                           
      set dist sqrt (xcor * xcor + ycor * ycor)                                        
      set t_dispers (t_dispers + 1)                                                 
      set energy (energy - (1 / efficiency))                                       
      let flightdistnow sqrt ((xcornext  - xcorhere) * (xcornext  - xcorhere) + (ycornext - ycorhere) * (ycornext - ycorhere))   
      set flightdist (flightdist + flightdistnow)

    ][]]     

   [let np patches in-radius perceptdist          ; find the patch with the highest totalattract value within perception range                                 
    let bnp max-one-of np [totalattract]                                              
    let ah [totalattract] of patch-here
    let xcorhere [pxcor] of patch-here
    let ycorhere [pycor] of patch-here                                             
    let abnp [totalattract] of bnp 

    ; -- why this ifelse condition is here ansd why they use these numbers??    ---      
   ifelse abnp - ah > 2 and random-float 1 < 0.1                                  
     [move-to bnp                                     ; move to the patch with the highest attractivity value
      let xbnp [pxcor] of bnp                                 
      let ybnp [pycor] of bnp
      let flightdistnow sqrt ((xbnp - xcorhere) * (xbnp - xcorhere) + (ybnp - ycorhere) * (ybnp - ycorhere)) 
      set t_dispers (t_dispers + flightdistnow)                
      set energy (energy - (flightdistnow / efficiency))      ; how the turtle decision to stay/move further is made - ratio of turtle energy/efficiency  
      set flightdist (flightdist + flightdistnow)
      set dist sqrt (xcor * xcor + ycor * ycor)               

   [rt random moveangle lt random moveangle                                        
    set dist sqrt (xcor * xcor + ycor * ycor)                                      
    set t_dispers (t_dispers + 1)                                                  
    set energy (energy - (1 / efficiency))                                         
    let xcorhere2 [pxcor] of patch-here                                           
    let ycorhere2 [pycor] of patch-here                                            
    fd 1
    let xcornext2 [pxcor] of patch-here                                            
    let ycornext2[pycor] of patch-here                                             
    set dist sqrt (xcor * xcor + ycor * ycor)                                         
    let flightdistnow sqrt ((xcornext2  - xcorhere2) * (xcornext2  - xcorhere2) + (ycornext2 - ycorhere2) * (ycornext2 - ycorhere2))   
    set flightdist (flightdist + flightdistnow)

end  

来源:https://stackoverflow.com/questions/32319606/netlogo-how-to-make-the-calculation-of-turtle-movement-easier

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!