设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8742|回复: 0

[求助] 在看例子时有几个问题看不懂

[复制链接]
发表于 2012-6-20 08:59:43 | 显示全部楼层 |阅读模式
新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。
' m: i0 C& P  @0 R: enetlogo自带的social science--traffic grid这一例子当中,8 x  [# D) Z( F8 O
globals$ ~$ y7 O; p3 h) u) q3 g7 V+ {
[
+ t( i( Z3 T$ I6 e0 \- C5 M  @4 Y  grid-x-inc               ;; the amount of patches in between two roads in the x direction
' L. D4 s, S" _9 S* a  grid-y-inc               ;; the amount of patches in between two roads in the y direction
8 f6 N  \4 p! G  acceleration             ;; the constant that controls how much a car speeds up or slows down by if/ n6 F8 q1 T6 q; [7 }
                           ;; it is to accelerate or decelerate/ _$ l0 B$ [  Q: B" r
  phase                    ;; keeps track of the phase
* h' w2 v4 N1 W! n  num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure9 m9 }8 a# b6 c. L( S, n
  current-light            ;; the currently selected light
+ Z4 ~# m( j0 `# s! t9 `4 q: {/ }+ j7 @5 p  u
  ;; patch agentsets8 F3 q9 X0 O( |; R
  intersections ;; agentset containing the patches that are intersections
  n+ G$ @, ~2 M* ^+ N  roads         ;; agentset containing the patches that are roads+ f+ z0 K" D$ V" [$ L5 q% a6 z
]
) u' Q8 F7 d) k2 P4 r& s9 h7 U/ K+ L6 v
turtles-own8 i- }' q6 O, g1 p/ N. J. |
[
9 n( D) S" K( ~  speed     ;; the speed of the turtle
& h% k6 b, H' t0 q  up-car?   ;; true if the turtle moves downwards and false if it moves to the right1 E( r# e0 A) I5 x4 `
  wait-time ;; the amount of time since the last time a turtle has moved
* w5 h7 r1 o! i2 f( E8 J) Z]5 l* r5 ^/ z* Q

/ O( A4 T/ ]. B  Opatches-own1 Q- I- g. z$ K) q8 |
[& B( `! g4 ~! S0 X3 t6 S; f
  intersection?   ;; true if the patch is at the intersection of two roads
1 o6 C6 h$ [6 A. ?1 G  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.
2 W! g" E( M( L! L* L                  ;; false for a non-intersection patches.
2 I: z/ V. ~3 o5 _  my-row          ;; the row of the intersection counting from the upper left corner of the; Y1 @8 D$ x0 J# G) L
                  ;; world.  -1 for non-intersection patches.) i2 I: s. ^( O& V* j
  my-column       ;; the column of the intersection counting from the upper left corner of the
4 t0 j, h% f1 g) j5 F# ^                  ;; world.  -1 for non-intersection patches.
! G2 R+ K3 u  H: m' G  my-phase        ;; the phase for the intersection.  -1 for non-intersection patches., g& [. h% K. Q  c0 d6 ]: f
  auto?           ;; whether or not this intersection will switch automatically.
* P$ E7 d: I- \                  ;; false for non-intersection patches.. A7 c; {2 O" g
]7 y' d: W( ?0 ]9 V
0 n9 R" D1 C; I! M  N$ ?# v0 C
# S$ m  X/ e. @( O* R: |! H
;;;;;;;;;;;;;;;;;;;;;;. G9 f6 ]9 g4 Z& b, V; U
;; Setup Procedures ;;
, Q+ ~( \+ u  x;;;;;;;;;;;;;;;;;;;;;;3 P- L9 c4 ]( f& b1 w. e7 q

9 z9 t4 ^" s0 X. @. K9 i/ Q9 p) Q;; Initialize the display by giving the global and patch variables initial values." T+ E* }2 r: c/ M7 a0 k
;; Create num-cars of turtles if there are enough road patches for one turtle to, |, o, q; G% P9 z$ B7 \" ]; Q
;; be created per road patch. Set up the plots.
3 p+ v, Q6 U2 \, A0 j2 rto setup
0 m8 ]. H! S6 e2 ^/ k  ca
: j' K; R2 N7 G5 y5 g( t  setup-globals
  k" p. r* x) u; Y6 U6 T. j6 d" y+ o' d% q- N
  ;; First we ask the patches to draw themselves and set up a few variables
/ f2 K! k4 Q) q- b# K- N; I4 R  setup-patches
, P2 H7 R; j- n: w  make-current one-of intersections
! C( e/ }6 x* V. U& k, ^4 o  label-current
' }! j% R  |6 v0 w% d. o% H
& l7 \, }) T, V' o; c# O1 z  set-default-shape turtles "car"
  z( O1 f: ]  l
+ E# W/ P8 @1 v1 p: ?! c# ?" K  if (num-cars > count roads)2 r( f3 g) `5 o0 j7 L
  [
/ S! z8 p! A. |+ U    user-message (word "There are too many cars for the amount of "/ o5 r+ M; E9 X/ g6 G
                       "road.  Either increase the amount of roads "
# K6 B1 \% C. R) D; P( F# S9 {! g. t                       "by increasing the GRID-SIZE-X or "- x) {$ `) S7 k8 k- I- C
                       "GRID-SIZE-Y sliders, or decrease the "0 E8 m$ X2 [. d
                       "number of cars by lowering the NUMBER slider.\n"
  H; P, ~6 U6 P  E* V/ O& x3 B                       "The setup has stopped.")
. q1 ~6 I* b+ i/ K9 @. o3 a) o    stop3 z; C( u, ~- Q
  ]) n7 T- v% K- v

5 C- O5 W: l; o- F" u  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color- B5 K! J! I3 y' x
  crt num-cars' _8 y# C8 o6 H/ ~2 `5 v$ c% ^- ]7 }4 _
  [
* e8 {! h: H! M: j& {) o    setup-cars6 i2 P; N3 c. M' N
    set-car-color0 i3 b1 `& l, `7 u/ g) ^; `
    record-data! B6 Y- w% W2 S6 F
  ]
8 F! n  [, N: [8 O# f( O4 c  T3 ?7 K: G% r# C
  ;; give the turtles an initial speed
7 a) r$ M3 m% x4 m  t* O* P  ask turtles [ set-car-speed ]
% P% V  p9 _9 Y- i
% ]& N! P; M+ w9 q  reset-ticks
' B* V; s* `  mend
1 K" r1 Z" c( z# E# X) S' E( R  _
4 q" W0 U' ^6 `5 Y9 b1 n" [;; Initialize the global variables to appropriate values
9 q$ }- X$ ]; }% X( {( r0 Dto setup-globals# J3 O8 K  B! l) T% X9 P
  set current-light nobody ;; just for now, since there are no lights yet
! O; @4 q5 R7 ]  set phase 0) L, x# f1 K! F; b6 X
  set num-cars-stopped 0
/ Y) m/ j, D3 A1 Q! {' L  set grid-x-inc world-width / grid-size-x6 \! ?+ Z: N2 k/ T+ y+ Q& p# ^* E" F
  set grid-y-inc world-height / grid-size-y; n% N- k* A( i: G/ s
( p6 N; U6 D8 x; B, J% o: N
  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary7 V. M; N  _6 K  M% N
  set acceleration 0.0991 s' ^, L. H( q6 l- R
end
, y; O! y6 Y; }5 y& W& I4 h2 @# L. k! n8 V8 K0 m% k$ s0 U
;; Make the patches have appropriate colors, set up the roads and intersections agentsets,
7 e3 e, Z. T% N0 ^. l0 b# k;; and initialize the traffic lights to one setting
& ^+ ^5 J  e0 D0 sto setup-patches
4 J9 j$ t% t* o  ;; initialize the patch-owned variables and color the patches to a base-color
, v; G' a& r( ?" L: H% J  ask patches$ \4 a7 a- x2 A4 u1 t
  [
% o, P9 J. r/ B: Z9 x    set intersection? false
7 U! s! n" M' |! ?1 u% H" g    set auto? false
2 J: |  B% Q; x% g    set green-light-up? true
% X! S0 N# ?$ m6 ~! T& x    set my-row -1
0 i1 J! {( r2 r# q, [' @+ z) w    set my-column -18 M% G- h) P1 A' I+ M
    set my-phase -10 m( z1 ^+ ]! ?, |7 w1 O
    set pcolor brown + 31 x) r3 x0 s9 g; y+ z
  ]
, l. \/ q; s! o0 u: H% x- b2 X6 u: _3 v0 k
  ;; initialize the global variables that hold patch agentsets
1 M( r7 F* ?- I2 Q( F3 B& R3 u# R  set roads patches with1 U, @% q) y+ o% }% v" @# k/ ]. `
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or( i, d7 Z- n' I, w* \. f6 ^
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]: |5 }6 l/ i* b& o5 R
  set intersections roads with
( J- Z2 J2 y- E5 C$ h! _6 Y    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and
. E, T/ J; c8 t- y1 ]    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]% k: k3 P+ G& F7 ^
% L; S& ]  j4 @( O
  ask roads [ set pcolor white ]
4 c8 K6 k% c* Q- m    setup-intersections
: o6 T& M( d7 G: H) e. send
- Y) B1 ]  K( S  o其中定义道路的句子,如下所示,是什么意思啊?
% `  P/ \) X( O set roads patches with& I" B) P% `( G5 Z/ J4 |( U5 w& D' {0 k
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
/ |5 s1 M9 o' B: z    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]& F8 h9 D! v. i* A2 m8 v6 C
谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-3-7 11:39 , Processed in 0.016666 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表