当你有多个海龟配置文件时如何导出 NetLogo 6.2 视图?

How to export NetLogo 6.2 View when you have multiple turtle profiles?

我正在尝试实现一个从视图导出的输出。我从这个 link 得到了帮助: 我非常感谢 Luke C 的帮助,因为我设法实现了我想要的部分内容。

但是,我仍然没有成功地通过海龟剖面生成图像。我有 16 个海龟配置文件(请参阅 ValidHabs)。

例如,我想为 16 个海龟配置文件中的每一个导出一个图像。

例如海龟档案1(只能在habitatcover 1中出生和孵化),所以:

At tick 0, the world started with: 1 turtle no (patch 15 -4),
At tick 1, there are 2 turtles in patches (patch 15 -4) and (patch 14 -8) and
At tick 2, there are 4 turtles in patches (patch 15 -4), (patch 14 -8), (patch 12 -5) and (patch 17 -1).

所以对于海龟轮廓 1,您将得到一个白色的导出图像,其中补丁 (补丁 15 -4)、(补丁 14 -8)、(补丁 12 -5) 和 (补丁 17 -1) 被涂成洋红色. 然后我将图像导出到 turtle 2 的轮廓等...直到我得到只能在 habitatcovers 4 和 5 中产卵的 turtle 16 的轮廓。

我尝试使用 foreach 将图像导出到每个配置文件,但结果是打开一个 .png 文件并在该文件中生成结果(“覆盖”)。我想要的是为每个海龟配置文件生成 1 个 .png 格式的文件。我认为使用 foreach 并小心我可以生成文件。但到目前为止我还做不到。如果有人能帮助我,我将不胜感激:)

提前致谢

代码:

globals [ ListProfiles ]
patches-own [ turtle-born-here ]
turtles-own [ all-code  metabolism reproduction code-metabolism code-reproduction ]

to setup
  ca
  set ListProfiles [ [1] [2] [3] [4] [5] ]
  ask patches [ set turtle-born-here false ]
  ask n-of 5 patches [
    sprout 1
    setup-turtles    
    set turtle-born-here true
  ]  
  reset-ticks
end

to go
  ask turtles [
    rt random 60 - 30
    fd 1
    if random-float 1 < 0.05 [
      hatch 1
      ask patch-here [ set turtle-born-here true]
    ]
  ]
end

to setup-turtles 
  ask turtles [
    (
      ifelse
      metabolism = 2 [set code-metabolism "M1"]
    )
    (
      ifelse
      reproduction = 5 [set code-reproduction "R1"]
    )
    set all-code ( word code-metabolism code-reproduction )
  ]
end

to example-export-image
  setup
  ; Some example go runs
  repeat 50 [ go ]

  ; This is the export-view component
  cd
  ask turtles [
    ht
  ]
  ask patches [
    ifelse turtle-born-here
    [ set pcolor magenta ]
    [ set pcolor white ]
  ] 
  carefully
  [ file-delete ( "View.png" ) ]
  [ ]
  foreach ListProfiles
    [
      y ->
      let k turtles with [ all-code = y ]
      ask k [
      export-view ( "View.png" )
      ]
    ] 
end

当您提供代码时,建议您从头开始,而不是试图削减现有模型(请参阅 How to Ask and How to create a Minimal, Reproducible Example)。这将在(至少)两个主要方面有所帮助:

  1. 它使您的代码更具可读性,因此使您更有可能获得有用的答案,因为如果本网站上的其他用户不必 也将更容易理解问题 尝试理解代码的哪一部分与实际问题无关。
  2. 它使更有可能自己解决问题,或者至少会帮助您更好地了解问题的根源。

我建议您在 post 提出问题时努力尝试遵循上述指南。就目前而言,您提供的代码远远超过问题本身实际需要的代码,对我来说可以归结为:“如何更改多个实验/模拟的文件名?”这个问题已经 that may suit your needs- if the code example below does not clear things up, have a look through those other questions and keep in mind the "Search and Research" component of the How To Ask 帮助页面。

对于一个独立的例子,这实际上只是对 Charles 在上面第一个 link 中的回答的改进:

patches-own [ hab-type turtle-born-here ]

globals [ profiles ]

to setup
  ca
  resize-world 0 29 0 29
  set profiles [ "a" "b" "c" ]
  ask patches [
    ( ifelse pxcor < ( max-pxcor / 3) [
      set hab-type "a"
    ] pxcor < ( max-pxcor * 2 / 3 ) [
      set hab-type "b"
    ] [
      ; else
      set hab-type "c"
      ]
    )
  ]
end

to fake-simulate
  foreach profiles [ profile ->
    ask turtles [ die ]
    ask patches [
      set pcolor black
      set turtle-born-here false
    ]
    ask n-of 5 patches with [ hab-type = profile ] [
      sprout 1
      set turtle-born-here true
    ]
    reset-ticks
    repeat 50 [
      ask turtles [
        rt random 60 - 30
        fd 1
        if random-float 1 < 0.1 and [ hab-type ] of patch-here = profile [
          hatch 1
          ask patch-here [ set turtle-born-here true]
        ]
      ]
      tick
    ]
    export-image profile
  ]
end


to export-image [ unique-id ]
  ; Prepare the view for export
  ask turtles [ ht ]
  ask patches [
    ifelse turtle-born-here
    [ set pcolor magenta ]
    [ set pcolor white ]
  ]
  ; Use word to create a file name
  let out-file ( word "example_view_export_" unique-id "_.png" )
  export-view out-file
end

输出类似: