DISTANCE 预期输入为 Netlogo 中的代理 [英] DISTANCE expected input to be an agent in Netlogo

查看:45
本文介绍了DISTANCE 预期输入为 Netlogo 中的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久后,我在运行我的 netlogo 模型时收到一条典型的错误消息:

After a short while I get a typical error message when running my netlogo model:

DISTANCE 期望输入是代理,但没有输入.人类 18 运行 DISTANCE 时出错

到目前为止,我无法修复错误.Netlogo 向我显示了错误发生在源代码中的位置:

So far, I was not able to fix the mistake. Netlogo shows me the location in the source code where the mistake occurs:

let dist-nearest-resource distance nearest-resource

我相信知道该消息意味着没有可用的绿色补丁.除了说代理应该继续前进并随机走动之外,我知道还有什么要编码的.

I believe to know that the message means that there are no green patches available to go to. I do know what else to code other than to say that the agents should move on and walk randomly around.

在这里,下面是我的最小模型,以便您更好地理解.有人知道如何解决这个问题吗?

Here, down below is my minimal model to make you better understand. Does somebody know how to fix this?

breed [ humans human ]
humans-own [ energy ]

patches-own [ countdown ]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca

create-humans(population)
  [
    set shape "person"
    setxy random-xcor random-ycor
  ]

  ask patches [
      set pcolor one-of [green brown]
      ifelse pcolor = green
        [ set countdown 30 ]
        [ set countdown random 30 ]
    ]

  reset-ticks
    end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go-people
  ask humans [ orientation ]
end

to orientation
   ifelse (energy < 4) [ ;if hungry
     let nearest-resource min-one-of (patches with [pcolor = green] in-cone 3 360 ) [ distance myself ] ;check distance between you and nearest resource (3 fields 360 degrees view)
     let dist-nearest-resource distance nearest-resource ;defines what is the shortest distance
     if is-patch? nearest-resource [ ;if green patch exist at all
       face nearest-resource fd distance nearest-resource ;face it and go directly to it
     ]
   ]
   [ walk ] ;otherwise just walk randomly around
end

to walk
  ask humans [
   rt random-float 30 - random-float 30 ;randomly wandering around
   if patch-at dx 0 = nobody [ ;humans get "bounced" away from the limits of the world
     set heading (- heading) ]
   if patch-at 0 dy = nobody [
     set heading (180 - heading) ]
  ]
end

to sustainability ;countdown on brown patches: if 0 is reached, grow resources again after the time set by user
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown regrowth-time ] ;exhausted fields need 30 ticks to recover
      [ set countdown countdown - 1 ]
  ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  if not any? turtles [ stop ] ;defensive programming

  go-people

  ask patches [ sustainability ]
  set resources count patches with [pcolor = green]

  tick

  if count patches with [pcolor = green] = 0 [ stop ] ;model stops if food is no longer available
  if count turtles = 0 [ stop ] ;model stops if all humans died
end

推荐答案

在您的代码中,您永远不要使用 dist-nearest-resource 变量!除非您打算将 dist-nearest-resource 用于其他目的,否则您可以去掉整行.

In your code as it is, you never use the dist-nearest-resource variable! Unless you planned to use dist-nearest-resource for another purpose, you could just get rid of that whole line.

此外,facenearest-resource fd distancenearest-resource(顺便说一下,它不会崩溃,因为它在你的if is-patch?nearest-resource 条件)可以替换为一个简单的move-tonearest-resource.

Furthermore, face nearest-resource fd distance nearest-resource (which, by the way, doesn't crash because it's inside your if is-patch? nearest-resource condition) could be replaced with a simple move-to nearest-resource.

这篇关于DISTANCE 预期输入为 Netlogo 中的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