如何孵化面对代理集最近邻居的海龟

how to hatch turtles that face closest neighbor of agentset doing the hatching

我目前有一个代理集(端口)孵化另一个代理集(船舶)。 这个想法是让船只面对离他们当前位置最近的港口。

[let target min-one-of ports [distance myself] face target].

不幸的是,这使得船只面对它们当前的位置,因为它们是在给定的港口孵化的。如果没有办法排除它们孵化的端口 - 我有一个位置(端口)的索引并且可能将目标设置为索引中的以下项目但是我不确定我将如何完成此操作。有什么建议吗?

完整代码示例

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值赋值给船舶作为当前港口,将目标港口定义为非当前港口的关闭港口。

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