|  | 
 
| 新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。9 v) [* _& H6 N4 }  ~+ [ netlogo自带的social science--traffic grid这一例子当中,
 ( _( R4 C& o4 J2 `, C, ?) Hglobals
 ' y- W! k  A2 @6 W, a9 H3 H' }[! m6 B) q1 o+ Y0 M% b8 \
 grid-x-inc               ;; the amount of patches in between two roads in the x direction
 * J' q+ @2 D6 K- \0 _% p3 a9 ~  grid-y-inc               ;; the amount of patches in between two roads in the y direction3 J8 o; C* I; x3 J$ o
 acceleration             ;; the constant that controls how much a car speeds up or slows down by if# Z3 D+ r8 `0 |+ e- Q! W  E
 ;; it is to accelerate or decelerate( Q8 R' D, |) a0 H  h
 phase                    ;; keeps track of the phase6 Z2 b) C7 L# c3 }. U. I$ @  ?/ E
 num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure; b5 x7 D0 P8 R( A, a$ u! U
 current-light            ;; the currently selected light
 m8 v  v/ F6 H1 I* x. Q/ g8 r5 Z/ a  G9 [
 ;; patch agentsets8 M* X) C) z+ w" q2 x$ W6 ^& R$ `2 ^
 intersections ;; agentset containing the patches that are intersections
 * c9 q* U- T/ Q$ i  roads         ;; agentset containing the patches that are roads
 + v+ G& B$ L. F& p. s]
 7 W" V# b4 A& @# `& v& l8 v" C* ]( M8 q! y2 l" D) Z
 turtles-own/ s) M, L# D" M/ n9 y
 [; u0 V' L, i5 ]  X9 {
 speed     ;; the speed of the turtle$ g& T0 ]$ q* U# @; f) w& i2 R, D
 up-car?   ;; true if the turtle moves downwards and false if it moves to the right
 4 z* W% Y6 ^1 }. U  wait-time ;; the amount of time since the last time a turtle has moved2 x5 h) p! Y! R1 }0 v% V  r; Z
 ]7 l! Z  R; R/ x
 0 A: F4 G2 L3 R8 P
 patches-own
 ; {. X: f! r* a4 B[
 3 M: h: ^+ J# X* R+ l$ O" h- \& o  intersection?   ;; true if the patch is at the intersection of two roads
 , N. A2 s! K+ o  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.  u0 o4 b. x2 N& D+ P$ ?. d! X' K
 ;; false for a non-intersection patches.
 / l" e* P6 X  _2 W8 b' T; |  my-row          ;; the row of the intersection counting from the upper left corner of the" A& c- R; d4 p! _. S% F
 ;; world.  -1 for non-intersection patches.- \9 X; Q5 F" J+ E% ^8 y
 my-column       ;; the column of the intersection counting from the upper left corner of the" ^+ \: ]7 ?& l6 ^
 ;; world.  -1 for non-intersection patches.' Q. x7 U) b- N% G) U$ q. _' ^
 my-phase        ;; the phase for the intersection.  -1 for non-intersection patches.% g* W4 ^$ R# J; x6 C
 auto?           ;; whether or not this intersection will switch automatically.7 A$ }  m. C; k& [
 ;; false for non-intersection patches.) G$ ~' w5 A9 d  |) D
 ]; U. `. u; c) B# S2 D) D8 y7 `
 
 & q8 F# p6 r' x' Q9 k& i! L4 \. X' m+ z, p" U/ p6 M: t, x$ t3 b, {
 ;;;;;;;;;;;;;;;;;;;;;;
 7 J: @6 K6 e3 d$ o! B;; Setup Procedures ;;
 & L9 R( |1 C1 V1 S3 h. w" d;;;;;;;;;;;;;;;;;;;;;;
 - z3 |+ `: S$ R' |! ^+ f- I3 S% g: i) w
 ;; Initialize the display by giving the global and patch variables initial values.. r" V  h* w; \$ N% e4 K2 E
 ;; Create num-cars of turtles if there are enough road patches for one turtle to- S" ]2 Z5 J3 K1 W( c7 W6 K/ o; t
 ;; be created per road patch. Set up the plots.  m! ?, s7 b. i
 to setup
 8 I+ m7 J* L, r* m8 a! b7 z' s) J  o  ca5 z8 V* s4 g* }
 setup-globals
 2 A9 f$ w' T" N0 @4 f, q9 b' C3 N
 ;; First we ask the patches to draw themselves and set up a few variables
 * g0 w4 A+ A4 H  setup-patches' f0 z. B* v- H1 R
 make-current one-of intersections4 A& q" c: g# D  f. X. Z
 label-current
 3 x4 N6 S  s! Q( @  r, E) D5 d3 J* z) ^1 a
 set-default-shape turtles "car"3 {' @4 R: W' v1 M
 
 / |* b2 J; f# A' i- X. u' T  if (num-cars > count roads)3 A) x' z; D  _4 x4 K+ Y) X- y- U
 [
 ! D' n! M+ c' O3 i% B! c; l: @    user-message (word "There are too many cars for the amount of "
 8 B1 }( ]# |- Z4 m0 X- C                       "road.  Either increase the amount of roads "
 ' l9 ?& n- e& s9 e/ }                       "by increasing the GRID-SIZE-X or "2 ~4 t# Y( J0 O$ {( R* B
 "GRID-SIZE-Y sliders, or decrease the ". r. Q8 d# i+ ^, a
 "number of cars by lowering the NUMBER slider.\n"
 ( q. E/ Y7 A5 p                       "The setup has stopped.")* E& l5 o. M' n; y- t  k( X4 m
 stop
 4 C6 y! a9 U1 c' r' S  ]
 5 M# \1 D$ @" c% b8 @
 ' j* y* z2 O8 e  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color6 G! N! `% X2 s: l2 {
 crt num-cars
 + w1 S0 b" o+ O. r  [
 : E/ ~8 c8 L3 L+ i2 ?    setup-cars8 T1 I$ Z0 Q- a
 set-car-color' C+ D, u% U1 {" [; Z# L; u5 y
 record-data
 7 X% T5 j- ~9 h  ]; t: S) B0 }% V! V4 Q+ p$ m/ O
 
 4 `0 }" g- L3 e% X) i: e  ;; give the turtles an initial speed5 a( M% W  U- l$ g& e
 ask turtles [ set-car-speed ]
 ' ^  S( E* ?2 {- h8 ^6 z+ q  n
 % _% O0 S7 P( u- Y7 d- j  reset-ticks
 . ~' ~. s8 G/ Oend( Y/ C4 g. q( i( B8 \* U
 
 ' @, w2 i. r7 E5 }; x; F7 x;; Initialize the global variables to appropriate values
 0 `" J/ B  X+ P$ O# hto setup-globals
 ! I9 m5 K+ q. W3 |$ _  set current-light nobody ;; just for now, since there are no lights yet
 0 d! |- ]- W% C$ G/ z% g; x  set phase 0* f) ~8 v% M4 X/ J0 y/ z
 set num-cars-stopped 0- l/ ~6 \" O6 X( p7 _$ P  K
 set grid-x-inc world-width / grid-size-x
 m2 o* L/ ]& X+ S2 ?0 D' ^  set grid-y-inc world-height / grid-size-y6 ]- ?3 a# O( ?8 [) b2 z5 e
 
 , q7 W* a4 m/ n# K& K5 S' `4 i- S* ^, p  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary
 , h/ e) T; H1 \* \( J1 |4 A  set acceleration 0.099
 - y1 l3 S# f4 u  J6 iend
 ) U; z' P1 a, C8 S" X; }* s+ Y4 M0 P+ L
 ;; Make the patches have appropriate colors, set up the roads and intersections agentsets,( U2 f% ]- ?$ Z4 W2 N
 ;; and initialize the traffic lights to one setting# D  H! G: r, |/ X6 o. ]# G& s1 ]
 to setup-patches$ Z$ k7 A# Y4 D2 Q( Y8 r' I
 ;; initialize the patch-owned variables and color the patches to a base-color. W& |2 t* O( F5 J, c0 h$ D: g' d
 ask patches  H% y/ m) ~) o4 n
 [) z, z4 u: W0 B7 I, Y& F
 set intersection? false6 i/ z! u- ]/ j$ W" t
 set auto? false
 $ ^' C2 s" Q% E1 m" G    set green-light-up? true% B: X4 W; a# U9 Z# l
 set my-row -1
 1 G/ j3 F: U' ?; Y( H) r+ _. a* H" N9 Q    set my-column -1
 ; |) Z$ x; o9 ?1 v  H7 v5 v+ u# f; D    set my-phase -1" X$ h' b7 d* |+ C: r
 set pcolor brown + 3
 ' R; ~5 x1 e4 |+ y' C  ]  p/ x7 e  F* b2 r9 l: T
 9 L1 A* j: Y4 S/ X+ k" K( G6 A5 ?
 ;; initialize the global variables that hold patch agentsets
 1 E# B  k8 M1 |0 \  set roads patches with4 ~5 g$ X& _; ]4 @) e& A
 [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or+ T7 F6 t' T8 r6 B" P0 I
 (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
 3 G8 Z! S. ]0 q& Z  set intersections roads with
 3 w& _) C/ N, ?& l    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and. H  Q  N3 Q/ H+ R
 (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
 H. J# f* I3 l* ~0 Y5 B8 U) Y5 R/ [$ V' X% S& a
 ask roads [ set pcolor white ]
 , m! h" o# e' m, d( g    setup-intersections
 6 J  T: H- p2 x4 F' j( dend0 r* {" j2 ?0 w( x' D
 其中定义道路的句子,如下所示,是什么意思啊?
 # d6 i; j& r' s% o! M6 ] set roads patches with( y! J  e: Q& Z+ J+ S$ S7 |( M
 [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
 1 T9 k5 g  W( u# F% h    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]% G* I+ J+ [! O: m
 谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
 | 
 |