yanyanxihua 发表于 2012-6-20 08:59:43

在看例子时有几个问题看不懂

新手,在看netlogo自带的例子时,有几行程序看不懂,希望高手能够指点。
netlogo自带的social science--traffic grid这一例子当中,
globals
[
grid-x-inc               ;; the amount of patches in between two roads in the x direction
grid-y-inc               ;; the amount of patches in between two roads in the y direction
acceleration             ;; the constant that controls how much a car speeds up or slows down by if
                           ;; it is to accelerate or decelerate
phase                  ;; keeps track of the phase
num-cars-stopped         ;; the number of cars that are stopped during a single pass thru the go procedure
current-light            ;; the currently selected light

;; patch agentsets
intersections ;; agentset containing the patches that are intersections
roads         ;; agentset containing the patches that are roads
]

turtles-own
[
speed   ;; the speed of the turtle
up-car?   ;; true if the turtle moves downwards and false if it moves to the right
wait-time ;; the amount of time since the last time a turtle has moved
]

patches-own
[
intersection?   ;; true if the patch is at the intersection of two roads
green-light-up? ;; true if the green light is above the intersection.otherwise, false.
                  ;; false for a non-intersection patches.
my-row          ;; the row of the intersection counting from the upper left corner of the
                  ;; world.-1 for non-intersection patches.
my-column       ;; the column of the intersection counting from the upper left corner of the
                  ;; world.-1 for non-intersection patches.
my-phase      ;; the phase for the intersection.-1 for non-intersection patches.
auto?         ;; whether or not this intersection will switch automatically.
                  ;; false for non-intersection patches.
]


;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

;; Initialize the display by giving the global and patch variables initial values.
;; Create num-cars of turtles if there are enough road patches for one turtle to
;; be created per road patch. Set up the plots.
to setup
ca
setup-globals

;; First we ask the patches to draw themselves and set up a few variables
setup-patches
make-current one-of intersections
label-current

set-default-shape turtles "car"

if (num-cars > count roads)
[
    user-message (word "There are too many cars for the amount of "
                     "road.Either increase the amount of roads "
                     "by increasing the GRID-SIZE-X or "
                     "GRID-SIZE-Y sliders, or decrease the "
                     "number of cars by lowering the NUMBER slider.\n"
                     "The setup has stopped.")
    stop
]

;; Now create the turtles and have each created turtle call the functions setup-cars and set-car-color
crt num-cars
[
    setup-cars
    set-car-color
    record-data
]

;; give the turtles an initial speed
ask turtles [ set-car-speed ]

reset-ticks
end

;; Initialize the global variables to appropriate values
to setup-globals
set current-light nobody ;; just for now, since there are no lights yet
set phase 0
set num-cars-stopped 0
set grid-x-inc world-width / grid-size-x
set grid-y-inc world-height / grid-size-y

;; don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary
set acceleration 0.099
end

;; Make the patches have appropriate colors, set up the roads and intersections agentsets,
;; and initialize the traffic lights to one setting
to setup-patches
;; initialize the patch-owned variables and color the patches to a base-color
ask patches
[
    set intersection? false
    set auto? false
    set green-light-up? true
    set my-row -1
    set my-column -1
    set my-phase -1
    set pcolor brown + 3
]

;; initialize the global variables that hold patch agentsets
set roads patches with
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
set intersections roads with
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) and
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]

ask roads [ set pcolor white ]
    setup-intersections
end
其中定义道路的句子,如下所示,是什么意思啊?
set roads patches with
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
谁能帮我解释一下[(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0)是什么意思吗?
页: [1]
查看完整版本: 在看例子时有几个问题看不懂