question

Craig DIckson avatar image
0 Likes"
Craig DIckson asked Matt Long commented

Delay in Process Flow custom logic?

Is there a way to delay a token in a process flow custom logic activity? This would greatly simplify my model.

I tried to delay by calling executesubflow(); and having a Delay Activity in the subflow, but it doesn't seem to hold the token at that line in the custom logic as I had hoped.

Thanks

Craig

Choose One
process flowdelay
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

You can't just add a delay activity after your Custom Code activity? What are you actually trying to do?

0 Likes 0 ·
Craig DIckson avatar image Craig DIckson Phil BoBo ♦♦ commented ·

Phil,

My delays are in the middle of several nested while loops that use some fairly complicated findmax() statements to decide what to do - and each loop represents a single task or sub task. I can of course replicate the logic using a bunch of Set Label and Decide Activities, but it is much simpler (and more intuitive) to just do it in code.

Maybe in the next version??? I am sure there is an underlying reason, but from a user's perspective it seems like a pretty artificial limitation -- it seems like I can do absolutely anything in code EXCEPT delay....and time is what simulations are all about.

Cheers,

Craig

1 Like 1 ·
Phil BoBo avatar image Phil BoBo ♦♦ Craig DIckson commented ·

This isn't some artificial limitation. This is how programming works.

A computer executes one line of code at a time. When it is done executing one line, it moves onto the next line.

You are writing your code with the expectation that other code in your model is going to be running at the same time. If your while() is waiting for something to change external to the code within the while() loop, then your while() loop is going to be infinite. This is how programming works.

FlexScript code executes immediately as computer code. It is not a logic builder that runs in simulation time using discrete events being processed within the simulation timeline like ProcessFlow activities. You can't arbitrarily delay the code execution in the middle of the code based on simulation time.

2 Likes 2 ·

1 Answer

·
Matt Long avatar image
1 Like"
Matt Long answered Matt Long commented

No, you can't delay a token in a Custom Code activity. This activity calls a flexscript node and then immediately moves on. There isn't anyway to stop the token from moving to the next activity.

Execute subflow is just like calling a user command. Any delays or events created in the sub flow won't be executed until after the token has left the Custom Code.

I don't know what your model looks like, but you could use a Run Sub Flow activity who's sub flow has a Custom Code and a Delay activity in it. This would effectively turn your two activities into one, but this is only useful if you're calling the same Custom Code and Delay multiple times from multiple locations.

· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Craig DIckson avatar image Craig DIckson commented ·

Matt,

Thanks. Honestly, that seems like a serious limitation to using custom logic. My loop structure is so much simpler when written as code than it would be using process flow activities e.g decide.

Please please consider this a feature request. I can tell you for certain that your competitors (AnyLogic) does allow this in their direct analog to ProcessFlow, and it makes things MUCH easier.

Regards,

Craig

0 Likes 0 ·
Matt Long avatar image Matt Long Craig DIckson commented ·

Process Flow activities are designed to be simple. Each activity performs one task or one piece of logic. This was done very specifically. By allowing you to put delays into your custom code you're now just duplicating the logic of a Delay activity. This goes against the fundamental design of Process Flow.

If you'd like to post your logic we'd be happy to look at it and see if there is a better way to do whatever it is you're trying to accomplish.

1 Like 1 ·
Craig DIckson avatar image Craig DIckson Matt Long commented ·

Matt,

For what it's worth, even though your philosophy was to make Process Flow simple for non-programmers, Process Flow mode still ended up nearly identical to AnyLogic's main method of programming, which is specifically aimed at computer scientists or at least programmers (i.e. any engineer under 35). To be sure, FlexSim PF has some nice additional features ... and this one major limitation.

WRT the suggestion of placing my code in a Delay activity ... I have multiple different delays in the same task, but I can't just add up the delays and take the whole delay at the end, as specific pieces of data have to be manipulated after each delay. I can (and I guess I will have to) do it using a series of Decides, but it is just plain uglier.

And as I mentioned in my reply to Phil, it seems like an artificial limitation - why is delay virtually the only thing I can't do in Custom Code? It feels odd, given that everything else in FlexSim is almost ludicrously flexible.

Craig

1 Like 1 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.