从特定代理的上下文来看,两种不同代理之间的距离

Distance between two different breeds of agents from the context of a particular agent

在我的模型中有三种代理;人、公共汽车站和工作场所。每个人都被分配了一个工作场所 (job) 并选择了一个公交车站 (chosen-bus-stop) 来上班。 我想出了如何找到一个特定的人和他们的 job 和他们的 chosen-bus-stop 之间的距离,使用这个线程作为指导:How can I compute the distance between two patches?。但现在我正在努力寻找这个人的 chosen-bus-stop 和他们的 job 之间的距离。 任何想法将不胜感激!

这是我的设置代码:

breed [people person]
breed [workplaces workplace]
breed [transit-stops transit-stop]

people-own
[ ownHome
 job
 distance-to-job
 chosen-bus-stop
 distance-to-my-bus-stop
 distance-bus-stop-to-job ]

workplaces-own
[ location
 location-type ]

create-workplaces 1000
 [ set shape "triangle 2"
   set color 12
   set size 0.6 ]

create-people population
 [ set shape "circle"
   set color 4
   set size 0.4
   set job one-of workplaces
   set job-location [location] of job ]

create-transit-stops 800
 [ set shape "flag"
   set color blue 
   move-to one-of patches ]

;; I can work out the distance from a particular agent to their ```chosen-bus-stop``` and their ```job```:*

ask people
 [ set distance-to-job [ distance myself] of job
   set chosen-bus-stop one-of transit-stops with [color = blue] in-radius 9
   set distance-to-my-bus-stop [distance myself] of chosen-bus-stop ]

;; But when I try something similar to find the distance from the bus stop to their job I get this error: TRANSIT-STOPS breed does not own variable JOB*

   set distance-bus-stop-to-job [ distance job ] of chosen-bus-stop  

 ]
end

尝试:

set distance-bus-stop-to-job [ distance [ job ] of myself ] of chosen-bus-stop

或者:

let my-job job
set distance-bus-stop-to-job [ distance my-job ] of chosen-bus-stop

要记住的重要一点是(就像askof原语引入了上下文的变化。在这种情况下,这意味着 of 之前的报告程序块在 chosen-bus-stop 的上下文中运行,并且(正如错误消息告诉我们的那样)公交车站无法直接访问 job变量,这是一个people-own变量。