'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
- Defined the variables
startTimeendTimecycleTimein the agent class Patient which is being pushed through the model. - Put
agent.cycleTime=agent.endTime-agent.startTime;in the On enter slot of the block in which I want the timing to end. - Defined a Histogram Data called
myDataSetwith the Valueagent.cycleTimein Main - Made a histogram in Main which takes
myDataSetin 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:
- Wherever timing should start, you write
agent.startTime = time()(logs curr model time) - Wherever timing should end, you write
agent.cycleTime = time() - agent.startTime, essentially measuring how much time has passed since the start. - 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): 
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 |
