【问题标题】:NetLogo :Loop with changing agentsNetLogo :循环与不断变化的代理
【发布时间】:2017-05-11 04:47:06
【问题描述】:

在过去的 24 小时内,我发布了 2 个问题,幸运的是,所有问题都得到了解答。

但是,问题依然存在。

这是我的计划。

我喜欢制作一个微型市场模型,代理商正在寻找他们最近的邻居并进行交易。

如果距离很近(小于 1 个补丁),则以物易物开始。

我喜欢强加一个条件,

也就是说,当事务完成时,每个代理都在为另一个事务寻找其他代理,即使当前代理位于最近。

正如评论的那样,我喜欢让代理集根据他们的新交易伙伴不断更新。

我尝试制作字符串列表(代表交易伙伴),但未能再次将它们转换为有效的代理集。

我该如何解决这个问题?

如果你对我的问题有什么好的想法,请发表评论。

谢谢大家。

(我对立即得到的答案感到惊讶,这也很感谢 这是我尝试过的代码...)

to setup
clear-all
reset-ticks
ask patches [ set pcolor white ]
create-turtles num-turtles [
setxy random-xcor random-ycor
set energy random-gamma 10 0.5
set trust random-float init-trust
]
ask turtles [
    set color scale-color green energy 0 99
    set shape "default"
  ]
end


to go
  ask turtles [
    while [any? other turtles-here] [fd 1]

;    let the-other-turtles [who] of other turtles
;    let the-other-closest-turtles remove my-former the-other-turtles
;    let ws ["turtle"]
;    let other-closest-turtles append-word ws the-other-closest-turtles
;    let ls other-closest-turtles
;    let id the-other-closest-turtles
;    set other-closest-turtles create-other-turtles ws ls id
;    let closest-turtle other-closest-turtles with-min [distance myself]

    let closest-turtle other turtles with-min [distance myself]
    set closest-turtle one-of closest-turtle
    while [closest-turtle = nobody] [fd 1]
    if closest-turtle != nobody [face closest-turtle fd 1]
    if distance closest-turtle <= 1 [transact]
    if energy + trust <= 0 [die]
    ]
  tick
end

to transact
  let stronger max-n-of 2 turtles [trust]
  let weaker min-n-of 2 turtles [trust]
  ask stronger [
    set energy energy - 1
    set trust trust + 1.5
    set my-former weaker
  ]
   ask weaker [
    set energy energy + 1.5
    set trust trust - 1
    set my-former stronger
  ]
end

【问题讨论】:

  • 你不能做什么?该问题询问有关从字符串构造代理集的问题。我们需要查看示例字符串输入和预期输出才能帮助解决该问题。但是这样的解决方案会让你在错误的道路上走得更远。您似乎正在构建一个包含 who 数字的字符串。几乎可以肯定的是,首先简单地构造一个代理集并使用turtle-set 原语添加新的海龟。这也是stackoverflow.com/questions/43896539/making-agentset-outof-list/… 的意思
  • 是的,@JenB。您是对的,首先收集代理集比构建指示海龟名称的列表要好得多。但是,我能够通过连接单词和数字来制作由看起来像 ["turtle 0", "turtle 2", ..."turtle 15"] 的字符串组成的列表。但是,不可能从这些字符串中激活代理集。无论如何感谢您的评论。

标签: loops netlogo


【解决方案1】:

您可以创建一个代理列表,而不是创建一个字符串列表,这样就无需在描述海龟的字符串和海龟本身之间进行转换。可以通过列表操作添加或删除代理。

这是一个使用代理列表创建代理集的完整示例。

to testme
  create-turtles 5
  let mylist (list turtle 1 turtle 3 turtle 4)
  let myset turtle-set mylist
  show myset
end

但 Nicolas 对您上一个问题的回答显示了如何转换字符串。

【讨论】:

    猜你喜欢
    • 2018-08-13
    • 2019-07-22
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多