Agent is not leaving the Assembler block in AnyLogic - simulation

Agent is not leaving the assembler block while the model keeps runing with out showing any error. The image of Assembler properties is given below.
When I run the model, I act like this all the time.
Moreover, when I limited the number of arrivals to one for the sources, then it worked just fine.Kindly let me know what I am missing and how to solve this issue.

Related

Parameters Variation not running model in AnyLogic

When I create a ParametersVariation simulation, the main model does not run. All I see is the default UI with iterations completed and replication. My end goal (as with most people) is to have a model go through a certain number of replications, but nothing is even running. There is limited documentation available on this. Please advise.
This is how Parameters Variation is intended to work. If you're running 1000 runs and multiple replications with parallel runs, how can you see what's happening in Main in each?
Typically, the best way to benefit from such an experiment is to track the results of each run using elements from the Analysis palette or even better to export results to Excel or similar.
To be able to collect data, you need to write your code in Java actions fields with root. to access elements in main (or top-level agent).
Check the example below, where after each run a variable from main is added to a dataset in the Parameters Variation experiment. At the end of 100 runs for example, the dataset will have 100 values of the main variable, with 1 value for each run.

Considering differences in the same materials - Stations

I am trying to simulate a manufacturing assembly process, where material items are processed following an unique line. In the quality control stations, when a failure is detected, the object is sent to the repair area (by a truckpallet) and, when it is repaired, the same resource takes it and puts it at the start of the line. Until this point, I already programmed it.
The problem is the following: when it is a repaired object, is has to follow the same conveyor but with no stops in the stations. The object must enter a station and leave it, with no delays (as the works related with the stations have already been made).
I thought the best would be to consider the difference (repaired vs. not repaired) in the Agent, but then I can't work with it in the Main agent... I have also tried alternative solutions, for example defining variables in each station 1 and consider that in the stations delays and in the following station:
triangular( 109.1*delay_bec, delaytime_bec*delay_bec, 307.6*delay_bec)
Actions - in finished process:
if(delay_bec==0){
delay_headers=0;
delay_bec=1;}
But nothing worked... Any help?
I thought the best would be to consider the difference (repaired vs. not repaired) in the Agent, but then I can't work with it in the Main agent...
This is actually the correct approach. You need to create a custom agent type, give in a boolean variable isRepaired (or similar) and then in the delay you can dynamically adjust the duration using that characteristic:
agent.isRepaired ? 0. : 100
This will delay normal agents by 100 time units and repaired agents not at all.
Obviously, you must make sure that the agents flowing through the flow blocks are of your custom agent type (see the help how to do that)

data processing of Dymola's result during simulation

