设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9632|回复: 0

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

[复制链接]
发表于 2012-6-20 08:59:43 | 显示全部楼层 |阅读模式
新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。
1 l  ]8 p$ S. G/ @netlogo自带的social science--traffic grid这一例子当中,
1 W) s) T1 b; B' `  |globals
; `' w+ P! e  W$ Z# ~[' [9 C+ u9 ^# R4 I2 |
  grid-x-inc               ;; the amount of patches in between two roads in the x direction% F9 i/ _# [# X: N# k5 I% l8 m
  grid-y-inc               ;; the amount of patches in between two roads in the y direction
# k9 p8 T8 \1 t3 V0 o( B! W- a. B0 z  acceleration             ;; the constant that controls how much a car speeds up or slows down by if+ K1 a1 w3 ~) ]9 V; s
                           ;; it is to accelerate or decelerate: `& w6 E" H9 f. [
  phase                    ;; keeps track of the phase! P+ B* j5 j1 R
  num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure
% N9 C* k; Q4 r! Q5 c; i% S% U. m  current-light            ;; the currently selected light
9 `0 v8 |$ j' N6 G' |; n3 i1 f
9 @- e/ e9 x! A7 q& \9 v+ j  ;; patch agentsets
+ l7 Y: j6 z7 o8 p  x, F  intersections ;; agentset containing the patches that are intersections
. }) w9 [- [" D+ v0 V- F  roads         ;; agentset containing the patches that are roads- n) @9 w' U9 ^9 N: t
]
0 X7 ~7 _$ K, M9 }2 `+ U9 z/ ]
0 x) U# }) V5 k" U7 K8 d& s) \turtles-own
5 q) w9 {- l! l1 l4 G[& z: w; J9 c$ j9 a" M
  speed     ;; the speed of the turtle
! v) W; q  E1 g1 O  up-car?   ;; true if the turtle moves downwards and false if it moves to the right) L# D) j5 V% b* ?9 U" k
  wait-time ;; the amount of time since the last time a turtle has moved: `3 h9 ^  \; ^" z
]9 A' [/ Y7 l9 {, L3 ~
) e+ I9 F/ r5 X  Q! ~& J
patches-own
7 d7 [* v/ O2 X, u" j  }[
8 u) n4 ~' M( v, O. v  intersection?   ;; true if the patch is at the intersection of two roads, N. Q: H: Z# J0 M: H, n
  green-light-up? ;; true if the green light is above the intersection.  otherwise, false.
/ q: G4 U8 w0 {% f$ E$ T$ G# c                  ;; false for a non-intersection patches.
7 Z% n! h5 m$ i4 ^1 w7 @( T% z  my-row          ;; the row of the intersection counting from the upper left corner of the
5 V: S5 t' ^& q1 o2 U, w                  ;; world.  -1 for non-intersection patches.
; Q  ]) L6 Q- g+ L& ~' h8 Z  my-column       ;; the column of the intersection counting from the upper left corner of the
2 |" V# `) W* d) f, [' s0 L                  ;; world.  -1 for non-intersection patches.- }9 e7 }. s: F& O; z1 u9 D
  my-phase        ;; the phase for the intersection.  -1 for non-intersection patches.
, c$ m4 h3 e3 h/ `, s4 @* V  auto?           ;; whether or not this intersection will switch automatically.* _  _; s1 b0 s8 P8 W0 U7 ?
                  ;; false for non-intersection patches.2 P. D; F  D) F& u6 g. I
]
/ k/ p: i/ h1 i) N/ D6 b( d7 m0 o. V  u$ u0 T+ Y7 e5 R* W

& y" w. W! x# `1 @# G+ k; z;;;;;;;;;;;;;;;;;;;;;;
9 F, n" f/ s& ?$ g' T2 T: ~3 c;; Setup Procedures ;;
) c5 f( _2 _( H& ];;;;;;;;;;;;;;;;;;;;;;
. h2 A8 z3 z0 o
1 y6 O& _0 d6 i;; Initialize the display by giving the global and patch variables initial values.
4 v6 v/ d( U$ }7 J* H3 ?;; Create num-cars of turtles if there are enough road patches for one turtle to# w' w1 j, m- ?
;; be created per road patch. Set up the plots.* J3 g0 p, a4 ^0 p5 k2 I" w
to setup
; |: w$ v8 O+ w! }3 d  ca1 j1 s* X+ r  ^
  setup-globals) o2 _$ {; X% f7 Q
: k7 ~+ e( ^$ \* ]4 i
  ;; First we ask the patches to draw themselves and set up a few variables0 W  L7 _& y/ m  {) Z
  setup-patches* G6 p) ?, b- o' C/ N9 k5 C. g
  make-current one-of intersections
