How to create a Netlogo model for bus transport (public transport)?

153 Views Asked by At

I am trying to make a simulation of people boarding a public bus in Netlogo. However, I have very little experience with coding. I tried to create it myself, but sadly I'm stuck. So I hope that you can help me out. I will first explain what I want to code, after that I will show my current code. Thanks in advance!

So, the idea is to create a platform where turtles are waiting to board the bus. At the moment I do have passengers waiting at the platform, however I cannot get them to move to the bus.

Besides that I have no clue how to make the bus move. So it stop next to the platform, and after a certain time it should leave. To do this made one big bus from 1 big turtle. Then when the bus arrives the passengers go to the bus and board, to code this I wanted to let the turtles 'die'. However, it looks like the turtles don't die in my code. Do you guys know how I can make the bus arrive, turtles board (die) and the bus leaves?

1

There are 1 best solutions below

5
LeirsW On

A first problem I see here is that you have a separate breed for the bus, but not a separate breed for the passengers. Because of this, when you ask turtles to do something the bus will also take that action.

A second problem with your breeds is the confusing naming of your bus breed. The first name you use is supposed to be a plural and the second a singular, whereas you are using singular, a-singular. This is just a convention but I suggest you try sticking to them, otherwise things can get confusing very quickly. In your case that would be breed [buses bus]. I assume you copied your approach from the wolf-sheep model, where there is a breed [sheep a-sheep], or from another library model with breed [fish a-fish]. These two are exceptions because both the singular and plural are written the same way. That's why they attached "a-" to the second one to emphasise that this on is the singular form.

Next, you don't need the entire construction of move-to one-of patches with [pxcor = 3 and pycor = -3]. Instead, just use move-to patch 3 -3.

Then lastly, what exactly are you trying to accomplish with if any? neighbors with [pxcor = 3 and pycor = -3] [die]? You are first asking all of your turtles to move onto patch 3 -3, and then you ask all of your turtles to look if the patch next to them is maybe patch 3 -3. This is never the case because the patch they are standing on is that patch. If you want them to check the patch they are on, you would use patch-here. But why even check if they are on patch 3 -3? You just told them all to move there.

If you would want to expand the model and let the turtles ride with the bus, and potentially get off at the next stop, I suggest you take a looks at links. The tie primitive for example allows you to let 1 turtle move in tandem with another turtle.