lundi 31 août 2015

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

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:

enter image description here

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                                                 
    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  



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire