0
votes

I'm trying to create an agent statechart where a transition should happen every day at 4 pm (except weekends).

I have already tried: 1. a conditional transition (condition: getHourOfDay() == 16) 2: A timeout transition that will "reinsert" my agent into the chart every 1 s and check if time = 16.

My code is still not running, does anyone have any idea how to solve it?

enter image description here

This is my statechart view. Customer is a single resource that is supposed to "get" the products out of my stock everyday at 4pm. It is supposed to happen in the "Active" state.

enter image description here

I have set a timeout transition (from Active-Active) that runs every 1s.

enter image description here

Inside my "Active" state in the "entrance action" i wrote my code to check if it is 4 pm and run my action if so.

I thought since i set a timeout transition it would check my condition every 1s, but apparently it is not working.

2
would be helpful if you show your statechart... and since you ask a lot of questions in stackoverflow, you should start marking those that got answered... you have never done that. - Felipe
a few options why your transitions don't work: the current state doesn't have the transition you want, your condition is never evaluated, your simulation never gets to 4pm... that's what I can think of - Felipe
Thank you for your comments Felipe, I just added the statechart pictures to the question. Also, thank you for warning me about the question marking, i did not know i could do that. - Renata mariani

2 Answers

1
votes

Your agent does not enter the Active state via an internal transition.

Redraw the transition to actually go out of the Active state and then enter it again as below: enter image description here

1
votes

Don't use condition-based transitions, for performance reasons. In your case, it also never triggers because it is only evaluated when something happens in the model. Incidentally, that is not the case at 4pm.

re your timeout approach: Why would you "reinsert" your agent into its own statechart? Not sure I understand...

Why not set up a schedule or event with your recurrence requirement and make it send a message to the statechart: stateChart.fireEvent("trigger!");. In your statechart, add a message-based transition that waits for this message. This will work.

Be careful to understand the difference between the Statechart.fireEvent() and the Statechart.receiveMessage() functions, though.

PS: and agree with Felipe: please start using SOF the way it is meant, i.e. also mark replies as solved. It helps us but also future users to quickly find solutions :-) cheers