首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >控制来自形状文件的邻近多边形中海龟的行为

控制来自形状文件的邻近多边形中海龟的行为
EN

Stack Overflow用户
提问于 2022-06-21 05:09:42
回答 1查看 48关注 0票数 1

你能帮我解决下面的网络标识问题吗?以下是我的问题:

  • 每个农民都由一只海龟
  • 农民在县多边形边界内随机创建,该多边形是从形状文件中导入的。该形状文件具有显示每个县中农民no (FarmNo)的属性。这些数字被用来选择随机的农民(请看图片)。
  • I创建了一个文本文件Neighbor.text,它包含每个多边形的信息和相邻多边形的id。
  • ,我需要为每个相邻的县创建农民的代理集,在每个代理集合中,农民的数量将由他们自己的县内的农民和他们的邻近的
  • ,农民有一个采用的阈值AT。现在,如果农民在附近的农民中的收获率高于他的AT值,那么农民将是积极的。
  • I应用下面的代码创建了具有形状文件的世界,导入了邻居信息,并在多边形内部创建了农民。但是,我错过了在邻近县创建农民代理集的机会。

代码语言:javascript
复制
extensions [gis]

globals [
  GA-dataset  ;; the shape file
  ]
patches-own [
  ID     ;;patch ID is identical with polygon ID_ID
  farm          ;;number of farmers in each county
  myneighbors  ;;neighboring polygons' 
  AR ;; adoption ratio
    ]
turtles-own [
  tId ; id of each farmer
  AT ; adoption threshold
  tneighbors ; an agentset of its neighbor turtles 
  positive  ; if AR > AT
]

to setup
  ca
  reset-ticks

  set GA-dataset gis:load-dataset "County.shp"
  gis:set-world-envelope gis:envelope-of GA-dataset

  gis:apply-coverage GA-dataset "CODE" ID
  gis:apply-coverage GA-dataset "FARMNO" farm
 
  file-close
  file-open "Neighbor.txt"

  while [not file-at-end?] [
    let x file-read let y file-read
    ask patches with [ID = x ] [
      set myneighbors ( patch-set myneighbors patches with [ID = y ] )
    ]
  ]
file-close

  foreach gis:feature-list-of GA-dataset [ feature ->

    let target-patches ( patches gis:intersecting feature ) with [ gis:contained-by? self feature ]
     ; Get the number of turtles that should be in each target-patch:
      let farm1 round gis:property-value feature "FarmNo"

    if any? target-patches [

     gis:create-turtles-inside-polygon feature turtles farm1 [
        set tID who
        set shape "person"
        set color green
        set size 2
        ]
    ]
  ]

 ask turtles [
    set AT random-normal 0.2  0.1920 
    set label precision AT 2
    ]
  ask patches [
  set AR 0
   ]
  ask turtles [
set tneighbors [myneighbors] of patch-here
]
  ;; Draw boundary
  gis:set-drawing-color white
  gis:draw GA-dataset 1

end

to go
  ask turtles [
  set positive count tneighbors with [AT <= AR]
  ]
  if ticks = 11 [stop]
  tick
end
EN

回答 1

Stack Overflow用户

发布于 2022-06-26 19:21:34

这个模型中似乎有四种不同的实体:

Areas

  • Counties

  • Farms

  • (Kinds
  1. 单位的作物(可能?或者我们只看一种crop?)
  2. Adopted作物(可能吧?)还是我们只看一种作物?)

单位土地面积(ULA)

location

  • Provide中的
  • 被空间地排列和固定在farms
  • Contain县的ID信息的源数据
    • 中,因此可以用来定义counties

  • 实现为修补程序

ULAs (patches)

  • Defined通过ULA上的县ID在源数据

  • 中包含
  • ,因此,从ULAs
  • 继承的空间信息与相邻的县有关系,在文本file
  • Maintain记录中将county
  • Implemented中的农民的作物适应率定义为一种海龟,每县一只。

农场

(patch)

  • Adopt作物中的
  • 来自于
  • 的种类,在一个县的
  • 也受到其他农场的选择的影响。包括来自邻近counties

  • 是一种海龟品种--每个农场一只。

