首页 > 解决方案 > 如何报告链接之间的距离并将报告的值用于代码中的其他计算?

问题描述

我正在尝试计算和报告 NetLogo 中特定代理集之间的距离(链接长度)?有没有办法将链接长度计算到列表中?

代理的移动基于距离(连接)值是否低于/高于阈值。但是,我很难将链接长度的值设置为可变连接。(最好在列表中)。我会很感激任何帮助。

globals[hourly-wage connection]
breed[offices office]
breed[employees employee]
offices-own [
  pay-high ;; 7 offices pay well
  pay-low  ;; 3 offices dont pay well
]
to setup 
  clear-all
    create-offices 10 [
    set size 1.0
    set color blue
    set shape "house"
    setxy random-xcor random-ycor
    ask offices [create-link-with one-of other offices] ;; undirected links
    ask links [set color red]
  ]

  create-employees 2 [
    set size 1
    set color brown
    set shape "person"
  ]
  set hourly-wage 20
end

;;;; 
 to go
  cal-dist
  ask employees [ 
    if connection > 15
   move-to one-of high-pay office
    if connection <= 15
    move-to one-of low-pay office
  ]
end

to cal-dist
  set connection [list print link-length] ;; 
  ask links [show link-length]
  set salary (hourly-wage * connection)   ;;; salary printed in a list
end

标签: netlogo

解决方案


不完全确定您在这里尝试使用 etc 做什么,但您可以使用- 例如connection将任何链接变量放入列表中:of

to setup
  ca
  ; First create the agents
  crt 5 [
    while [ any? other turtles in-radius 5 ] [
      move-to one-of neighbors
    ]
    set color blue
    set shape "house"
  ]

  ; Once they're created, have them link with
  ; one of the other agents
  ask turtles [ 
    create-link-with one-of other turtles [
      set color red
    ]
  ]

  let link-lengths [ link-length ] of links

  print link-lengths

  reset-ticks
end

我不知道这实际上回答了您的问题,因此您可能想提供更多详细信息,说明您要通过这些链接完成的工作。


推荐阅读