5 ?3 X4 u  w: z3 }  label-current
6 k4 {0 C, L5 K) Z+ @. ]( N/ {
/ }( P' V  \, x# {+ ~  set-default-shape turtles "car"
1 F* k8 ~5 Q3 O% V$ ~! o" y3 D$ [5 c
" d9 U9 q3 O  N  if (num-cars > count roads)' Q. o5 }4 F( }, u+ }  Y! M
  [
* v; }# l1 V- M: l3 D    user-message (word "There are too many cars for the amount of "
& {& m( E6 T+ V) r6 i                       "road.  Either increase the amount of roads ": d! @# R+ l1 G. z$ g& D
                       "by increasing the GRID-SIZE-X or "6 C: }3 H* X% I- @. r/ V* z% H0 p# @
                       "GRID-SIZE-Y sliders, or decrease the "; F0 G' W2 I" j. `
                       "number of cars by lowering the NUMBER slider.\n"( H! l2 B# K9 T2 ?/ o- @3 Q6 }
                       "The setup has stopped.")4 a+ X& |% F1 V8 C1 s7 g
    stop# J+ k& T# e5 l7 P7 a
  ]
1 v+ R, i8 s5 Y3 O0 D
" Z: P* e7 B- j" c( J4 [1 h  ;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color7 K2 i2 e0 u( M& p
  crt num-cars
$ [4 t* R$ n# f9 `: D1 n  [' b0 K9 w6 W+ J0 _
    setup-cars8 E0 T: i( J! f( U! H1 y
    set-car-color$ D3 }5 N# `$ b/ K+ r) s
    record-data
- O% r! Q$ J4 i  ]8 a% Y9 u7 \+ [. m' `5 [% r, V6 h
; a4 M# ~7 j" B7 H& k, {
  ;; give the turtles an initial speed
" Y$ g& S# V6 B4 m  ask turtles [ set-car-speed ]  ]7 q( u' E- T2 \5 @
4 K4 I+ [5 j/ i. [
  reset-ticks
# ?  _5 z( B; ?! p: [' Oend
/ W" f6 C8 F: v! |6 h' J8 G. r/ W1 g6 g) n: h3 N8 N
;; Initialize the global variables to appropriate values
0 j0 r" E3 H0 k0 ?( xto setup-globals
$ I# `% Y- j/ ~- v: |+ d% S" A" p$ o  set current-light nobody ;; just for now, since there are no lights yet  X2 @. g/ ~5 I$ z# t& C" B
  set phase 0
. E$ I6 o! f' j; T  set num-cars-stopped 0" }5 Q' r) j8 F5 \: T
  set grid-x-inc world-width / grid-size-x
% u1 f! h8 t1 |# _' R/ d  set grid-y-inc world-height / grid-size-y
6 E; n% ~! _) j9 l8 @+ Q  Y: t
) a1 r' }# [  _2 u  ;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary3 `. p  o: |! ]9 ]& b: `
  set acceleration 0.099  i7 `  m  O0 q/ y; @* D
end+ ?. ~7 q4 c  D; T9 p+ n! q. j. M

4 h- f) I3 |; |" ?! w4 T5 E;; Make the patches have appropriate colors, set up the roads and intersections agentsets,
, n: _) J5 O6 V& o0 B, R7 U9 c;; and initialize the traffic lights to one setting
* h/ \& `0 E' o8 q5 v6 h5 Pto setup-patches
! k4 @" Q9 |  h  ;; initialize the patch-owned variables and color the patches to a base-color
0 j: Q& U7 P& X- N  ask patches
6 r6 N$ _( U9 q, a  [: B& J' w4 e6 @! }" L  T5 ]  v
    set intersection? false
. b& D2 X3 o! @# P, ?2 c, z    set auto? false
; r3 ^) ~9 q) m6 x) s- X" _! `0 y0 j    set green-light-up? true
6 J( A0 y, I# R: C    set my-row -1
! {2 b* M( d' f    set my-column -10 {( [- ]1 B$ _$ }5 w
    set my-phase -1
3 p$ N9 G% y8 U( @0 m' S8 x    set pcolor brown + 3: n6 R/ Z# N# I3 I6 n
  ]. V  G  L. |8 a- b" V

4 g. i6 P3 d0 [& I* j9 b  ;; initialize the global variables that hold patch agentsets
# ^% F9 L6 w- U) f: q  Q  set roads patches with& c2 J7 k, `9 Y% O
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
4 A& a  W1 H: S' E2 X    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]. C9 }2 x; V$ ^/ g% q" ?
  set intersections roads with" r# n: }6 j, S
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and
0 R7 [2 y% X3 C9 f' A9 X    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]) ?. n- }; b4 a: E

& [$ w% e2 T. Q) a5 j+ ~( |/ \  ask roads [ set pcolor white ]
- o; e, ]/ s2 j% l. l: ^    setup-intersections
- {' t; l' d  i% Y# o$ [" ?- B; Kend6 F4 M) d! F# }# }
其中定义道路的句子,如下所示,是什么意思啊?
: b9 E) y  r. ^9 O set roads patches with
7 W+ Y! G: A& T6 w! x    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
: z2 Y3 V2 E* h, D    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]8 _$ N  A; A5 H, ]
谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-24 17:27 , Processed in 0.015948 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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