粮食作物

archetype

  • Used
  • 定义了由各县提供给农场
  • an
  • 的哪些作物来保存收养率记录
  • 可以将其种类的
  • 计算为一种海龟,每种作物
  • 农场链接到各种作物

F 275

采用作物

由农场countable

  • Implemented

  • 采用的
  • 必须是有向链接品种,农场
  • 农场采用的每一种作物使用该链接可以链接到各种作物,如果采用的作物有任何统计数据(单位面积的产量百分比、价值,不管是什么),它们都属于采用的作物链接。

<代码>H 187农场可以采用多种H 288/code>H 189也可以被各州用来方便地管理每种作物的statistics

  • terrible名称,对不起,可能是“种植”或“选择”或其他什么?H 292

有了这些,你就可以很容易地得到如下的答案:

考虑到本县和邻近的counties?

  • What作物在neighborhood?

  • What中的AR值最高的是每种作物的AR值是什么?

这些问题在代码中会被问到,比如:

代码语言:javascript
复制
;; show top neighborhood crop for each county
ask counties
[
  show [ label ]
    of max-one-of
         crops 
         [ count 
           [ my-adopted-crop-neighbors ]
           of [ neighborhood-farms ]
             of myself 
         ]
]

看上去很复杂,但根据关系由简单的部分组成。

注意:由于NetLogo自己使用的补丁和链接“邻居”,以及该模型在县使用“邻居”和“邻里”,所以有很大的人为混淆的空间。考虑使用一个替代词,或者用不那么令人困惑的记者来包装网络徽标的混淆名称。就像to-report my-plantings report my-adopted-crop-neighbors end

要清楚的是:除非你想要具体的可视化一些东西,只有补丁和农场是可见的(甚至农场可能只是一个彩色的正方形,也许意味着顶部作物的采用)。

即使只有一种作物,这是一个是/否的问题,你仍然可以利用种类和采用的品种进行簿记。

下面的代码是如何设置这样一个代理系统的示例。实际上,它编译时没有错误。可以随意使用任何有帮助的东西。

代码语言:javascript
复制
extensions [gis]

globals
[
  GA-dataset  ;; the shape file
]

breed [ Counties County ]
breed [ Farms Farm ]
breed [ Crops Crop ]
directed-link-breed [ Adopted-Crops Adopted-Crop ]

patches-own
[
  p-ID      ;; ID of the patch's county from the source data
  p-county  ;; points to the patch's county turtle
  farm-count ;; count of farms in this patch
  AR        ;; adoption ratio (is this a patch-level value or a county one?)
]

farms-own
[
  f-ID      ;; ID of the county from the source
  f-County  ;; points to the farm's county turtle
  AT        ;; adoption threshold (per crop?)
            ;; (is this a farm-level value or a county value?)
            ;; is this one value or set of values? (ie, all the crops)
            ;; if this is per-crop (a list), then this is eliminated
            ;; by the adopted crops 
  positive  ;; if AR > AT ;; same-- this may be a per-crop value
]

Crops-Own
[ ;; label ;; use the built in label for values like "oranges" or "corn"
  ;; add variables as needed for things like..
  ;; cost
  ;; market-value
  ;; adoption-preference
  ;; etc.
]

Adopted-Crops-Own
[ ;; add variables for per-farm or per-county things like:
  ;; % of production
  ;; production amount?
  ;; label -- copy the label from the Crop,
  ;; this will probably be convenient to have
]

counties-own
[ county-ID      ;; ID number of the county from Source
  county-patches ;; patches in this county
  border-patches ;; set of patches on the border of the country
                 ;; useful to draw the map
                 ;; and later may be useful for visualization
                 ;; that needs to highlight a county
  county-farms   ;; farmers in this country
  county-crops   ;; unless it frequently changes membership,
                 ;; the set of all adopted-crops links for all my farms
  
  adjacent-counties  ;; set of counties sharing a border
  adjacent-farms     ;; set of farms from those counties
  neighborhood       ;; set of this and adjacent counties
  neighborhood-farms ;; farms in this and adjacent counties
  neighborhood-crops ;; crops adopted in this and adjacent counties
                     ;; any other county-level variables, like adoption rate history
]

