'agent cannot be resolved to a variable when timing segments of AnyLogic model

In the model, I need to time segments in which some agents go through, but not all, rendering the use of timeMeasureStart and End blocks ineffective as any agents who go through a certain End block MUST go through it's corresponding Start block, but not all agents that will encounter the End block will have gone through it's corresponding Start block.

I have done the following and receive the error that 'agent cannot be resolved to a variable' in the Histogram

  1. Defined the variables startTime endTime cycleTime in the agent class Patient which is being pushed through the model.
  2. Put agent.cycleTime=agent.endTime-agent.startTime; in the On enter slot of the block in which I want the timing to end.
  3. Defined a Histogram Data called myDataSet with the Value agent.cycleTime in Main
  4. Made a histogram in Main which takes myDataSet in it's Histogram slot.


Solution 1:[1]

First, you can still use TimeMeasureStart/end blocks. Just let some agents bypass them with a SelectOutput block upstream of the TimeMeasureStart block. The condition would be determined by who should be measured.

Ok, then to your details:

Put agent.cycleTime=agent.endTime-agent.startTime; in the On enter slot of the block in which I want the timing to end.

This is not how you would measure time. The variables are a good start, though. Do this instead:

  1. Wherever timing should start, you write agent.startTime = time() (logs curr model time)
  2. Wherever timing should end, you write agent.cycleTime = time() - agent.startTime, essentially measuring how much time has passed since the start.
  3. Now you do what you want with agent.cycletime

Defined a Histogram Data called myDataSet with the Value agent.cycleTime in Main

this is not how you use Histogram Data. You need to use the API calls on it properly, for example myHistogramData.add(someValue): enter image description here

Also, always check example models and the help, many issues can be solved by checking those first :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Benjamin