设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8803|回复: 0

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

[复制链接]
发表于 2012-6-20 08:59:43 | 显示全部楼层 |阅读模式
新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。
. o4 g0 d$ C; I8 M2 Y: _netlogo自带的social science--traffic grid这一例子当中,& T. n: t7 R# ], [  K- ^; c* v
globals
8 n9 Z& g* N9 X7 k7 Q[* c/ w1 n3 k- A
  grid-x-inc               ;; the amount of patches in between two roads in the x direction
/ c0 P8 m& R* U' I; q* D# u) \  grid-y-inc               ;; the amount of patches in between two roads in the y direction
" J, V5 `( P) A6 Q- @5 J# V7 `  acceleration             ;; the constant that controls how much a car speeds up or slows down by if
% j, V0 e, \4 M                           ;; it is to accelerate or decelerate
% M  L3 W$ R9 P) I  phase                    ;; keeps track of the phase! r$ R1 ?8 |  H. ^' U$ X% {" @
  num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure& }3 V6 R' i" |, @+ y
  current-light            ;; the currently selected light5 u( `! u) w* N& D- I
1 A  p/ a$ T- K* @
  ;; patch agentsets
3 k% s/ O* o% q" v( j% U" T$ c  intersections ;; agentset containing the patches that are intersections8 S. n# I7 F7 R. w, M/ W
  roads         ;; agentset containing the patches that are roads
7 [2 _2 r2 e' N( {, M" X5 F7 \]
$ k4 p3 H4 w- N" j, z
- N/ b9 B1 c- P. X+ [; {turtles-own3 a+ V% R( p8 o8 Q& C  s
[( D0 U/ h) S! K9 l& I* |
  speed     ;; the speed of the turtle9 |) [! U$ q! O7 ]
  up-car?   ;; true if the turtle moves downwards and false if it moves to the right
3 D5 J4 N3 {  J* ~' l2 U. B. ^  wait-time ;; the amount of time since the last time a turtle has moved
  E' s# f( O5 F' S9 ^]  J( k: f. i3 V3 ^

: M" Z; L: Y. o9 M& U' G* ^patches-own2 a! w; ]' G4 y8 e
[
, B* ?. M$ H* h  intersection?   ;; true if the patch is at the intersection of two roads
# w$ }6 o8 \8 Q  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.
; f( v, W& y5 s7 y! I% {  \                  ;; false for a non-intersection patches.2 s* A  P3 X* g$ T& N, A
  my-row          ;; the row of the intersection counting from the upper left corner of the
( E# o6 ^1 v! M& r7 ~) }/ ]& d                  ;; world.  -1 for non-intersection patches.- k3 O' N9 `  ?% G: q2 c3 L% r
  my-column       ;; the column of the intersection counting from the upper left corner of the
7 X$ S, v3 O# w                  ;; world.  -1 for non-intersection patches.6 [! w, U4 o6 F1 P0 z
  my-phase        ;; the phase for the intersection.  -1 for non-intersection patches.
; w/ M% I! B2 f1 |" |  auto?           ;; whether or not this intersection will switch automatically.+ U7 \6 `) z% p0 V# s* X* \. D1 K- u; S
                  ;; false for non-intersection patches.
- A6 O' q& [; H3 Q2 {]2 \( Y/ J0 M+ f' }" ~& _
1 v9 O: M# Q' i" g) h3 r! h% `9 S

