【问题标题】:my netlogo code doesnt seem to have any problems, but my agents dont appear我的 netlogo 代码似乎没有任何问题,但我的代理没有出现
【发布时间】:2021-01-03 17:29:19
【问题描述】:

我只是在学习使用 netlogo,我正在尝试编写一个简单的模型来让不同的代理 [品种] 执行不同的任务。出现在界面/宇宙上的代理是用选择器选择的......

这是我在代码中写的:


breed [escarabajos escarabajo]; type of beetles that survive in forests
breed [beetles beetle]; type of beetles that survive in agricultural areas 

;For each breed there are three sub-types of beetles, depending on how far they can move (vagility) this is also selected with a chooser. 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup

  ca

  setup-patches

  set-default-shape turtles "bug"

  ask turtles [create-bichos]

  reset-ticks 
  
end

to setup-patches

  ask n-of 100 patches [ set pcolor green ]

  ask n-of 500 patches [set pcolor yellow]

end

to create-bichos

  if breed = "escarabajo" [

    ask patches with [ pcolor = green ] [

      let k forest-carrying-capacity ; what I want is to create the maximum amount of beetles ;possible per patch, and this maximum is determined with a carrying capacity value, which is set ;with a slider.... 

      sprout-escarabajos k [set color 116 set size 6]
      ]
  ]
  
   if breed = "beetle" [

    ask patches with [ pcolor = yellow ] [

        let k agricultural-carrying-capacity

        sprout-beetles k [set color 76 set size 6] 
      ]
  ]

end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


to go

  if ticks = 72 [stop]

  ask turtles [rt random 360

    move
  ]
  

end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;; PROCEDURES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to move

  if vagility = "High"

  [ask turtles [

    move-to one-of patches in-radius 2 

  ]
  ]
  
  if vagility = "medium"

  [ask turtles [

   move-to one-of neighbors

  ]
 ]
  
  if vagility = "low"

  [ask turtles [

   move-to one-of neighbors4

  ]
]

end 

就像我说的,代码似乎没有任何问题,但是当我点击设置按钮时,只出现不同颜色的补丁......

【问题讨论】:

    标签: netlogo agent


    【解决方案1】:

    您有ask turtles [create-bichos] 行。这有三个问题。 (1) 你还没有海龟,所以没有海龟要问,所以不调用 create-bichos 过程。 (2) 如果您确实已经有一些海龟,那么这些海龟中的每一个都会调用该过程,因此它们会要求补丁多次执行操作。 (3)breed是海龟的属性,不能作为选择器的名字。

    作为一名学习者,您需要编写少量代码并确保每个代码都能正常工作,然后再继续学习。因此,让我们假设您从创建海龟开始(因为这是您的问题),您的选择器称为“品种选择”。解决方案是简单地删除ask turtles,但作为第一遍,您应该在引入更多代码之前简单地创建固定数量的海龟。

    breed [escarabajos escarabajo]; type of beetles that survive in forests
    breed [beetles beetle]; type of beetles that survive in agricultural areas 
    
    to setup
      clear-all
      setup-patches
      set-default-shape turtles "bug"
      create-bichos
      reset-ticks 
    end
    
    to setup-patches
      ask n-of 100 patches [ set pcolor green ]
      ask n-of 500 patches [set pcolor yellow]
    end
    
    to create-bichos
      if breed-selector = "escarabajo"
      [ ask patches with [ pcolor = green ]
        [ sprout-escarabajos 5 [set color 116 set size 6]
        ]
      ]
      if breed-selector = "beetle"
      [ ask patches with [ pcolor = yellow ]
        [ sprout-beetles 5 
        ]
      ]
    end
    

    【讨论】:

    • 非常感谢!你的回答很有用:D
    【解决方案2】:

    使用 create agent command create-escarabajos <number>create-beetles <number> 创建您的自定义品种的新代理

    【讨论】:

    • 该命令已包含在代码中。问题是该命令位于未被调用的代码部分中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    • 2014-01-23
    • 2020-11-13
    • 2019-11-21
    相关资源
    最近更新 更多