I plan to do a Monte Carlo Simulation, but the introduction on the AnyLogic page does not really help me. I want to vary one parameter via uniform(0,1) and run the model 1000 times and save the results in a excel sheet.
My idea was to have a variable called "durchlaufzeit" which takes the Model Time at the sink. So in the sink I say durchlaufzeit = Math.round(time())
. Is this a right way to get the total delay time? Or is there any alternative to it?
The commands in the sink look like this:
So at the end of the Discrete Event Simulation I want to write the entire delay time of the simulation into my ExcelSheet
ergebnisse
. I have created a monte carlo experiment in the following way:
In my mind MonteCarlo should execute the code I have written into the sink. However, when I run Monte Carlo I have the following problems:
If I comment out the problematic code snippets the MonteCarlo Experiment is executed but when I look at my Excel Sheet, there is no data written to it (from the code which is place on the sink). Where could I be mistaken?
Here are my findings on your issues
The errors you experiencing in the default UI created for the Monte Carlo experiment are just due to shortcomings of the AnyLogic automatic UI creator.
I don't see any code where you write the durchlaufzeit
value to the excel sheet
Are you sure you are closing the Excel sheet after the experiment? Have you completed the Tutorials and viewed the example model son using Excel files? https://anylogic.help/anylogic/connectivity/excel-file.html#excel-file
That said here is my suggestion:
If you want to run multi experiments, especially in parralele, you have to provide the file that you will be writing to, from out side the model. Else every instance of Main will create, and override the existing file created by other instances...
Thus you need a File object on Monte Carlo (or your normal experiment page) and a parameter on main to pass it to.
I would never use Excel, for various reasons, but rather use a text file. It is small, lightweight, easy to just write in the next line, can be opened in Excel and most importantly - it is thread safe.
So I would have this setup.
It is important to remember to close the text file.
For this simple test I have an event on Main that writes some random data to the textFile
parameter on Main which is of type TextFile
.
After running the Monte Carlo experiment for 10 iterations, I get 10 random numbers in the text file.