0

I have a model of a supply chain in which my agents "Product" pass through blocks in some agents (i.e. "Vendor", "Factory", "Wholesaler", and "Retailer") and I have a flowchart block in which the said agents in the supply chain use it. I would like to measure the time my agent "Product" spent, which its TimeMeasureStart is in for example its "Vendor" page and its following TimeMeasureEnd is in the said flowchart block like this. Now I have difficulty defining TimeMeasureStart in the TimeMeasureEnd block in the flowchart block.

I tried to use getRootAgent() but this way I couldn't access the timeMeasureStart block of the root agent so I couldn't try this. Also tried to define a variable in the flowchart block page like this (and I know this way is wrong but I have no idea how to define a variable to suit TimeMeasureStart) and then use it to define the corresponding TimeMeasureBlock the "Product" had passed: timeMeasureEnd Properties

but it gave me these 2 errors:

Type mismatch: cannot convert from TimeMeasureStart[] to TimeMeasureStart.
Variable must provide either dimension expressions or an array initializer.

Also tried set_startObjects but I didn't understand how to work with it and couldn't find the documentation in AnyLogic Help. I really would appreciate any help. (Also so sorry if the images are blurry, I don't know why their quality gets like this when I upload them.)

1 Answers1

0

Either use

((Main)getRootAgent()).timeMeasureStart()

Or simply use

main.timeMeasureStart

Both take you back to Main. The former uses type casting, the latter is a direct link created by AnyLogic (assumes your timemeasureStart is in an agent embedded in Main)

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • @Banjamin Thank you so much for your quick response, but the thing is the timeMeasureStart is not in the main. Some agents are embedded in the main (like Vendor) and the timeMeasureStart blocks are in those agents. But I can't use something like `main.vendors(id).timeMeasureStart` either, because different agents (all embedded in the main) use this flowchart block not just one of them. What should I do in this case? – Narges Hajloo Jan 19 '23 at 23:37
  • Either share your actual model hierarchy (it all depends on that) or learn how to navigate through your model via https://anylogic.help/advanced/code/access.html#where-am-i-and-how-do-i-get-to – Benjamin Jan 20 '23 at 06:09