I open this new question directly linked to my previous question posted here: Avoid Exceptions after a train collision in Anylogic
In a rail scenario, we use blocks to control and make run/stop trains. In the most simple scenarios, where trains and rail cars have no specific proprieties to embed, Trains and RailCars can be normal Agents. In a TrainMoveTo block, we simply specify the acceleration and speed of the train and it moves consequently toward the specified target.
My scenario uses a RailSettings block to capture the event "On car hit car". Its parameters are:
RC car
— the car
boolean frontside — the side of the car that hits another car (true if front side)
RC other
— another car
RailwayTrack track
— the track where this is happening
RailwayNetwork railYard
— the rail network defining the railyard
if I call car.something
, Anlylogic handles it as a simple Agent and I'm wondering, which function should I access to specify the very same information that I order via "TrainMoveTo" blocks? I tried with a simple car.stop()
to make the train stop, but it didn't work.
The same question rises too in the very same case I want to create a specific Train and RailCar function and I want to control train parameters via code.
Can Anyone help me to understand this? Thanks a lot! Piero
This is the basic "trick" of agent-based modelling: Make the source block create not "Agent" agents but agents of your specified agent type:
Create agent types as needed, make sure they are flagged as Train or Rail car in the agent-type properties (see below) and make the sources create these. Then, it will be instances of that agent type flowing through your model and you can access their characteristics:
Best do all step-by-step tutorials in the AnyLogic help, they use this a lot (and it is a very core concept for everything) :)