How to control trains via code in railways scenario in Anylogic - anylogic

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) :)

Related

How can I use a static population of agents with a pedestrian model?

I am trying to make a model to simulate the contagion of covid in public spaces using a mix between SEIR and pedestrian models. and I was stuck when using my population of agents with the pedestrian library.
Looking in the documentation about pedSource I was able to make it add the agents it created to the population. but I want that when the agent leaves the space of the simulation it is not deleted and then that agent can reappear through the entrance.
For this reason I am using a pedEntry and pedExit and send the agents to another space where they wait in queues until they return to the main space of the simulation.
Is there any documentation that talks about using a static population with the pedestrian library?
You can convert your peds into normal agents if you like. You should do that as soon as you do not need the pedestrian capabilities, as they eat a lot of processing power.
Simply create a normal agent type and duplicate the parameters that you need.
Then, create an agent in PedSink using the ped's characteristics before it is destroyed.
Pro tip: You can even use a parent agent type that your PedAgent type and your normal AgentType inherit from. It can hold all the characteristics, so no need to duplicate elements ;)

Moving agents with other agents using Pickup/Dropoff from PML in Anylogic without duplicate code

Info: The question was updated with more explanation
I want to transport a agent (e.g. bananas) with a moving agent (e.g. truck) from place A to place B, where, for example, place A is where the bananas where plucked and place B is some storage for the bananas. So the bananas are simply being transported by the truck. Especially, the agent to be moved (the bananas) are not a resource (in the sense of Anylogic PLM) and have no upper amount limit.
There are various ways to solve this problem, but most of them either require some element in the model that I don't need or want (for example, a rack/pallet system in the case of the block 'Rack Store') or require the agents to be Anylogic resources.
As described in this answer, it kinda makes sense to use pickup and dropoff for this task. The problem is that the agent to be moved is not being transported, so that answer does not solve my question. To explain further, when the agent to be moved (the bananas) are being dropped off at the target location (place B), they simply re-appear at their original location (place A), even though the truck which picked them up via the pickup block has moved to place B.
I made a minimal example of this here.
As I described, the 'transportation' only works if I add the separate 'moveTo1' block for the dropped off agents.
Is there any simple and obvious way to handle this rather simple task of transportation in Anylogic without having multiple move blocks or other workarounds? I know there is 'ResourceAttach', but that requires the agent to be moved to be resources, and there is 'RackStore', which requires a rack/pallet system, which I don't need or want in my model.
What I want to know is what the 'standard' Anylogic way would be to do this.
Thanks a lot in advance!
Now I understand what your problem is...
When you use dropoff, the block that comes after it needs to define the new location of the agents, otherwise they stay in the same place.. You can use the moveTo block with a jump so the agents are teleported to the location you want them to be:
In almost all the blocks of the PML you can define the agent location in the properties, and this is a case where using that property is necessary.
You can set the position of the bananas to the position of the truck.
e.g. using agent.setXY(container.getX(), container.getY()) in the "On dropoff" field.
It seems to work for a simple test model.

BPMN Combining Collaboration Diagrams or using Call Activity

Let's say I have a collaboration diagram that models a process named CheckMessage which is quite complex and spans over few lanes and pools. Now I would like to model another process, e.g. CreateMessage which would make use of the previous process to check first if message doesn't exist already or if all its fields are valid, etc.
The thing is, that both processes make use of the same swimlanes and pools. What is the proper way to model such interactions? I was thinking to model CheckMessage as a sub-process of CreateMessage, however sub-processes can't be attached to pools or lanes - if I understand it correctly they just stay within a lane of activity which invoked them. Can a Call Activity encapsulate such beahviour (cross pools and lanes)? Or can I somehow reference the CheckMessage diagram as a whole?
Thanks in advance.
I could think of the following approaches:
Using Diagram Reference: This is used quite often when you want to switch easily to the more complex part. The disadvantage is that, unlike Fragments in SDs, you do not have ways to really connect flows in and out of referenced diagrams.
Repeating parts of the process: here you just pick those actions from the complex process which ought to interact with the other process. You can highlight that by putting a boundary around these and adding a diagram reference as described above.
Call Activity: This is another valid way. Here you have an activity which you instantiate as action. The advantage here is that you can add pins for input and output parameters.
I guess there is no silver bullet and you have to choose what is appropriate in each case.
Edit Regarding #3 it looks like that:
(this is an example and not to be used in practice)
The Action to the right is an instance of the Activity as you can see by Ctrl-L (show parent).

Generating sub-systems based on user input (MATLAB/SimMechanics)

The user in this webinar;
http://www.mathworks.com.au/videos/parameterizing-bodies-68850.html?form_seq=conf1134
can create new levels of links for the scissor lift by copy pasting the sub systems.
I was wondering if there was any way the number of subsystems and the joints could be automated via user input.
i.e a gui which allows the user to input the number of levels in the scissor lift and that number of levels (subsystems) is generated in SimMechanics.
If someone could provide a solution I could adapt it to the problem I'm trying to solve.
Thanks in advance!
Yes, you can automate it, as long as you know what susbsytems and what joints you want to add. The functions of interest are:
add_block(path_to_your_subsystem,path_to_destination_subsystem) (I assume your susbsystem is stored in a library). You probably want to specify the 'Position` parameter so that all blocks don't end up on top of each other. It will take some experimenting to find coordinates that work for your model and that are parameterised based on the number of susbystems to add.
add_line(path_to_subsystem_of_interest,path_to_output_port,path_to_input_port). You'll need to know which port you want to connect to which and figure out how many times you need to do this based on the number of subsystems to add. Simscape and SimMechanics are a special type of ports, and you need to refer to them correctly otherwise it won't work, see Programatically connect two subsystems for more details (note: this is undocumented as far as I know and is therefore likely to change in a future release).
So in short, yes it's possible (I've done it in the past), but it's by no means easy. See this blog for a very simple introduction.

how to isolate a part of car model in simulink

I have a simulink car model which includes different part of a car obviously (subsystems):). I want to isolate a part of this model, for example, brakes, and feed in dummy variable as inputs.
My problem is that this model has few bus selector and creator, which makes it a little bit complicated. I wonder how I can isolate the brakes part without messing up the buses.
When you say isolate, do you mean you want to move the contents of the subsystem into a separate model? If so, one way to do this is to use the "Convert to Model block" tool. To use this,
Make sure the subsystem is atomic (set_param(subsys, 'TreatAsAtomicUnit','on');).
Right-click on the subsystem and choose Convert to Model block.
The tool might ask you to make a few changes to the model.
At the end of the process, you will have a new model with the contents of the subsystem, and the tool will create any bus objects that are needed.