Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.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
如何在我要求死亡的NetLogo中存储代理的xy坐标?_Netlogo - Fatal编程技术网

如何在我要求死亡的NetLogo中存储代理的xy坐标?

如何在我要求死亡的NetLogo中存储代理的xy坐标?,netlogo,Netlogo,在我的模型中,我有很多海龟被生产出来,这会减慢速度。我可以通过杀掉他们并设置一个全局计数器来解决这个问题: ask turtles [ if energy < 0 [ set turtle-count turtle-count + 1 die ]] 询问海龟[ 如果能量

在我的模型中,我有很多海龟被生产出来,这会减慢速度。我可以通过杀掉他们并设置一个全局计数器来解决这个问题:

ask turtles [
 if energy < 0 [
 set turtle-count turtle-count + 1
 die
  ]]
询问海龟[
如果能量<0[
设置海龟数量海龟数量+1
死亡
]]
但我也希望能够提取这些代理的“who”、“xcor”和“ycor”。我怎样才能做到这一点


谢谢

您可以将这些值保存在外部文件中。我想这将帮助您设置它,但不确定您是否可以直接复制粘贴

使用以下内容设置模拟:

to setup
    ....
    set-current-directory user-directory ;;choose directory of file  
    file-open "database.txt" ;;choose any name for your file  


    ask turtles 
    [
         if energy < 0 
         [  
             write-to-file ;;go to the writing section  
             set turtle-count turtle-count + 1  
             die  
         ]
    ]


    ....
end 



to write-to-file  
    file-write who  
    file-write xcor  
    file-write ycor  
    file-print "" ;;new line for next turtle
end
如果您打开txt文件,它可能看起来很乱,但是导入它时,例如,在excel中以空格分隔,您将能够很好地阅读所有内容

编辑1

您还可以执行以下操作,这可能会加快您的模拟速度(而不是向每个海龟询问if函数)

用[能量<0]询问海龟
[  
写入文件;;转到“写入”部分
设置海龟数量海龟数量+1
死亡
]

也许有经验的人可以评论一下情况是否如此?

你能再解释一下你的背景吗?我很好奇你为什么需要who。@mattsap我想我真的不需要,我只是想能够在输出文件中识别出单独的海龟。如果你不需要,你可能需要查看飞行重量模式:使用
如果

file-close-all ;;save the file
ask turtles with [energy < 0] 
     [  
         write-to-file ;;go to the writing section  
         set turtle-count turtle-count + 1  
         die  
     ]