NetLogo:让海龟不断移动直到最后

时间:2016-02-23 08:00:40

标签: netlogo

读卡器,

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

  1. 我收到一条错误“你不能在海龟环境中使用tick,因为tick只是观察者。
  2. 我需要在每只乌龟进入“到达 - 接收,到达 - 分流,去骚房”这三个之后更新蜱值。
  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
    
  4. 感谢。

1 个答案:

答案 0 :(得分:1)

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

to go-drroom
end

然后填写稍后程序中发生的细节。

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

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

go程序中,您首先拨打move-people。 [{1}}这样做(适当地)来自观察者上下文。然后你打电话给ask turtles [ ],也没关系。

但是,您仍然可以从观察者上下文中调用arrive-receptionarrive-triage,并拥有go-drroom之类的命令。谁被要求搬家?你没有move-to。另一方面,过程ask turtles ...包含wait-in-queue之类的命令,但它很好,因为它只能在move-to过程中的ask turtles ...内调用。