0

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 Answers1

0

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.

LeirsW
  • 2,070
  • 4
  • 18
  • Thank you vert much! I'm trying to find the tandem model, but I can't find it... Do you know the exact name of it? – Dwayne Johnson Oct 12 '22 at 10:26
  • @DwayneJohnson Oh there is no tandem model, or at least not one that I know of. But the "Tie System Example" model in the model library might give you some clue as to how ties work. There is also a section on them in the [programming guide](https://ccl.northwestern.edu/netlogo/docs/programming.html#tie) – LeirsW Oct 12 '22 at 12:00
  • Ooh I see, I read it wrong. I looked at the example model, but I don't really understand it to be honest. However, I adjusted my code somewhat (see above). I want to let the turtles board the bus, to represent that I let them 'die' when they are in it. Because you "can't" see people in the bus. This works now. After that you can press on the button 'drive' and the bus will drive. However, I have a problem with creating the passengers. When they are created, I want them to only be at the white patches. This works now, however I can only do this with 12 turtles. How can I increase this number? – Dwayne Johnson Oct 12 '22 at 17:38
  • @DwayneJohnson You create all your passengers by letting a patch `sprout` them. You could for example `create` them yourself and move them to the patches afterwards, or you could let the patches `sprout` them but use a construction using a loop to keep sprouting until you have enough turtles, instead of letting every patch `sprout` at most once, as you are doing right now. – LeirsW Oct 13 '22 at 13:28
  • By the way why are you even still using an `if`? You are forcing the turtles to move to that spot so the condition is always true. – LeirsW Oct 13 '22 at 13:29