如何在netlogo中存储要还原的网络上下文?

如何在netlogo中存储要还原的网络上下文?,netlogo,Netlogo,在杀死一只海龟后,我试图恢复海龟的初始(回到它的第一个状态)上下文和链接。 我一直在尝试这个解决方案,但不知怎么的,它不起作用。 下面是我的代码 to cycle if Measure = "Efficiency of network" [ ;store node and link nw:set-context turtles with [ shape = "circle" ] links with [ color = blue ] sho

在杀死一只海龟后,我试图恢复海龟的初始(回到它的第一个状态)上下文和链接。 我一直在尝试这个解决方案,但不知怎么的,它不起作用。 下面是我的代码

to cycle
    if Measure = "Efficiency of network" 
      [ ;store node and link
        nw:set-context turtles with [ shape = "circle" ]  links with [ color = blue ]
        show map sort nw:get-context
        set old-turtles item 0 nw:get-context
        show old-turtles
        set old-links item 1 nw:get-context
        show old-links  
        ;start process
        process-performance     
      ]
end

to process-performance

  if NumberOfNodes = 1 
  [file-open "1node.txt"  
    while [not file-at-end?]
    [
      ;calculate initial performance value
      set initial nw:mean-path-length
      show initial

      let nodeseq read-from-string (word "[" file-read-line "]")
      show item 0 nodeseq
      ask turtle (item 0 nodeseq) [ die ]
      update-plots

      ;calculate new performance value
      set final nw:mean-path-length
      show final
      set result (1 - (final / initial)) * 100
      show result

      nw:set-context old-turtles old-links
      show map sort nw:get-context

    ]    
    file-close
]
end
我一直在netlogo的文档中使用“nw:set-context old turtles old links”,但似乎无论我如何存储它们,我存储在“old-turtles old links”中的原始turtle和链接上下文都会被故意更改。我在想如果[die]函数改变了存储的代理集?当我杀死节点时,旧海龟和旧链接的大小逐渐变小。我并没有将西北部的新环境存储回老海龟和旧链接

或者有人有其他方法来存储旧的代理集和链接并恢复到其原始网络结构吗


感谢您通读。

杀死海龟确实会将其从所有代理集中删除,因此恢复上下文不会使其恢复。您可以尝试从上下文中删除海龟,而不是杀死它。你可以隐藏海龟和它的链接来重现杀死它的视觉效果。这将类似于:

...
let target-turtle turtle (item 0 nodeseq)
ask target-turtle [
  hide-turtle
  ask my-links [ hide-link ]
]
nw:with-context (remove turtle (item 0 nodeseq) old-turtles) old-links [
  update-plots

  ;calculate new performance value
  set final nw:mean-path-length
  show final
  set result (1 - (final / initial)) * 100
  show result
]
...

通过这种方式,为了计算的目的,海龟会从上下文中移除,但不会被杀死,因此它的结构信息会被记住。为您处理存储和恢复上下文的操作,但是如果没有上下文,这段代码也可以正常工作(您只需要自己恢复上下文)

感谢您的回答,以及您对海龟被杀的确认,这也将从所有代理集中删除海龟。相当有趣的财产。稍后我将尝试使用“隐藏”功能。目前,我正在使用一种非常暴力的方法来恢复我的所有节点和链接。