【发布时间】:2020-05-28 16:31:56
【问题描述】:
当我运行以下代码时,我在代码底部不断收到此错误消息(DISTANCE 预期输入是代理,但得到的是代理集(代理集,16 个补丁)。):
globals
[
x-grid-size ;; Global variable for inter-city grid-sizing in the x direction
y-grid-size ;; Global variable for inter-city grid-sizing in the y-direction
grid-x-inc ;; Global variable for inter-city street spacing in x-direction
grid-y-inc ;; Global variable for inter-city street spacing in y-direction
roads ;; Global variable for inter-city road network
outer-roads ;; Global variable for outer-city road network
a-station
]
breed [inter-buildings inter-building] ;; Inter-city buildings such as office, retail, business, apartments, etc.
breed [outer-buildings outer-building] ;; Outer-city buildings such as residential, reatail, apartments, etc.
breed [AVs AV]
AVs-own
[
goal
trip-status ;; (0 = heading to station, 1 = pick-up passenger from station, 2 = heading to drop-off point)
destination ;;
]
patches-own
[
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.
]
to setup
clear-all
setup-globals ;; Command for setting up and initializing the global variables
setup-patches ;; Command for setting up the patches for the inter-city and outer-city zones of simulation
;;setup-building-infras ;; Command for setting up the building infrastructure on approp. patches
if show-buildings? ;; if the show-building switch is true then building infras will be shown
[
create-inter-buildings Inter-City_Density ;; Creating the inter-city building density
[
set heading 0
set shape "square"
set size (random 0.5) + 1
set color grey
move-to one-of patches with [pcolor != white] ;; if building is on the road, move it to patch that isn't white
setxy (-25 + random-float 50) (-25 + random-float 50) ;; Set position building infras anywhere ranging from -25 to 25 for x- and y-directions
ask inter-buildings
[
if (pcolor = white) ;; if building infras. still lands on road move to patch that isn't white in color
[
move-to one-of patches with [pcolor != white]
]
if (pcolor = red)
[
move-to one-of patches with [pcolor = 96]
]
ifelse (pcolor = white)
[
move-to one-of patches with [pcolor != white]
]
[
if (pcolor = 66)
[
move-to one-of patches with [pcolor != 66]
]
]
]
]
create-outer-buildings Outer-City_Density ;; Creating the outer-city building density
[
set heading 0
set shape "square"
set size (random 0.05) + 0.65
set color yellow
move-to one-of patches with [pcolor != white] ;; if building is on the road, move it to patch that isn't white
setxy (0 + random-float 0) (0 + random-float 0) ;; Set position building infras anywhere ranging from -50 to 50 for x- and y-directions
ask outer-buildings
[
if (pcolor = white) ;; if building infras. still lands on road move to patch that isn't white in color
[
move-to one-of patches with [pcolor != white]
]
if (pcolor = red)
[
move-to one-of patches with [pcolor = 96]
]
ifelse (pcolor = white)
[
move-to one-of patches with [pcolor != white]
]
[
if (pcolor = 66)
[
move-to one-of patches with [pcolor != 66]
]
]
]
]
]
create-AVs (Market_Pentr) * Vehicles
[
set size 0.4
set shape "car"
set color orange
move-to one-of roads
set goal a-station
set-heading-to-station
]
create-TVs (1 - Market_Pentr) * Vehicles
[
set size 0.5
set shape "car"
set color magenta
move-to one-of roads
]
reset-ticks
end
to set-heading-to-station
set trip-status 0
let goal-candidates patches with [pcolor = red and any? neighbors with [pcolor = white]]
set a-station one-of goal-candidates
set destination one-of goal-candidates with [self != [a-station] of myself]
end
to setup-patches ;; Command for setting up patch design for simulation
ask patches
[
ifelse ((pxcor <= 25 and pxcor >= -25) and (pycor <= 25 and pycor >= -23)) ;; if a patch is between pxcor and pycor of -25 and 25
[
set my-row -1
set my-column -1
set pcolor yellow + 3 ;; set the patch's color to yellow for inter-city block representation
]
[
set pcolor 96 ;; otherwise set the patch's color to a modified sky blue for outer-city block representation
]
]
ask patches
[
if ((pxcor <= 25 and pxcor >= -25) and (pycor <= 25 and pycor >= -25))
[
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)
]
]
]
;; setup the a-station
set a-station patches with [(pxcor >= 36 and pxcor <= 39) and (pycor >= 37 and pycor <= 40)]
ask a-station
[
set pcolor red
]
ask roads
[
ifelse ((pxcor <= 25 and pxcor >= -26) and (pycor <= 26 and pycor >= -25))
[
set pcolor white
]
[
set pcolor white ;; this is a placeholder
]
]
end
to Drive-Around
ask AVs
[
if [pcolor] of patch-here = white
[
face drive-forward
forward AV-speed
]
]
end
to-report drive-forward
ask AVs
[
if goal = a-station ;;and (member? patch-here [neighbors4] of a-station) ;; CHANGE THIS SO IS CONDUCIVE WITH PEDESTRIAN AGENTS LATER ON
[
set trip-status 1
set goal destination
]
if goal = destination ;;and (member? patch-here [neighbors4] of destination)
[
set trip-status 2
;; this could be the count of the number of assisted citizens
set-heading-to-station
let A-Station_X_Cor [pxcor] of a-station
let A-Station_Y_Cor [pycor] of a-station
let Destination_X_Cor [pxcor] of destination
let Destination_Y_Cor [pycor] of destination
let required_range 1.5 * (
abs(A-Station_X_Cor - [xcor] of myself) +
abs(Destination_X_Cor - A-Station_X_Cor) +
abs(A-Station_Y_Cor - [ycor] of myself) +
abs(Destination_Y_Cor - A-Station_Y_Cor))
if required_range < 50
[
set goal a-station
]
]
]
let choices neighbors with [pcolor = white]
let choice min-one-of choices [distance [goal] of myself]
report choice
end
我正在尝试查看是否可以让车辆代理移动到模拟中的特定位置,但同时停留在我的城市网格系统中的道路上的白色斑块上。需要注意的一点是,被称为distance 的原语不断给我错误,我不确定错误消息告诉我什么,也不知道此时该做什么。我尝试在 to Drive-Around 命令中放置 if 语句,但它似乎并没有删除错误消息。
【问题讨论】:
-
请编辑您的问题以仅显示相关代码。可能只是生成错误消息的过程以及对变量含义的描述。错误消息的意思是您询问的是到 16 个代理而不是 1 个代理的距离,但我不知道那在哪里或为什么。
标签: netlogo