. h* M/ p$ I' y;;;;;;;;;;;;;;;;;;;;;;
9 Y" K% k2 g  I* J# J;; Setup Procedures ;;
7 a+ a, ~( h% [+ u;;;;;;;;;;;;;;;;;;;;;;
" w* V5 b& X1 \" ?3 l
4 B1 E, z2 q2 v* {, R3 I7 p5 ~;; Initialize the display by giving the global and patch variables initial values.
4 g4 G- M4 u6 x1 o* |+ O4 d;; Create num-cars of turtles if there are enough road patches for one turtle to: r# B5 X, Z* J1 P* {2 t+ \5 \5 S3 c
;; be created per road patch. Set up the plots.& h0 K* _" P: l' F8 N
to setup  \: S3 [! ^  f5 s$ i
  ca
* Y1 X+ H" b4 S( \0 o) p* z  setup-globals
* K' \8 p! C. b' p2 e0 N* i' w
$ |* E2 m7 o7 [; A" n  ;; First we ask the patches to draw themselves and set up a few variables! }* Y5 a0 L( f" g
  setup-patches* L& R/ z  t: e. a
  make-current one-of intersections
, J$ j0 T4 v3 N  label-current
" d3 P7 a' S7 _  y9 ?! l0 Y
/ A) _/ G; f# }& u4 U  set-default-shape turtles "car"6 p! t' j3 F% v- i
! U8 Y* |' e2 B0 W
  if (num-cars > count roads)$ e& M! b0 N/ I" J& S
  [
, ^3 ^7 V2 h9 A% y) f    user-message (word "There are too many cars for the amount of "
- P' U; k& Y0 Y  t% d! k3 T& R" W                       "road.  Either increase the amount of roads "" L; ]8 f! ]( Y" U- v- r& b( Q4 f
                       "by increasing the GRID-SIZE-X or "
: X( o" c6 _  W6 y                       "GRID-SIZE-Y sliders, or decrease the "3 d- I* l' G9 _
                       "number of cars by lowering the NUMBER slider.\n"
; e4 D. o' `3 y" \8 [$ c" o                       "The setup has stopped.")+ H- z8 V3 @. n) Q: h
    stop3 U: c) b3 j0 v! q' v( {3 M+ W
  ]
( f6 Y4 z& Z; [  N* c# c! n" M+ G! L) W$ G
  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color
# Z7 ?, O% G* o+ B; Y! h3 O; c  crt num-cars
- M# T) _# q( s/ y4 k* T" Q  [0 h* H+ A6 K( m; t  F$ P. w" I
    setup-cars: W' X. A0 k3 I( A
    set-car-color. V1 y! {5 Y  O5 G, \( R
    record-data' a4 M% o" h2 V7 O, H+ A
  ]* h6 D0 T  c% W3 F9 V- o" b* i
, t. y+ f4 @) ?' v0 K
  ;; give the turtles an initial speed
. z8 I4 b3 h, K: K) t  Z  ask turtles [ set-car-speed ]. M8 O4 C! A' G) c5 F+ Y( I

& B4 I8 s' N1 E. f+ B+ O* _! S7 U  reset-ticks) r9 }  a. u" C
end
! o/ R2 x  u# x9 I6 B3 M  K  d. A+ ^9 |0 h0 ?! y' m
;; Initialize the global variables to appropriate values1 v1 ~$ d4 a% \2 u6 o7 ]0 w
to setup-globals
, B+ q7 \) h' N! {* U+ |7 a  set current-light nobody ;; just for now, since there are no lights yet
0 k- }0 o. X& q' a+ Q  set phase 0* J4 P8 |9 L+ `* @
  set num-cars-stopped 0) ]) h& F' r  G, v
  set grid-x-inc world-width / grid-size-x
0 B: [/ ~7 j" R# I) K, [  set grid-y-inc world-height / grid-size-y
* R) ?" r6 r# y9 Y; I5 F. p
" P( R# V7 L1 O& f: @0 @  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary; m1 }& S, ?* |) ^' S5 n
  set acceleration 0.099
$ t% j4 q7 l3 s. ~end0 H2 \1 {5 ^; s& A0 N& \0 K1 p

: W/ G2 V8 s* z4 y: T0 M;; Make the patches have appropriate colors, set up the roads and intersections agentsets,; w0 z; J: k- T7 W9 Q
;; and initialize the traffic lights to one setting
2 F. p* ^  ]: T0 R. P, X% Mto setup-patches: ~% p7 n" L3 g. c
  ;; initialize the patch-owned variables and color the patches to a base-color
0 W0 A  t/ E' T7 q  ask patches4 `/ {* H3 Y; O' @% e' ?; \
  [
: x; b8 W. D3 }    set intersection? false
3 X2 o$ ]; X; l' I7 F    set auto? false+ E! g4 S+ E" P; m+ o+ U
    set green-light-up? true
% [$ v& c, d5 n& U2 ~    set my-row -1
* G& B2 a; |  L- \    set my-column -1, w  m' ?" C% z2 F/ ]  ^6 y5 ]: ?
    set my-phase -1- ?8 Q. g, O4 C+ X
    set pcolor brown + 3- f+ G, k6 _* y
  ], m6 N: e& _' g8 _
, p' ^# H! U1 g( m" I9 N( ^
  ;; initialize the global variables that hold patch agentsets
- J% S  Y$ n- c7 C  set roads patches with
. O, l; L/ I3 @5 n7 l    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
+ l; ~( T  F, W    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
1 E- F& F" x+ `# b+ E4 l* X8 p& E  set intersections roads with; R7 v( j3 i/ P+ _
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and+ r, I8 z1 [+ I" g3 t( ~
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
) M9 H: u& H% J8 w% J  z3 O- M& S  k! D
  ask roads [ set pcolor white ]
! \3 I# e, {0 S( I' F- H    setup-intersections' A% k1 o4 Q. A2 L* U& b" @: e) e
end( b% y* {5 D# u/ C; R' }8 S, R
其中定义道路的句子,如下所示,是什么意思啊?2 F( k7 C4 o' C( q
set roads patches with
1 W; c2 v. ?+ x    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or" n' i, c6 F$ \
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]) t1 d- L, V& q" k! z7 g* V
谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 15:10 , Processed in 0.020128 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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