设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11580|回复: 0

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

[复制链接]
发表于 2012-6-20 08:59:43 | 显示全部楼层 |阅读模式
新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。" M6 l7 z! u) o
netlogo自带的social science--traffic grid这一例子当中,
" |8 W- A4 n( ?# pglobals
+ _! w) e. S6 v2 l) H; r[1 F3 K. s: j( i/ V
  grid-x-inc               ;; the amount of patches in between two roads in the x direction! \$ {; e0 ^9 j1 Z+ k& s5 F. z6 V
  grid-y-inc               ;; the amount of patches in between two roads in the y direction
6 F% J0 P+ ^+ w: i' `6 K  acceleration             ;; the constant that controls how much a car speeds up or slows down by if9 A, ^0 h& z6 Z) d( b9 l5 s
                           ;; it is to accelerate or decelerate
7 n6 z! y# J2 @  phase                    ;; keeps track of the phase
$ V  D2 e$ e1 ^' Z% w/ C" I0 a" B- G  num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure
* [9 S3 \4 y, X4 A9 `" y1 H  S* v& b  current-light            ;; the currently selected light
' _: D: X. A  \% ^/ C6 u
% F7 w$ t. I' }1 ^" I& Q( p  ;; patch agentsets
7 ~+ O7 F+ }5 |+ K8 s: Z2 n  intersections ;; agentset containing the patches that are intersections0 f8 q: `7 k5 j7 l& U/ n$ G! ~
  roads         ;; agentset containing the patches that are roads
) [! [' N5 M# ?; M$ C, N]
3 a9 U) e. _6 _3 P" X! S3 ?! A; E* ^8 x# ], j2 z) Z  u( E
turtles-own" d# n; l7 E/ K4 s( a9 f
[$ _0 y' g6 f$ b+ f8 v/ j
  speed     ;; the speed of the turtle" h  Z% W- S( ?0 s" h
  up-car?   ;; true if the turtle moves downwards and false if it moves to the right! n$ y: X8 \9 n0 r% [1 i9 f
  wait-time ;; the amount of time since the last time a turtle has moved1 |, i5 _! J( W1 C/ a$ w
]
4 M  y  T" c% j* V7 \0 w0 P9 t
/ W) r; B2 O3 z6 Mpatches-own
" z- |- \1 e) O4 V7 o, T1 G[
. o! N; m( B4 W, m0 A+ a9 `% L6 g  intersection?   ;; true if the patch is at the intersection of two roads
7 h( Q3 [5 U& S/ J+ `4 l; y7 B7 Q  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.+ b2 m% C+ g) {0 g
                  ;; false for a non-intersection patches.) ?7 H% B7 M' d" X& ^
  my-row          ;; the row of the intersection counting from the upper left corner of the, Q' m) c+ x% p6 p
                  ;; world.  -1 for non-intersection patches.2 `' `, z7 t1 J  ]: i: o
  my-column       ;; the column of the intersection counting from the upper left corner of the
$ ~5 d# _" p$ T8 e; K6 W  `                  ;; world.  -1 for non-intersection patches.
) ^! N4 [5 F0 j9 l  my-phase        ;; the phase for the intersection.  -1 for non-intersection patches.5 L' Y. d+ @+ t* I0 d3 i7 l  r
  auto?           ;; whether or not this intersection will switch automatically.
  y- L# H$ I, H/ O, A) a                  ;; false for non-intersection patches.
' n- U1 N  {6 f. Z]% \( U8 Y, C4 U( |
4 _& [! Z# d8 T2 ]9 x; x' u, n  L
2 a! [( b% [1 r/ t/ M
;;;;;;;;;;;;;;;;;;;;;;3 H4 E' _% ?  s1 k$ K
;; Setup Procedures ;;
9 F- b6 [$ p' n* g0 `9 R" J! ~3 }9 };;;;;;;;;;;;;;;;;;;;;;
4 Y; g  ^: e3 x6 ?% K" N0 @: h: q" c* ^
;; Initialize the display by giving the global and patch variables initial values.  ]- X( x( L- [# X9 x$ ]
;; Create num-cars of turtles if there are enough road patches for one turtle to
, w- G# }) n# N/ \;; be created per road patch. Set up the plots.+ Q: A! @. g5 ?# }. {- C
to setup
( B; f0 F7 X' N! S+ V4 L; u  ca$ N* f+ u3 R! b. A; E. L
  setup-globals
+ _6 U( I5 ]( {8 G: l! [% q& f; T9 e3 s
  ;; First we ask the patches to draw themselves and set up a few variables& `# g+ M7 g) w+ O3 y  }) ^8 n0 U& n! Z
  setup-patches  f3 \0 L: v5 c9 I
  make-current one-of intersections
' H- {3 |" a1 B" k4 W0 V/ ~  label-current4 |  W2 ?9 m/ }$ K2 S2 G

  n5 f2 U. u9 Z7 b  set-default-shape turtles "car": r5 k3 M# @8 D
+ I) W1 J- m2 d. K
  if (num-cars > count roads)
3 h; b1 O) d$ N6 S: I! z  [
7 U8 Q& u7 z' p    user-message (word "There are too many cars for the amount of "+ a' T% P4 E* Q& g! V/ D
                       "road.  Either increase the amount of roads "1 W7 N" ]( ^% e
                       "by increasing the GRID-SIZE-X or "
2 V1 V$ p: C) z0 t4 X4 e1 s                       "GRID-SIZE-Y sliders, or decrease the ") |2 r) ]' c! \' }+ S
                       "number of cars by lowering the NUMBER slider.\n"
0 {$ B# @9 i# ]' P6 z                       "The setup has stopped.")0 U. p0 U4 e/ M4 p
    stop* S- |9 T! C4 c1 k" B
  ]
9 [" j+ Q7 s  ?0 l$ m/ M3 |3 n( u' U2 b% d
  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color; a6 V: h6 l1 [; o
  crt num-cars
1 o% v6 D" a3 n  [6 U& f/ s0 i- ^9 _
    setup-cars7 [7 g' U* s9 x. s( N) A0 Y$ q
    set-car-color
/ b' I0 Q) D+ j% l    record-data% V2 q# A7 o  R+ b6 p! s& e. K
  ]" A3 j5 U# A& S6 e5 s0 e
! u) y+ `+ W6 Y! y: I
  ;; give the turtles an initial speed/ ~0 }- k4 R7 ^& E! f
  ask turtles [ set-car-speed ]
4 I6 E8 K% d" C' D9 O' m7 o
. h# d/ |1 x8 ]" M* {1 x2 ~; [( ?& F  reset-ticks6 G# e4 d  ~1 H) p( v& O
end' p/ ?: g# [4 i% w' o4 R+ j. Q
. Q( e* `! Y9 v  E% n! u
;; Initialize the global variables to appropriate values, n  x5 `5 D1 ]8 D
to setup-globals
( K% j% j' g# x6 }- |8 j8 k  set current-light nobody ;; just for now, since there are no lights yet* H: r! }9 ?% k$ t# ~' h* r
  set phase 0; `6 S; n2 v. ~& V$ i/ d
  set num-cars-stopped 0" P$ \* [' W0 C
  set grid-x-inc world-width / grid-size-x* d9 R3 d( L+ P2 e+ F: i" a
  set grid-y-inc world-height / grid-size-y9 z  U' A2 q6 [/ o9 p- O. w
* V+ S6 L6 D6 N* u( j
  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary$ k5 v) i1 O3 N# C" m
  set acceleration 0.099
& v* `5 [# O: d% |* q3 f# c6 t& Vend
# L2 x* ~3 R$ K# J3 `: E) O+ D# a- s; ~5 O: m3 l. e
;; Make the patches have appropriate colors, set up the roads and intersections agentsets,
/ T8 w( B) L: _1 D8 u2 g/ x;; and initialize the traffic lights to one setting2 s% V2 M9 k/ Z! y! v
to setup-patches
& L) q: h2 J% @. s' ]2 }  ;; initialize the patch-owned variables and color the patches to a base-color' k) D" ]2 L8 O" A
  ask patches( Y" ~" j1 C1 E  a$ }
  [3 @8 j9 @2 Z' u6 n% K
    set intersection? false
) y+ Y& B3 M0 n7 G- R    set auto? false
; N( f6 E* e2 Y    set green-light-up? true, p/ C, H+ y% q6 X8 J7 Q
    set my-row -1: ]0 {9 o, U4 y# L3 E
    set my-column -1
4 u* z$ {, v5 m1 X    set my-phase -18 Y- p. g% a2 a" ]8 A! H. H
    set pcolor brown + 33 }5 o9 Y# T) H3 g
  ]3 R; G1 l2 t6 ~2 T" [
: ?8 U1 f- V# e! f) ]/ t. N
  ;; initialize the global variables that hold patch agentsets
  j/ A1 H, n  D5 {  set roads patches with
! v5 a- t; X+ Z0 f; [! \    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or1 Q# \. w* B) `% R5 |
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
+ v! R/ d/ A7 ~  set intersections roads with
# Y3 G) f  [( u7 B/ w! o    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and
; ^4 u% U, ?$ o    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]( M; ~4 i  l0 e3 k" ?

- Q; B" M. q5 p1 J! @! _* i  ask roads [ set pcolor white ]
& B2 r; a  X6 T! `/ {% |- ~    setup-intersections  N) V. j3 I6 [( _6 M4 O' n3 }0 g
end( J' H5 ]' `/ S& u
其中定义道路的句子,如下所示,是什么意思啊?9 g/ q% Q5 D% ]4 \' o* P% m
set roads patches with
4 W3 y8 I2 r: Z! G+ F    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
) a4 ~" b: ^3 S2 N    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]$ C3 ^# s; N4 j" l$ P
谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-5 11:01 , Processed in 0.011391 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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