设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6295|回复: 0

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

[复制链接]
发表于 2012-6-20 08:59:43 | 显示全部楼层 |阅读模式
新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。
; w" r9 x" z! G* Z, c- V" d+ K4 ^5 h1 Snetlogo自带的social science--traffic grid这一例子当中,+ f, L! j0 |" ^$ ^0 z0 j& u5 p
globals4 \8 J" b/ R1 o6 Q7 }
[4 v, r: T9 e6 [. I/ K
  grid-x-inc               ;; the amount of patches in between two roads in the x direction
$ O6 \( W6 B# E$ `+ T8 f. S3 k  grid-y-inc               ;; the amount of patches in between two roads in the y direction
% a) t' c6 o8 n4 Z, H  acceleration             ;; the constant that controls how much a car speeds up or slows down by if
9 J2 ^, P6 c- G5 h" a/ x0 {                           ;; it is to accelerate or decelerate5 _$ V- j* ]4 J) w" Q! {
  phase                    ;; keeps track of the phase5 {' f; R% G9 O, f
  num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure3 f$ Q  ^  F$ E, P0 P' w# j
  current-light            ;; the currently selected light
( F' d: ]0 \4 O3 F. p+ N3 f0 A6 u9 R
  ;; patch agentsets. G* l1 ^9 L- ~+ u- b
  intersections ;; agentset containing the patches that are intersections7 E! M0 ?' j) f" o
  roads         ;; agentset containing the patches that are roads
; H  M! K; G( E]
3 O. Z6 n: \  J7 U% h/ k. W: u
% w" g# ^! x0 `, zturtles-own
  o; R' i' \$ y; K[
6 N6 t4 A! Z6 f8 E7 j$ J: Q  speed     ;; the speed of the turtle
/ J$ n: J/ d/ l; V) ^  up-car?   ;; true if the turtle moves downwards and false if it moves to the right1 P  A' v4 p; P, h
  wait-time ;; the amount of time since the last time a turtle has moved" z% _! e( p! @' |2 a7 F
]  h- \; A8 P* x, t! D$ ~
& {: A5 ]/ q% I+ r' h
patches-own, l5 c/ O: I4 J* x4 ^: i
[- }8 \( ]# L  C
  intersection?   ;; true if the patch is at the intersection of two roads. U  [( I% {/ G% f- ~* C
  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.
3 E2 D. D9 h: A9 F/ c                  ;; false for a non-intersection patches.
4 ?: @0 S/ B6 b- S  my-row          ;; the row of the intersection counting from the upper left corner of the( i4 R, m: I5 O9 z
                  ;; world.  -1 for non-intersection patches.4 x/ n/ a9 W9 }
  my-column       ;; the column of the intersection counting from the upper left corner of the
& I/ _  q9 H- G, U' u                  ;; world.  -1 for non-intersection patches.
# T" g( ?7 E8 ^" |& u4 w  my-phase        ;; the phase for the intersection.  -1 for non-intersection patches.% R: E7 O* k- t# T
  auto?           ;; whether or not this intersection will switch automatically.
: w9 Q8 k) v" g, o3 S! }                  ;; false for non-intersection patches.
; E0 ~' [$ @" {) m( V]
6 f2 t. R+ b  h
/ a5 ^$ E5 ~  z- i, V# x2 l, Q, [+ p# ?- j4 R5 W
;;;;;;;;;;;;;;;;;;;;;;
% y' ~, s* @! z$ ^/ u& d6 y;; Setup Procedures ;;
$ g" B/ T- G  P;;;;;;;;;;;;;;;;;;;;;;
5 W" R0 W1 K3 ?8 _  U* r" K+ s7 ^- |8 v& O6 W
;; Initialize the display by giving the global and patch variables initial values.
! {! K! B* o, L  t;; Create num-cars of turtles if there are enough road patches for one turtle to
2 V6 l6 A# m2 ]6 p4 f! C0 q7 X;; be created per road patch. Set up the plots.& e$ V  c( e6 r( w) J! r
to setup' c. q+ P9 K- y1 X6 w
  ca$ ]2 ]( w+ \7 b2 z
  setup-globals2 _: T2 g: h; G% v: `9 F9 q
) G" K$ l( n) W: u7 L7 b
  ;; First we ask the patches to draw themselves and set up a few variables
/ b5 l# {% y; `& l; I* B* I  setup-patches! Z2 {* O  V) e
  make-current one-of intersections5 [5 I0 w  ]( r8 S* a" L% P
  label-current
( a1 r  ?, i' l; V
+ N  Z$ ]- n* r7 z  set-default-shape turtles "car"
: t. S+ X; T" s9 u% s3 ]+ E# s$ `( Y/ I" }3 A
  if (num-cars > count roads)
- l% G3 ]; G, o) y/ ]8 G  [& s3 Y+ _! t1 L4 t4 E
    user-message (word "There are too many cars for the amount of ". |+ K' I/ `+ n) h% \
                       "road.  Either increase the amount of roads "
  c8 D8 b6 U# j5 N" `7 \& R2 @# ?                       "by increasing the GRID-SIZE-X or "0 D/ g8 F+ V3 I& e4 Y+ Y
                       "GRID-SIZE-Y sliders, or decrease the "1 e) ?6 R0 P1 Y' x  G. H" ^, q
                       "number of cars by lowering the NUMBER slider.\n") l* ]: Z+ g" p5 L  k
                       "The setup has stopped.")
, {; i% \  `( T; a    stop" G& B. r' U# `% o" ^5 F$ A
  ]3 z; M5 h3 T% H( O, Z: N/ [
- d! `, T8 S: T/ U- C1 }
  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color
9 Z/ l) h: E1 _7 B8 V# f  crt num-cars8 v' B9 o6 G0 }# J, U' M
  [) M4 y9 [/ Q/ S
    setup-cars
9 H4 {9 j- \8 u, ?6 z3 _    set-car-color
0 ^# `0 F# B1 R, S- n) l3 D! K    record-data7 S" w3 S% f  T; E2 ?
  ]
+ k. B& O; `& Z% U7 m7 `+ s+ [
4 Y2 c  [1 r' a# A( v  ;; give the turtles an initial speed
- i9 m3 s! U+ b  ask turtles [ set-car-speed ]# O5 f4 l% {* b* n1 e! G* r2 F

: X1 E# [# x, _4 l  reset-ticks! a2 U6 S5 C8 K# R. Y
end/ V4 c& j% [8 N0 u: y

; O3 X& r- h% S' M7 m;; Initialize the global variables to appropriate values4 W* @# l! n# V9 z2 D* ?3 B
to setup-globals- Z' T* P  F8 u$ \, |8 q
  set current-light nobody ;; just for now, since there are no lights yet$ k, P5 k; A, X& n4 A4 i6 G' b
  set phase 0
# X% O5 M, P% ]# Y! J' e  set num-cars-stopped 07 l6 n9 n( I: c- n$ q
  set grid-x-inc world-width / grid-size-x
2 b  @4 F7 ^9 E2 r! ^  set grid-y-inc world-height / grid-size-y- P7 p2 g& q* I' S2 z

4 }/ ^$ X- D0 x, J# M& _4 P! W( L  a* q  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary
! A9 Q6 m" E5 V  q( q. c  set acceleration 0.099
6 \. l" N, W7 k. n& {# W# I- Qend
7 S/ Q, p& \! V& q1 @
& @3 s1 }) @: K8 X, m# o6 v;; Make the patches have appropriate colors, set up the roads and intersections agentsets,
8 v7 J. }% ^( x" A' a6 Q* };; and initialize the traffic lights to one setting
1 F' U* r7 l) W3 f# X3 G2 n9 fto setup-patches
" D3 \! q! Y, y2 M" Z* `0 h  ;; initialize the patch-owned variables and color the patches to a base-color3 v5 ?2 u# F4 `. |2 v
  ask patches
" m4 h0 Z( c# {' M3 S  [
5 ?7 ?/ `) e+ g% R) A3 c    set intersection? false
& O/ p5 h6 T5 y9 W* p0 T+ S    set auto? false
- u2 X/ j$ M' K% |; o3 n    set green-light-up? true9 A! [) q5 s  `( E3 ?
    set my-row -1. D0 a4 ?5 K8 n: m# e% e
    set my-column -1
6 ^( z% R- ?& y& ^2 z8 ~; `7 Y    set my-phase -10 Q# l) V" t( u) Q
    set pcolor brown + 3
) N1 G# c1 U. h' }1 `  ]( Z$ L& V* v2 z4 k7 O9 G5 o- S

3 @: k& }- r9 q$ h; B2 ~  ;; initialize the global variables that hold patch agentsets
+ `$ t3 @  [: i) {  set roads patches with% ^% d# x7 }; X* _3 T
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or9 o! \, F- n4 \8 [
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
# J/ {3 k- |( K+ a' F+ e2 O  set intersections roads with
9 z* V4 f* e2 D! |1 ~2 C3 }    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and
% `3 o) i. g* A/ ~0 R    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]6 w+ T: L  |1 q, a7 M
: Z2 Z& [( P$ y3 k) E2 z
  ask roads [ set pcolor white ]
% i  w: J8 l3 R+ }    setup-intersections( |: D- a0 ?) l' s5 [
end7 D' `; I9 ?2 t& c
其中定义道路的句子,如下所示,是什么意思啊?
) h% u1 ^4 I  U. p3 G4 U set roads patches with& Q6 _- F  V2 X0 k3 @) M
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
! z; c# I+ B1 b* k# P6 ~    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]7 @8 R' L2 A5 D6 t% O1 d7 o. A
谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-1 10:52 , Processed in 0.018460 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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