【问题标题】:NetLogo : Keep turtles moving continuously till the endNetLogo : 让海龟不停地移动直到最后
【发布时间】:2016-02-23 08:00:39
【问题描述】:

读者,

我是 NetLogo 的初学者。请帮助我解决以下代码的一些问题:

  1. 我收到错误消息“您不能在海龟上下文中使用刻度,因为刻度是仅观察者。
  2. 我需要在每只海龟都完成“到达接收、到达分流、go-drroom”这三个操作后更新刻度值。
  3. 其他人没有在到达接待处走动,到达分流正在运行。

    to setup-people
      set-default-shape turtles "person"
      set destination ( patch-set patch -2 34 patch 8 34 ) 
    
      create-turtles uninfected
      [ set color blue
        allocate-turtles        
      ]
    
      create-turtles infected
      [ set color red
        allocate-turtles
      ]
    
    end
    
    to allocate-turtles
      if (pcolor = 9.9 and any? turtles-here)
      [
      set size 1.5
      set heading 0                                                                                                                          
      setxy int random-xcor int random-ycor
      ]    
    end
    
    to go
      move-people
      arrive-reception
      arrive-triage
      go-drroom
      tick
    end
    
    to move-people
      ask turtles [
      rt 360
      forward 1
     ]
    end
    
    to arrive-reception
      ask n-of (random count turtles) turtles
      [
      if windows = 1
      [
       move-to patch -2 34
       ifelse not any? turtles-here
       [ wait wait-time ]
       [ wait-in-queue ]
      ]      
      ]
    end
    
     to wait-in-queue
       set arrival-time ticks
      bk 1
      if any? other turtles-here
        [ wait-in-queue ]
      wait wait-time
     if ticks - arrival-time > wait-time
     [ set arrival-time 0
       fd 1 ]
    end
    
    to arrive-triage
     if triage = "Open"
      [
       move-to patch 26 11
       if any? other turtles-here
        [ wait-in-queue]
       wait wait-time
       move-to one-of patches with [pcolor = 109 and not any? other turtles-here ]
       wait wait-time 
       ]   
     end
    
     to go-drroom
       move-to one-of patches with [pcolor = 128]
       if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
       [
        move-to one-of patches with [pcolor = 129]
       if ( min-one-of other turtles in-radius 5 [distance myself] != nobody)
        [
         move-to one-of patches with [pcolor = 5]
         if any? seats with [turtles = nobody]
           [
             move-to one-of max-n-of 6 neighbors [seats]
           ]
        ]
      ]
      wait wait-time
      die
      end
    

谢谢。

【问题讨论】:

  • 如何让海龟在队列中排成一列,一个接一个地排在另一个 n 服务的 fifo 方式

标签: netlogo


【解决方案1】:

首先,一些基本的编程技巧 - 在尝试调试之前不要写太多。如果你做了一个小改动并检查它,那么很容易找出错误所在。程序的初稿可以很简单:

to go-drroom
end

然后填写稍后程序中发生的事情的详细信息。

此错误通常是因为您忘记在某处关闭括号。也就是说,其中一个程序以ask turtles [ ... 开头并且没有] 所以NetLogo 仍然认为该代码适用于海龟。但是,我看不到明显的缺失]。

但你确实有一个概念问题。术语context 在 NetLogo 中用于指代谁要求完成代码以及向谁提出要求。所以ask turtles [ forward 1] 是观察者要求海龟移动并且是观察者上下文过程。您在编写程序时没有考虑您所处的环境,这可能是引发错误的原因。

go 过程中,您首先调用move-peopleask turtles [ ] 确实如此,因此(适当地)来自观察者上下文。那你打arrive-reception也行。

但是你仍然从观察者上下文中调用arrive-triagego-drroom 并使用move-to 之类的命令。谁被要求搬家?你没有ask turtles ...。另一方面,过程wait-in-queue 有类似move-to 之类的命令,但这很好,因为它只在arrive-reception 过程中的ask turtles ... 中调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2017-08-27
    相关资源
    最近更新 更多