【问题标题】:How to create a Netlogo model for bus transport (public transport)?如何为公交(公共交通)创建 Netlogo 模型?
【发布时间】:2022-10-13 00:52:50
【问题描述】:

我正在尝试模拟人们在 Netlogo 中登上公共巴士。 但是,我对编码的经验很少。我试图自己创建它,但遗憾的是我被卡住了。所以我希望你能帮助我。我将首先解释我想要编码的内容,然后我将展示我当前的代码。提前致谢!

因此,我们的想法是创建一个平台(白色斑块),让海龟(乘客)等待上车。我想给乘客一个人的形状,给公共汽车一个公共汽车的形状。 目前我确实有乘客在站台等候,但我无法让他们移动到公共汽车上。

除此之外,我不知道如何让公共汽车移动。所以它停在平台旁边,过了一段时间它应该离开。为此,从 1 只大乌龟中制造了一辆大巴士。然后当公共汽车到达时,乘客们去公共汽车上车,编码这个我想让海龟“死”。但是,看起来海龟并没有在我的代码中死去。你们知道我怎样才能让公共汽车到达、乌龟上车(死)和公共汽车离开吗?

我当前的代码:

turtles-own [target trip]
breed [bus a-bus]
to setup

clear-all
  
 
  ask patches with [pxcor = -1 and pycor = -1][set pcolor white]
   ask patches with [pxcor = 0 and pycor = -1][set pcolor white]
   ask patches with [pxcor = 0 and pycor = -2][set pcolor white]
  ask patches with [pxcor = 0 and pycor = -3][set pcolor white]
  ask patches with [pxcor = 0 and pycor = -4][set pcolor white]
  ask patches with [pxcor = 0 and pycor = -5][set pcolor white]
  ask patches with [pxcor = 0 and pycor = -6][set pcolor white]
   ask patches with [pxcor = -1 and pycor = -2][set pcolor white]
  ask patches with [pxcor = -1 and pycor = -3][set pcolor white]
  ask patches with [pxcor = -1 and pycor = -4][set pcolor white]
  ask patches with [pxcor = -1 and pycor = -5][set pcolor white]
  ask patches with [pxcor = -1 and pycor = -6][set pcolor white]
  
  
  
  
  ask n-of Passengers patches with [pcolor = white][set pcolor white                     
    sprout 1[                                                                    
      set color grey                                                              
      set size 1       
      set shape "person"
      set target patches with [pxcor = 3 and pycor = -3]
      set trip 0
  ]]
  
  create-bus Nbus[
    set color red
    set size 5
    set xcor 3
    set ycor -3
    set shape "bus"

]
  
    reset-ticks

end

to go
  ask turtles[
    move-to one-of patches with [pxcor = 3 and pycor = -3]
    if any? neighbors with [pxcor = 4 and pycor = -3] and shape != "bus"          ;; if passenger neighbors this patch, it dies
    [
      die]
  ]
   
    tick
    

结尾

【问题讨论】:

    标签: model netlogo bus


    【解决方案1】:

    我在这里看到的第一个问题是公共汽车有一个单独的品种,但乘客没有一个单独的品种。因此,当您ask turtles 做某事时,总线也会采取该行动。

    您的品种的第二个问题是您的公共汽车品种的命名令人困惑。您使用的第一个名称应该是复数,第二个是单数,而您使用的是单数,a-singular。这只是一个约定,但我建议您尝试遵守它们,否则事情会很快变得混乱。在您的情况下,这将是breed [buses bus]。 我假设您从有 breed [sheep a-sheep] 的 wolf-sheep 模型中复制了您的方法,或者从带有 breed [fish a-fish] 的另一个库模型中复制了您的方法。这两个是例外,因为单数和复数的书写方式相同。这就是为什么他们将“a-”附加到第二个以强调 this on 是单数形式。

    接下来,您不需要move-to one-of patches with [pxcor = 3 and pycor = -3] 的整个构造。相反,只需使用move-to patch 3 -3

    最后,您到底想用if any? neighbors with [pxcor = 3 and pycor = -3] [die] 完成什么? 您首先要求所有海龟移动到补丁 3 -3,然后您要求所有海龟查看它们旁边的补丁是否可能是补丁 3 -3。从来都不是这种情况,因为他们所在的补丁就是那个补丁。 如果你想让他们检查他们所在的补丁,你可以使用patch-here。但是为什么还要检查它们是否在补丁 3 -3 上呢?你只是告诉他们都搬到那里去。

    如果您想扩展模型并让海龟乘坐公共汽车,并可能在下一站下车,我建议您查看链接。例如,tie 原语允许您让 1 只海龟与另一只海龟一起移动。

    【讨论】:

    • 非常感谢!我正在寻找串联模型,但我找不到它......你知道它的确切名称吗?
    • @DwayneJohnson 哦,没有串联模型,或者至少没有我知道的模型。但是模型库中的“Tie System Example”模型可能会为您提供一些关于 tie 如何工作的线索。 programming guide 中也有关于它们的部分
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    相关资源
    最近更新 更多