1

I need to create a model of a simple train station where I want to have the "unwanted" option to have trains collide without the model crashing with one exception. Is there any chance to avoid the model crashing maybe stopping the two trains colliding when it happens (or just a moment before)? Thanks a lot!

Piero
  • 89
  • 5

2 Answers2

2

Drag and drop Rail Settings and it has a few things for conflict resolution.

On car hit car section allows you to type in any code.

enter image description here

Here are the local variables that you can use:

enter image description here

You can also watch this video from AnyLogic: https://www.youtube.com/watch?v=ERvdz0w_Zgk

Yashar Ahmadov
  • 1,616
  • 2
  • 10
  • 21
  • Thanks a lot! I've found it! Just another question. At the moment I didn't define a specific Agent type, but even if I do, how can I start and stop my car or train? I tried with `rc.stop()` and `other.stop()` to stop the train but didn't work and the exception happened again. – Piero Jan 12 '22 at 16:33
  • On the left side, there is Rail Library. When you click on it, you will see two different agent types at the top (`Train Type` and `Rail Car Type`). You will create your agents from there. Then you can access them with `train.blabla` / `car.blabla` in your model. – Yashar Ahmadov Jan 12 '22 at 16:38
  • You can pause the simulation when collision occurs, for example..with command `pauseSimulation()` – Yashar Ahmadov Jan 12 '22 at 16:40
  • 1
    @Piero always start new issues for new questions, please. StackOverflow does not work like a forum but like a knowledge base :) See https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow – Benjamin Jan 12 '22 at 17:34
1

You can also simply use the outHit port on the TrainMoveTo block: enter image description here

Best do the simple rail-model step-by-step tutorial (hump yard) as it shows how to use it

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • Thanks @Benjamin, I'm exploring this solution too. But I have a related question at this point: If I want to handle everything via `railSettings` block, Anylogic gives me an exception because the outHit output is not handled. In my model, I want to stop any colliding train and `railSettings` `on car hit car` exception handler works fine to me, so is there any way to avoid manually tapping all the outHit exits? – Piero Jan 13 '22 at 11:51
  • I don't think so. In the future, please always open new issues, even for follow-up questions, though. StackOverflow works best this way, see https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow :) – Benjamin Jan 13 '22 at 13:30