Как создавать различные шаблоны сетки в NetLogo - PullRequest
0 голосов
/ 25 мая 2020

Существующий в настоящее время код для сеток трафика c имеет один тип сетки в плоскости моделирования. Однако я пытаюсь создать сетку, в которой есть два типа сеток в одной плоскости моделирования. Например, в центре есть более мелкие сетки с плотно упакованной установкой, а внешние части плоскости моделирования имеют более крупные сетки, но менее плотно упакованную установку.

До сих пор я использовал Traffi c Grid (http://ccl.northwestern.edu/netlogo/models/TrafficGrid) установочный код из общей библиотеки NetLo go в качестве шаблона для начала работы. Одна из вещей, которые я сделал в коде, - это установка глобальных переменных для меньших сеток, установив внутренний размер сетки x и внутренний размер сетки y для меньших сеток, которые будут созданы в диапазоне - 25 <= pxcor <= 25 и -25 <= pycor <= 25. Это будет раздел с плотной сеткой. Я также установил глобальные переменные (например, external-x-grid-size и external-y-grid-size) для менее плотной секции, которая состояла из любых патчей за пределами ранее упомянутого диапазона. Мой код выглядит примерно так: </p>

    globals
    [
      x-grid-size ;; Global variable for inter-city grid-sizing in the x direction
      y-grid-size ;; Global variable for inter-city grid-sizing in the y-direction
      grid-x-inc ;; Global variable for inter-city street spacing in x-direction
      grid-y-inc ;; Global variable for inter-city street spacing in y-direction
      outer-x-grid-size ;; Global variable for outer-city grid-sizing in the x-direction
      outer-y-grid-size ;; Global variable for outer-city grid-sizing in the y-direction
      outer-grid-x-inc ;; Global variable for outer-city street spacing in the x-direction
      outer-grid-y-inc ;; Global variable for outer-city street spacing in the y-direction
      roads ;; Global variable for inter-city road network
      outer-roads ;; Global variable for outer-city road network
    ]

    breed [inter-buildings inter-building] ;; Inter-city buildings such as office, retail, business, apartments, etc.
    breed [outer-buildings outer-building] ;; Outer-city buildings such as residential, reatail, apartments, etc.

    patches-own
    [
      my-row ;; The row of the intersection counting from the upper left corner of the world.  -1 for non-intersection patches.
      my-column ;; The column of the intersection counting from the upper left corner of the world. -1 for non-intersection patches.
    ]

    to setup
      clear-all
      setup-globals ;; Command for setting up and initializing the global variables
      setup-patches ;; Command for setting up the patches for the inter-city and outer-city zones of simulation

      if show-buildings? ;; if the show-building switch is true then building infras will be shown
      [
        create-inter-buildings Inter-City_Density ;; Creating the inter-city building density
        [
          set heading 0
          set shape "square"
          set size (random 0.5) + 1
          set color grey
          ;;set pcolor grey
          move-to one-of patches with [pcolor != white] ;; if building is on the road, move it to patch that isn't white
          setxy (-25 + random-float 50) (-25 + random-float 50) ;; Set position building infras anywhere ranging from -25 to 25 for x- and y-directions

          if (pcolor = white) ;; if building infras. still lands on road move to patch that isn't white in color
          [
            move-to one-of patches with [pcolor != white]
          ]
        ]

        create-outer-buildings Outer-City_Density ;; Creating the outer-city building density
        [
          set heading 0
          set shape "square"
          set size (random 0.05) + 0.65
          set color yellow
          move-to one-of patches with [pcolor != white] ;; if building is on the road, move it to patch that isn't white
          setxy (0 + random-float 0) (0 + random-float 0) ;; Set position building infras anywhere ranging from -50 to 50 for x- and y-directions

          if (pcolor = white) ;; if building infras. still lands on road move to patch that isn't white in color
          [
            move-to one-of patches with [pcolor != white]
          ]
        ]
      ]
      reset-ticks
    end

    to setup-globals ;; Command for setting up global variables
      ask patches
      [
        ;;lets initiatize the global variables in this command
        if ((pxcor <= 25 and pxcor >= -25) and (pycor <= 25 and pycor >= -25))
        [
          set inner-x-grid-size 20
          set inner-y-grid-size 20
          set inner-grid-x-inc world-width / inner-x-grid-size
          set inner-grid-y-inc world-height / inner-y-grid-size
        ]

        if ((pxcor > 25 and pxcor < -25) and (pycor > 25 and pycor < -25)) <--- I am trying to make the outer grids double the size or larger than the inner grids that are at the center of the simulation plane
        [
          set outer-x-grid-size 20
          set outer-y-grid-size 20 / 2
          set outer-grid-x-inc world-width / outer-x-grid-size
          set outer-grid-y-inc world-height / outer-y-grid-size
        ]
       ]
    end

    to setup-patches ;; Command for setting up patch design for simulation
      ask patches
      [
        ifelse ((pxcor <= 25 and pxcor >= -25) and (pycor <= 25 and pycor >= -23)) ;; if a patch is between pxcor and pycor of -25 and 25
        [
          set my-row -1
          set my-column -1
          set pcolor yellow + 3 ;; set the patch's color to yellow for inter-city block representation
        ]

        [
          set pcolor 96 ;; otherwise set the patch's color to a modified sky blue for outer-city block representation
        ]
      ]

      ask patches ;; 
      [
        ifelse ((pxcor <= 25 and pxcor >= -25) and (pycor <= 25 and pycor >= -25))
        [
          set roads patches with
          [
            (floor ((pxcor + 25 - floor (grid-x-inc - 1)) mod grid-x-inc) = 0) or
            (floor ((pycor + 25) mod grid-y-inc) = 0)
          ]
        ]

        [
          set outer-roads patches with ;; THIS SECTION STATES THAT THE MODULUS WRAPS TO ZERO NOT SURE WHY
          [
            (floor ((pxcor + max-pxcor - floor (outer-grid-x-inc - 1)) mod outer-grid-x-inc) = 0) or
            (floor ((pycor + max-pycor) mod outer-grid-y-inc) = 0)
          ]
        ]
      ]

      ask roads
      [
        ifelse ((pxcor <= 25 and pxcor >= -26) and (pycor <= 26 and pycor >= -25))
        [
          set pcolor white
        ]

        [
          set pcolor white ;; this is a placeholder
        ]

    end

В коде, когда я настраиваю, все сетки все еще однородны, но я хочу, чтобы они были неравномерными с небольшими узорами сетки в центре (например, -25 <= pxcor <= 25 и -25 <= pycor <= 25) и более крупные сеточные узоры в других местах. Кроме того, я получаю ошибки, которые говорят мне, что я делю на ноль из-за того, что мой модуль возвращается к нулю, когда я вношу изменения в команду setup-patches. Кто-нибудь знает, как сделать таким образом неоднородный сетчатый узор? Это возможно в NetLo go? Мне тяжело с этим. </p>

...