在一行中创建重叠代理

时间:2015-04-24 08:46:27

标签: netlogo

使用以下代码我得到的代理是这样的: Normal-view enter image description here

  to setup
          ask breadth-patches [sprout-walls wall-agents[set color 2]]
          ask length-patches [sprout-walls wall-agents[set color 2]]
          ask gap-patches [sprout-walls wall-agents[set color 2]]
          ask length-patches[align-inside-at-top]
          ask breadth-patches [align-inside-at-right-left]
          ask gap-patches[align-inside-at-top]
        end


to align-inside-at-top  ;; patch procedure
  let counter count walls-here ;; we will use this as a count-down, after using it in some calculations
  if counter > 0                 ;; could assume there are turtles, but we are not.
    [ let gap1 1 / counter          ;; size of turtles, gap between turtles
      let half-gap gap1 / 2         ;; half-size of turtles
      let ytop 0
      if-else(pycor < 0)[set ytop  pycor - .5 - half-gap]
      [set ytop  pycor + .5 - half-gap]
      let xleft pxcor - .5 - half-gap
      ask walls-here
      [ set size gap1       
        set ycor ytop
        set xcor xleft + gap1 * counter
        set counter counter - 1    ;; so we're placing them from right to left
                                   ; set ycor ycor + 0.125
      ]
    ]
end

to align-inside-at-right-left  ;; patch procedure
  let counter count turtles-here ;; we will use this as a count-down, after using it in some calculations
  if counter > 0                 ;; could assume there are turtles, but we are not.
    [ let gap1 1 / counter          ;; size of turtles, gap between turtles
      let half-gap gap1 / 2         ;; half-size of turtles
      let ytop  pycor + .5 +  half-gap
      let xleft 0
      if-else (pxcor < 0)[
        set xleft pxcor + .5 - half-gap]
      [     set xleft pxcor - .5 + half-gap
      ]
      ask  turtles-here
      [ set size gap1
        set ycor ytop - gap1 * counter
        set xcor xleft ;+ gap * counter
        set counter counter - 1    ;; so we're placing them from right to left
      ]
    ]
end

注意:矩形中的间隙是由以下代码

引起的
 ask patches  with [pxcor > (gap * (-1)) and pxcor < gap and pycor =(breadthrec - 1)][ask walls-here[die]] 

这里,gap = 1,即1个补丁的宽度。

因此输入参数是wall-agents,它指定沿长度和广度补丁为每个补丁创建的代理数。 我希望改变以创建重叠代理,如下图所示(对不起,这个数字并不是那么完美,但我希望它能解释一下)。请帮忙说明如何实现这一目标。 enter image description here

1 个答案:

答案 0 :(得分:1)

这是要求任何人为你调试的很多代码。

我建议先解决问题的简单版本。你有代码可以在一个补丁中创建wall-agents海龟,沿着一条线均匀分布?一旦你有一个工作代码,那么你可以尝试将它推广到更复杂的问题。

如果你在编写这个更简单的版本时遇到麻烦,那么在Stack Overflow上你会遇到一个较小的问题,这个问题比你当前的非常大的问题更容易回答。

如果您能够编写更简单的版本,请不要丢弃它 - 保留它,以便在需要时可以返回它。然后解决更大的问题。

您甚至可以使用更简单的版本,将其放入过程中,然后从更大的解决方案中调用该过程。制作有效的小程序,然后从其他程序中调用这些较小的程序,通常是将问题分解为可管理部分的好方法。

相关问题