设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8283|回复: 0

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

[复制链接]
发表于 2012-6-20 08:59:43 | 显示全部楼层 |阅读模式
新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。
4 G- l& ~' o% m: ]5 t0 ynetlogo自带的social science--traffic grid这一例子当中,: g% F8 ]2 i& z
globals
8 E* r. `, j) w/ k[2 }" K- g$ n3 W7 J) S& b
  grid-x-inc               ;; the amount of patches in between two roads in the x direction
! o& S) Q1 ]8 _4 u  grid-y-inc               ;; the amount of patches in between two roads in the y direction
, }3 H0 M5 E1 l# t5 O3 w  acceleration             ;; the constant that controls how much a car speeds up or slows down by if
% n( |; X' D! ~! k5 Z* E                           ;; it is to accelerate or decelerate5 Y0 U$ m, J6 c0 d7 Q
  phase                    ;; keeps track of the phase
4 x# E6 G) r/ N* W: O" F6 ~; m  num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure
* v/ |- W4 A. Z5 ]  current-light            ;; the currently selected light
) B% Q$ f) U& A! S1 ^3 R4 B" O  Y; z: t- d/ G+ Z; z
  ;; patch agentsets
, j1 K. g* Y1 [  intersections ;; agentset containing the patches that are intersections
$ A6 k" o; @' i: s  roads         ;; agentset containing the patches that are roads
0 P/ }0 R; b  L" K# V( a]6 }; |$ F) Y" y( K6 U8 `+ ]' X
4 E( }) n! t1 [# V6 z' v
turtles-own8 T' ]2 P3 f) x, g; R4 f
[
# P3 u, R- n7 F. c& c8 z6 P  speed     ;; the speed of the turtle9 ^" M# S9 ~6 \
  up-car?   ;; true if the turtle moves downwards and false if it moves to the right: _) L: ^- B1 G! U, x$ y
  wait-time ;; the amount of time since the last time a turtle has moved/ L; e0 g% G5 x2 o& w, Q
]8 N1 q6 Y# {, X, u* ?  V% n) G: E
8 w5 n8 M2 o9 _1 W% P8 p
patches-own& Q  p+ q9 B% `9 g5 J1 s2 ]
[- S! j' ?; \9 w) L
  intersection?   ;; true if the patch is at the intersection of two roads. i% [/ u& z  v0 [/ q; k5 A* t7 Q
  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.
1 e6 v) u; w! n$ R# {                  ;; false for a non-intersection patches.
8 h" I0 k' [5 }. r' e" @% x8 B  my-row          ;; the row of the intersection counting from the upper left corner of the& ~+ G' S4 J3 ^5 B6 i
                  ;; world.  -1 for non-intersection patches.& X- R& V# E5 T0 K* z
  my-column       ;; the column of the intersection counting from the upper left corner of the
5 j( k3 v: O  H" v                  ;; world.  -1 for non-intersection patches.. r$ }9 h; g& p% ?; a
  my-phase        ;; the phase for the intersection.  -1 for non-intersection patches.
7 z( h) S6 R. h  auto?           ;; whether or not this intersection will switch automatically.  t" f& C$ A# G& I; @; N
                  ;; false for non-intersection patches.
1 w1 {0 N! U2 r! k, o, D]
+ J/ C' l+ v6 y! s% K  \9 \; n6 i1 d
0 K8 u, r* E% Y$ l' ]
;;;;;;;;;;;;;;;;;;;;;;4 i1 C6 a: _2 f7 Y! J; p- @0 z8 W; S
;; Setup Procedures ;;
, B1 ~% G8 g5 S;;;;;;;;;;;;;;;;;;;;;;
9 u  }4 i; b9 J6 t+ I: i7 r) T! ~0 Y4 G
;; Initialize the display by giving the global and patch variables initial values.' E5 A5 m) B7 u3 V- c. D- M
;; Create num-cars of turtles if there are enough road patches for one turtle to8 C$ x/ \' ?! o2 m7 g1 [; s
;; be created per road patch. Set up the plots.7 \3 _0 U1 \) V
to setup) p: o$ |5 W# H5 B/ x  j
  ca
( C3 P9 w4 Q4 u. t- w  setup-globals
' F* e- q( h3 p: F+ ^
! o) s4 a3 D* J: `2 E  ;; First we ask the patches to draw themselves and set up a few variables; |/ U. H: r  @/ ?5 R" O
  setup-patches) x# [8 t1 J; u/ S) C% E' c7 {( c
  make-current one-of intersections! u; W* Y9 B; d1 w- r/ Z3 h
  label-current
& r9 Q: X/ h! O( D* h& y
5 Q5 L( _9 [; U! G$ h- i' A# \  set-default-shape turtles "car"3 W* M' U7 t; {# t0 ?

& j: _2 s( M1 {* r  if (num-cars > count roads). J' v( v7 o' l# [
  [1 G1 P1 b- b: j0 b) _
    user-message (word "There are too many cars for the amount of "
, E. l- E4 ?6 C, f2 Z5 r                       "road.  Either increase the amount of roads "
2 H# |1 A$ h& S, f* T" [                       "by increasing the GRID-SIZE-X or "9 B+ s# E  F; L* h" i( C; B
                       "GRID-SIZE-Y sliders, or decrease the "& v* ?4 \% g, D' s7 T* ^/ f
                       "number of cars by lowering the NUMBER slider.\n"- Z2 I4 G8 C: I( j
                       "The setup has stopped.")
- ], e( m) X4 q    stop
# n5 c" t& S5 `  e  O  ]; y0 Y% Q1 S3 V3 ~3 a7 M
7 \( R8 s; k! [5 x7 t( K: U; v' h
  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color- H5 `: p$ J- K1 ?0 j
  crt num-cars
9 Q+ q8 P. U, m$ ~, K  [
( m; _$ I- M, q    setup-cars: [  n  e8 U/ i3 `
    set-car-color; S, }+ t( L0 F: ^! A) L6 K
    record-data
& \& k. C7 M7 ]6 ^& I0 c  ]
. u$ i7 d, |9 F" y9 C- U+ q" a$ h3 M
  ;; give the turtles an initial speed
# J8 i7 G8 m" p: F+ v- L7 o. p7 M1 }  ask turtles [ set-car-speed ]
& A$ W0 ~& C6 o4 I" v$ T0 v6 k& X1 a( D) u9 H
  reset-ticks. q' [: x/ S6 }: B
end
* d! W. q) g1 ?2 I* W- |
& D+ l( \# {: V0 @0 I;; Initialize the global variables to appropriate values
( }4 }3 v; W- |" c/ o% Q( J0 B8 mto setup-globals
' i7 j# X4 @3 U  m0 V$ a; Z$ n; z  `, W  set current-light nobody ;; just for now, since there are no lights yet
3 l4 g, a: Q' N7 y( D  set phase 01 a; S* I- g% |  x
  set num-cars-stopped 0$ L! y' q' K4 N
  set grid-x-inc world-width / grid-size-x1 O4 P2 ?& _5 l1 A' e. G
  set grid-y-inc world-height / grid-size-y2 u2 X0 i1 \+ |) a6 a5 ?

8 P8 S& W7 }( }5 x/ f  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary
; L7 t' s: P( Q- h" @2 F$ [  d  set acceleration 0.099/ Q! D5 T9 V" e6 p& V9 w" `
end
5 F5 w& i) ~- ~
+ }! r  j+ ?& }1 i; n  b5 [;; Make the patches have appropriate colors, set up the roads and intersections agentsets,
. ?9 q3 |$ A5 M;; and initialize the traffic lights to one setting: F6 M- c" _; S( C  Q! @
to setup-patches
- n; i& p3 o  v/ R$ X7 S: S  ;; initialize the patch-owned variables and color the patches to a base-color
3 `: T: P+ F8 `% y  ask patches
9 R: D  E! m* v7 t3 w! b9 k  [$ ?: b! ~( z6 B/ l. Y
    set intersection? false
9 s, ~- b' n' I6 u# T    set auto? false* t) W. t  Q$ z
    set green-light-up? true
& d# o9 E* K( X' b9 h7 d- K: ]    set my-row -1
3 k# g; T( ~% [2 _1 ?    set my-column -1
0 i0 K8 g, Z' v1 y6 F% ?& v    set my-phase -1" \7 ]8 w) p6 E8 o4 z- D- d9 W
    set pcolor brown + 3* D* t1 [6 f) @: E1 r9 b( I
  ]& Y8 b& J! x/ ?# ?0 R
$ }2 w' H& J$ l& z6 t* T1 J2 k
  ;; initialize the global variables that hold patch agentsets
2 G) X4 P$ D1 E5 P) {$ [  set roads patches with
6 {8 w& n9 B7 ^; k! a+ G4 Y    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or3 @% Q8 U/ W0 I- Q- T5 @! Y
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
8 b+ h7 k* [( y( l7 y  set intersections roads with
/ N- l( I5 f5 U    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and
2 u8 m3 B3 I2 d: C8 |    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
1 C* \0 I4 m! Z3 |; T( D
& K$ b. u) c- b! G5 f4 W# O9 i( r  ask roads [ set pcolor white ]9 F0 @- R- `  M8 K5 W' ]
    setup-intersections
  A% r1 M3 s" N) ~end' d2 u7 G4 N# C+ b! ^
其中定义道路的句子,如下所示,是什么意思啊?
9 N; [" E/ r6 u7 Y! d set roads patches with& w5 I- X' ]$ T* G- ^! M' r
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or/ F8 X* v- @. q4 W. G
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
  E9 @+ g+ Y; z6 Y谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-10 09:39 , Processed in 0.016668 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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