question

Andrew McNitt avatar image
0 Likes"
Andrew McNitt asked Andrew McNitt commented

Replacing cycle time with code sequence

I am creating a model where processors and multiprocessors are created through flexscript commands. I'm attempting to also change the cycle time to a triangular distribution through flexscript, that uses the incoming items label to set the parameters on the distribution. When I try to set the cycletime node value to user command code for triangular distribution, it executes it instead of setting the value equal to the distribution command. Is there a way to have the node value equal to the distribution command so it's dynamic for each item iteration?


example:

item.Process_Time = 50

getvarnode(Model.find(stationname), "cycletime").value = triangular(item.Process_Time*.9,item.Process_Time*1.1,item.Process_Time,getstream(current))

Sets the process time to results of 50 on a triangular distribution instead of the expression below.

1704055924238.png

1704053430494.png


FlexSim 22.2.0
flexscript codingprocesstime distribution
1704053430494.png (12.5 KiB)
1704055924238.png (10.2 KiB)
5 |100000

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

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Andrew McNitt commented

You should be able to dynamically assign the cycletime value but there are probably better ways.

Put the triangular expression in the processor field and then open the code to see what you need to assign to the cycletime node as a string. You'll see it's this:

Object current = ownerobject(c);
Object item = param(1);
return /**/triangular(item.Process_Time*.9,item.Process_Time*1.1,item.Process_Time,getstream(current))/**direct*/;

When you set the node to a different string you'll need to build it as flexscript using buildnodeflexscript().


Instead of this approach you could just put the cycle time function on the item itself and keep the processor's cycletime as item.Process_Time.

Example of that attached.

processTimeOnItem.fsm

Both approaches a somewhat limited in that they don't scale to multistage/step processes and equipment - for that you'll need a more complex structure involving tables or maps.


· 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.

Andrew McNitt avatar image Andrew McNitt commented ·

What you mentioned with the buildnodeflexscript() function is what I did as a work around for my regular processor. I used your answer here as a concept to create an entry trigger to use my Triangular Process Time user command. This works for a regular processor. My bigger issue was trying to replicate this same idea on a multiprocessor. Could I reconfigure the parameters of the buildnodeflexscript() differently to apply that concept to each process in the multiprocessor, and would it update the item value on each iteration if it was to change? Say process 1 takes 50 seconds, process 2 takes 100, and process 3 takes 150. The on process finish trigger would update the items local process time label to each of those values, but would the code be able to evaluate that change each iteration?


sample of my entry trigger code:

treenode attrHolder_P = Model.find(stationname);

treenode onEntry = function_s(attrHolder_P,"assertEvent","OnEntry");

onEntry.value = Model.find("Tools/UserCommands/Triangular_Process_Time/code").value;

buildnodeflexscript(onEntry);

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Andrew McNitt commented ·

You should be avoiding function_s calls where you can. This entry trigger looks to be changing its own code and not that of the process time - is that right - seems an incorrect approach. If you have different user commands to execute then use a case statement to do so, or find the command node by name and execute it. All this dynamic changing seems excessively messy.

If you need to post an example or your model then you can switch this post to private and maybe then we can suggest a better approach for you.

A user command to return the process time seems better where you pass the item the equipment and the process step.

0 Likes 0 ·
Andrew McNitt avatar image Andrew McNitt Jason Lightfoot ♦♦ commented ·

It probably isn't the right approach but it works, at least on the processor. The function_s and buildnodeflexscript() calls create the entry trigger node for each created processor in the model and then runs the below script where it changes the processor's cycletime node value on each item entry. I would like a different approach if there is a good option. The dynamic nature is necessary because my project is creating a fully automated model build through database inputs and user command execution.


entrytrigger script:

Object current = ownerobject(c);

Object item = param(1);

int port = param(2);


string station = current.name+(">variables/cycletime");

Model.find(station).value = triangular(item.Process_Time*.9,item.Process_Time*1.1,item.Process_Time,getstream(current));

0 Likes 0 ·
Show more comments
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Andrew McNitt edited

You want exchange a compiled source code. You can try such by SDK. But inside FlexSim you will see that a cycle time is function returning a value.

You can replace function parameters by FlexsSim Parameters or labels.
You can try to let execute a string that you build somewhere else.

· 1
5 |100000

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

Andrew McNitt avatar image Andrew McNitt commented ·

I'm not familiar with SDK, but perhaps that is an option. I tried using the execute string function but ran into some snags there as well with it wanting to execute on creation instead of in place of the standard cycle time function. I got around it on regular processors by building a node for entry triggers to run the user command, but I haven't found a way to do the same on multiprocessors. They are proving more challenging with their different structure for each individual process step.

0 Likes 0 ·