-2

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? enter image description here

The commands in the sink look like this:enter image description here 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:enter image description hereenter image description hereenter image description hereenter image description here

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:enter image description here 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?

DynamiX
  • 63
  • 4
  • Hi, welcome to SOF. You have to be a bit more specific in your very general questions. Add screenshots, try things out first, tell us what you did. Helps a lot in helping you fast, see https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow – Benjamin Mar 15 '22 at 06:43
  • Hi Benjamin, sry for my smattering, I'm quite new to AnyLogic and StackOverflow. I have uploaded some pictures and hope it helps you to understand my problem. – DynamiX Mar 15 '22 at 10:57
  • Beautiful, but still too many questions/problems in 1 issue. Split it into clean, small, specific and clear issues and you will get responses in no time. Have everything in 1 big fat issue with open-ended "is this correct?" questions, and you may wait for a long time :) . Think about how to make *our* lives easy :) We are all happy to help but also incredibly busy :) – Benjamin Mar 15 '22 at 12:27
  • (Don't feel discouraged, we have all been there. Welcome to the world of AnyLogic and SOF :) ) – Benjamin Mar 15 '22 at 12:28

1 Answers1

0

Here are my findings on your issues

  1. 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.

  2. I don't see any code where you write the durchlaufzeit value to the excel sheet

  3. 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.

enter image description here

It is important to remember to close the text file.

enter image description here

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.

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33