1
votes

I am simulating the passenger changeover process in metros using the Anylogic Pedestrian Library.

When passengers enter the vehicle, a seat is assigned to them from the seats available near the door (within a given distance) they entered the vehicle through, using a function called lookForSeat. If there is no more free seat available, their boolean parameter wantToSit is set to false and they will stay standing.

The parameter wantToSit is predefined for the Passenger Agent, with default value randomtrue(0.8). But even if I set it to default value = 1, I get the same error.

Then, passengers are separated using a PedSelectOutput block:

  • Condition 1: if ped.WantToSit = true --> they are sent to their assigned seat coordinates (PointNode 'seatPoint', null by default)
  • Condition 2: true (thus, ped.WantToSit = false) --> they stay in the standing area in the vehicle, no assigned seatPoint necessary in this case.

Now, it works pretty well, but when the majority of the seats is already occupied, suddenly the PedSelectOutput block directs a passenger with ped.wantToSit to its seating point, which gives null and I get the NullPointerException error.

Attached you find the function, the settings of PedSelectOutput and the log from the command.

As it can be seen, the PedSelectOutput sends the passenger through exit 1 (which gives the error due to calling the coordinates of a "null"), despite ped.wantToSit = false.

Any ideas, what is going wrong? For me it really looks like the function is working properly - I have been changing it the whole day until I realized that something in the PedSelectOutput block goes wrong.

Thank you in advance!

Pic 1: pedSelectOutput block and the command with the log

Pic 2: the function lookForSeat assigning the seats from the seat Collection

1
In which block do you call lookForSeat?Jaco-Ben Vosloo
There is a pedEnter block where the peds enter the inside of the vehicle. In this block, on exit, the function is called, before going into the pedSelectOutput block.Tóth Balázs

1 Answers

0
votes

The problem here is a subtle one, which has caused me many hours of debugging as well. What you need to understand is that the on exit code is only executed once the agent already has a path to which it is going to exit. i.e. the selectOutput and subsequent blocks are already evaluated and only once it is determined that the agent can move to the next block then the on exit code is called. But the agent will continue on its chosen path that has been determined before the on exit code has been executed.

See the small example below:

I have a pedestrian with a variable that is true by default and a select output that checks this value

enter image description here

If I ran the model all pedestrians exit at the top option, as expected

enter image description here

If I change the variable to false on the On Exit code I might expect that all pedestrians will now exit at the second option

enter image description here

But they don't there is no change....

If I add the code to the on enter code then it does..

enter image description here