当我运行以下代码时,我始终在代码底部收到此错误消息(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语句,但它似乎并未消除错误消息。谁能帮我解决这个问题?谢谢。
我在运行以下代码时,始终在我的代码底部收到此错误消息(DISTANCE预期输入是代理,但获得了代理集(agentset,16个补丁)。) >
在一个地方,您有:
set a-station patches with [...]