Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance 如何在NetLogo中将海龟的属性传递给其他海龟?_Inheritance_Attributes_Netlogo_Turtle Graphics - Fatal编程技术网

Inheritance 如何在NetLogo中将海龟的属性传递给其他海龟?

Inheritance 如何在NetLogo中将海龟的属性传递给其他海龟?,inheritance,attributes,netlogo,turtle-graphics,Inheritance,Attributes,Netlogo,Turtle Graphics,我想把海龟的属性转移到另一个海龟身上。我的目标基本上是这样,; 我创建了海龟公司,如果一家公司破产(如果其净值小于零),我希望这家公司复制一家幸存公司的属性(一家拥有正净值的公司)(公司将随机选择)。有50家公司,所以首先我应该随机选择一家幸存的公司,并将其属性转移到我破产的公司。(资产净值、产出等属性) 我只能写一个代码来更新我的净资产。在这里 to update-networth set networth networth + ( 1 - rd-fraction ) * profit e

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

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

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

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

在我看来,最简单的方法就是随机挑选一些幸存的海龟,让那家公司孵化出一家新公司。你是否希望保留破产公司的任何特征(如其所在地)?如果是这样的话,你需要把它们分配给新公司,这只会从另一个方向引入同样的问题

直接方式如下所示:

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

问题解决了,可能对别人有帮助,所以我把它留在这里

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
更新networth;坚定的
设置networth networth+(第1个分数)*利润
如果networth<0
[询问公司[复制属性]]
结束
复制属性
孵化公司1[设置[networth]>0的公司之一的[networth]
结束

不,我不想保留破产的任何属性。我已经找了
hatch
,我想这对我来说可能很合适。但仍然无法将随机企业与破产企业进行匹配。