【问题标题】:How to transfer attributes of a turtle to another in NetLogo?如何在 NetLogo 中将乌龟的属性传递给另一个乌龟?
【发布时间】:2015-06-14 22:15:06
【问题描述】:

我想将一只乌龟的属性转移给另一个。我的目标基本上是这个; 我创建了公司海龟,如果公司破产(如果其净值小于零),我希望这家公司复制幸存公司的属性(具有正净值的公司)(公司将被随机选择)。有 50 家公司,所以首先我应该随机选择一个幸存的公司,并将其属性转移到我的破产公司。 (净值、产出等属性)

我只能编写代码来更新我的净资产。在这里;

to update-networth
  set networth networth + ( 1 - rd-fraction ) * profit
end

如果你能帮助我,我会很高兴。我被卡住了。

【问题讨论】:

    标签: inheritance attributes netlogo turtle-graphics


    【解决方案1】:

    在我看来,最简单的方法是随机挑选一些幸存的乌龟,然后让这家公司hatch 成为一家新公司。您是否希望保留破产公司的任何属性(例如其位置)?如果是这样,您需要将他们分配给新公司,这只是从另一个方向引入了相同的问题。

    直接的方式如下:

    to copy-attributes [from-firm to-firm]
      ask to-firm
      [ set attribute1 [attribute1] of from-firm
        set ....
      ]
    end
    

    【讨论】:

    • 不,我不想保留任何破产属性。我一直在寻找hatch,我认为这可能对我有用。但是仍然无法将随机公司与破产公司相匹配。
    【解决方案2】:

    问题已解决,可能对其他人有帮助,所以我把它留在这里;

    to update-networth ; firm 
      set networth networth + ( 1 - rd-fraction ) * profit
      if networth < 0
      [ ask firms [copy-attributes] ]
    end
    
    to copy-attributes 
      hatch-firms 1 [ set networth [networth] of one-of firms with [ networth ] > 0 ]  
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多