to setup-patches-from-GIS
  set GA-dataset gis:load-dataset "County.shp"
  gis:set-world-envelope gis:envelope-of GA-dataset
  
  gis:apply-coverage GA-dataset "CODE" p-ID
  gis:apply-coverage GA-dataset "FARMNO" farm-count
end

to setup-counties
  let list-of-county-ids remove-duplicates [ p-ID ] of patches
  foreach list-of-county-ids 
  [ $ID ->
    create-counties 1
    [ set county-ID $ID
      set county-patches patches with [ p-ID = $ID ]
    ]
  ]
end

to setup-county-neighbors
  ask counties
  [ set adjacent-counties no-turtles
  ]
  file-close-all
  file-open "Neighbors.txt"
  while [ not file-at-end? ]
  [
    let $a file-read
    let $b file-read
    let $AA one-of counties with [ county-ID = $a ]
    let $BB one-of counties with [ county-ID = $b ]
    ask $AA [ set adjacent-counties ( patch-set $BB adjacent-counties) ]
    ask $BB [ set adjacent-counties ( patch-set $AA adjacent-counties) ]
  ]
  set neighborhood ( patch-set self adjacent-counties )
  file-close
end

to setup-crops
  let crop-list
  [
    [ "apples"    ] ;; include any other per-crop values to initialize
    [ "oranges"   ] ;; you could also store this list is a file 
    [ "rice"      ] 
    [  "beans"    ]
    [ "coffee"    ]
  ]
  foreach crop-list 
  [ crop-data-row ->
    create-Crops 1 
    [ hide-turtle
      set size 0
      set color black
      set heading 0
      set label item 0 crop-data-row
      ;; set other-property item 1 crop-data-row
      ;; etc
    ]
  ] 
end

to setup-farms
  ;; this is confusing... did we not already
  ;; load ID and farmno into the patches?
  ;; so.. can we just use that?
  
  ask patches with [ farm-count > 0 ]
  [ sprout-farms farm-count
    [ set f-ID p-ID
      set f-county p-county
      set shape "person" 
      set color green
      set heading 0
      set size 0 
    ]
  ]
  ;; setup adopted-crops
  ask farms
  [ create-adopted-crops-to crops
    [ hide-link
    ] 
  ]  
  
  ;;foreach gis:feature-list-of GA-dataset
  ;;[ feature ->
  ;;  let target-patches ( patches gis:intersecting feature )
  ;;     with [ gis:contained-by? self feature ]
  ;; ;; Get the number of turtles that should be in each target-patch:
  ;;  let farm1 round gis:property-value feature "FarmNo"
  ;;  if any? target-patches
  ;; [
  ;;    gis:create-turtles-inside-polygon feature turtles farm1
  ;;    [
  ;;      set t-ID who
  ;;      set shape "person"
  ;;      set color green
  ;;      set size 2
  ;;      set t-county one-of counties with [ county-ID = 
  ;;      ]
  ;;  ]
  ;; ]
end

to setup-farm-data
  ask farms
  [
    set AT random-normal 0.2  0.1920 
    set label precision AT 2
  ]
  ask patches
  [
    set AR 0
  ]
end

to update-county-datasets
  ask counties
  [ let this-ID county-ID
    set border-patches county-patches with
    [ any? neighbors with [ p-ID != this-ID ]
    ]
    set county-farms farms-on county-patches
    set county-crops (link-set [ my-adopted-crops ] of county-farms)
  ] 
  ask counties 
  [
    set adjacent-farms (turtle-set [ county-farms ] of adjacent-counties)
    set neighborhood-farms (turtle-set [ county-farms ] of neighborhood)
    set neighborhood-crops ( link-set [ my-adopted-crops ] of neighborhood-farms) 
  ]
end


to draw-boundaries
  ;; Draw boundary
  gis:set-drawing-color white
  gis:draw GA-dataset 1
end

to setup
  setup-patches-from-GIS
  setup-counties
  setup-county-neighbors
  setup-crops
  setup-farms
  setup-farm-data
  update-county-datasets
  draw-boundaries
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72695601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档