如何孵化面临代理人最近邻居的海龟孵化 [英] how to hatch turtles that face closest neighbor of agentset doing the hatching
问题描述
我目前有一个代理集(端口)孵化另一个代理集(发货)。
想法是让船舶面向最近的当前位置。
I currently have one agentset(ports) hatching another agentset(ships). The idea is to have the ships face the closest port to their current location.
[让目标min-one-ports [距离我自己]
。
面对目标]
不幸的是,这使得船舶面向当前位置,因为它们在给定的港口被孵化。如果没有办法排除他们孵化的端口 - 我有一个位置索引(端口),并可能将目标设置为索引中的以下项目,但我不知道如何实现这一目标。有什么建议吗?
Unfortunately this makes the ships face their current location since they are being hatched at a given port. If there is no way to exclude the port they hatch on- I have an index of the locations(ports) and could potentially set the target as the following item in the index however I am not sure how I would accomplish this. any suggestions?
完整代码示例
breed [ships ship]
breed[ports port]
to setup
let index 0
create-ports 3
[ let loc item index [ [459 -324] [670 -233] [677 -356] ]
setxy (item 0 loc) (item 1 loc)
set index index + 1
set shape "circle"
set size 5
set color red - 1]
ask ports
[ hatch-ships 1
[ set size 10
set color red
pen-down
set pen-size 1
let target min-one-of other ports [distance myself]
face target] ]
reset-ticks
end
推荐答案
您可以指定who值孵化端口到船舶的当前端口,并将其目标端口定义为不是当前端口的关闭端口。
You can assign the who value of hatching port to the ship as their current port and define their target port as the closes port which is not the current port.
breed [ships ship]
breed[ports port]
ships-own [currentPort targetPort]
to setup
clear-all
let index 0
create-ports 3
[
; let loc item index [ [459 -324] [670 -233] [677 -356] ]
let loc item index [ [4 -4] [ 9 5] [ -11 11] ]
setxy (item 0 loc) (item 1 loc)
set index index + 1
set shape "circle"
set size 5
set color red - 1]
ask ports
[
let s who
set label ( word S " Port " s )
hatch-ships 1
[ set currentPort s
set shape "sailboat side"
set size 10
set color red
pen-down
set pen-size 1
Set targetPort min-one-of ports with [ who != s] [distance myself]
set heading towards targetport
set label (word "target " targetport)
] ]
reset-ticks
end
这篇关于如何孵化面临代理人最近邻居的海龟孵化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!