I am working on a complex Modelica model that contains a large set of data, and I need the simulation to keep going until I terminate the simulation process, maybe even for days, so the .mat file could get very large, I got trouble with how to do data processing. So I'd like to ask if there are any methods that allow me to
output the data I need after a fixed time step during simulation, but not using the .mat file after simulation. I am considering using Modelica.Utilities.Stream.Print` function to print the data I need into a CSV file, but I have to write a huge amount of code that prints every variable I need, so I think there should be a better solution.
delete the .mat file during a fixed time step, so the .mat file stored on my PC wouldn't get too large, and don't affect the normal simulation of Dymola.
Long time ago I wrote a small C-program that runs the executable of Dymola with two threads. One of them is responsible for terminating the whole simulation after exceeding an input time limit. I used the executable of this C-program within the standard given mfiles from Dymola. I think with some hacking capabilities, one would be able to conduct the mentioned requirements.
Have a look at https://github.com/Mathemodica/dymmat however I need to warn that the associated mfiles were for particular type of models and the software is not maintained since long time. However, the idea of the C-program would be reproducible.
I didn't fully test this, so please think of this more like "source of inspiration" than a full answer:
In Section "4.3.6 Saving periodic snapshots during simulation" of the Dymola 2021 Release Notes you'll find a description to do the following:
The simulator can be instructed to print the simulation result file “dsfinal.txt” snapshots during simulation.
This can be done periodically using the Simulation Setup options "Complete result snapshots", but I think for your case it could be more useful to trigger it from the model using the function Dymola.Simulation.TriggerResultSnapshot(). A simple example is given as well:
when x > 0 then
Dymola.Simulation.TriggerResultSnapshot();
end when;
Also one property of this function could help, as it by default creates multiple files without overwriting them:
By default, a time stamp is added to the snapshot file name, e.g.: “dsfinal_0.1.txt”.
The format of the created dsfinal_[TIMESTAMP].txt is a bit overwhelming at first, as it contains all information for initializing the model, but there should be everything you need...
So some effort is shifted to the post processing, as you will likely need to read multiple files, but I think this is an acceptable trade-off.

ResourceTaskStart problem due to multiple resources in a seize

A little insight into my project:
I am trying to simulate a 6-floor inpatient hospital building. Where the patients that come in stay for a night or two and then leave, super simple. However, I want to add the task so that nurses prepare the patients room beforehand and that has proven to be harder than expected. After having tried multiple different methods I seek for your help for inspiration.
To keep the model as simple as possible I have only one Seize for all the floors due to restriction on the number of blocks. In that Seize I call a function that differs all the floors apart:
The seize for the rooms
The function that differs the floor apart
A similar function is for the nurses, a simple if-sentence that returns the right nurses.
Now for the hard part, the ResourceTaskStart.
I have multiple ResourcePools for this one seize so I haven't been able to connect them somehow together with the ResourceTaskStart. I can't call an agent.parameter as I have been doing in all these functions. I have tried to create a variable that returns a number as seen in my second picture "floor1 = 1" as an example. These variables should direct the nurses to the right location as seen in the following picture.
The ResourceTask set up
As seen in the picture I have ResourcePool for each of the floors that are initiated by the Seize "Rooms". These ResourceTaskStart and MoveTo are as following:
ResourceTaksStart block
MoveTo Block
However, when I run the model I keep getting a different error message for each run and on different time. Sometimes I have 88 patients go through with no problem, then 104 and even 244 patients but there always appears some error like these here:
First run:
Exception during discrete event execution
root.MoveToWard5:
Unit root.ward5 not found in the units seized by 276
Second run:
Exception during discrete event execution
root.MoveToWard8:
Unit root.ward8 not found in the units seized by 265
Third run:
Exception during discrete event execution
root.MoveToWard7:
Unit root.ward7 not found in the units seized by 353
This mismatch in the error message makes it difficult for me to decode and I have no idea why this error is appearing.
My question: Do you have any idea what the problem might be or do you have any idea of a better way to simulate this problem?
If you need any more information please comment and I will provide them.

NullPointerException during Parameter Variation Experiment with agent statistics

at the start of the experiment, I get the error message 'Error in the model during iteration 5 (numbers vary between 2, 3, and 5)' and it points to the agent-statistics Dataset from main that I try to add to a histogram dataset in my experiment. Is it possible that somewhere I try to collect agent statistics before the agents are initialized?
To be more precise about my setting: My root agent for the experiment is an agent called 'firms'. Within that agent, I have added the dataset 'DSUsers', which simply collects the agent statistics (item.inState(Firm....)) located in the main agent. The dataset DSUsers is what I try to add to the histogram dataset 'data' for the parameter variation experiment with the settings described below. (unfortunately, I can't add screenshots yet, I am too young a member...)
In the experiment, I use the following setup:
Before simulation run:
data.reset();
After simulation run:
data.add(root.DSUsers);
DSUsers being the dataset that I collect from the main agent-statistics. The top-level agent of my experiment is not the main agent (could that be a problem?).
So the process looks something like this:
Collecting agent statistics in main -> Using a dataset on the agent-level which collects the statistics from main and stores it -> importing this dataset to a histogram dataset in the experiment.
I get a large error message in the console, the first error pointing to
private double _DSPledgeUsers_YValue() {
return
get_Main().firms.NPledgeUsers()
;}
Found the problem-maker, however, I am not sure why it works:
Somehow the dataset I created in the agent caused all of the agents' states in the statechart to automatically update on every time step. This was a problem in my model because some states were supposed to update only occasionally. So I simply moved the dataset to main.
I do not want to speculate, but if you encounter the same problem, check the location of your datasets!