Define process time using Code Snippet

Define process time using Code Snippet

jonperez
Not applicable
13 Views
9 Replies
Message 1 of 10

Define process time using Code Snippet

jonperez
Not applicable

[ FlexSim 23.2.1 ]

Hello, I would like to know if there is any way to define the process time of a combiner by using Code Snippet. I attach a picture of the code where I want to define the process time with normal distribution.

Code Snippet.png

0 Likes
Accepted solutions (1)
14 Views
9 Replies
Replies (9)
Message 2 of 10

iago_mf
Not applicable

Hi, you can set value of properties with the method setProperty, for example:

Object combiner = Model.find("Combiner1");
double newValue = 50;
combiner.as(Object).setProperty("ProcessTime", newValue);

If the owner of the code snippet is the combiner, you have the reference as current:

Object combiner = current;

Depending on the case, it might be sufficient for the processing time to depend on that information, so you could use a custom code in the 'Process Time' cell. In this code, you should return the value according to the conditions you desire.

1704801188752.png

I hope it helps you!

0 Likes
Message 3 of 10

jonperez
Not applicable

how do I have to add it to the code in order to have a normal(10,1) process time?

0 Likes
Message 4 of 10

iago_mf
Not applicable

You just have to write the reference to that distribution in FlexSim with the correct parameters, for example:

Object combiner = Model.find("Combiner1");
double newValue = normal(10,1);
combiner.as(Object).setProperty("ProcessTime", newValue);
0 Likes
Message 5 of 10

jason_lightfootVL7B4
Autodesk
Autodesk
Accepted solution

The process time value can be: a numeric single value; a string expression that is evaluated to lookup or generate a number, or multi-line code that does the same (also string).

When you say you want to "define the process time by code" it can mean two things - you can:

1) have that code as the process time expression/script to fire for each item

2) write the value/expression/script into the process time property using code (triggered elsewhere)

Of course you could be doing both of those things - trigger a script that writes an expression or script to the process time property (last example below).

Examples:

combiner.setProperty("ProcessTime", normal(10,1)); //writes a random value once  to the combiner - eg. 10.5 will be used until you set another value.
combiner.setProperty("ProcessTime", "normal(10,1,getstream(ownerobject(c)))"); // writes the single line  expression to be evaluated each time a process time is needed.  (notice no semicolon at the end of the expression)

Lastly the code to write the script will look like this where the lines are seperated by semicolons and crucially the process time is returned by the script we supplied.

string newValue = "Object current=ownerobject(c); \
   double sampletime=normal(10,1,getstream(current)); \
   return sampletime;";
combiner.setProperty("ProcessTime", newValue); 

Note the last two examples generate the same random samples.


0 Likes
Message 6 of 10

jonperez
Not applicable

Thank you! Can I add here on code snippet?

Screenshot flexsim.png

0 Likes
Message 7 of 10

jason_lightfootVL7B4
Autodesk
Autodesk

Do you want to write the value dynamically in code or do you just want it as a fixed expression (in which case you can type directly into the process time field the normal expression)?

If you want to write it dynamically then when do you want that to happen? An exit trigger will be too late for the current item for example.

0 Likes
Message 8 of 10

jonperez
Not applicable

Hello Jason, I want that depending of the counter to have a different process time. For example, if the counter is 10 or less, to have a normal(10,1) process time and if the counter is between 10 and 20, to have a normal(15,2) process time. Is there any way to achieve in by writing it on the oxit or entry trigger of the combiner with the code snippet?


How would I need to add that on the code of this screenshot? And if it cannot be done, how would I need to do it?

Code Snippet.png

0 Likes
Message 9 of 10

moehlmann_fe
Observer
Observer

If the distribution and its parameters are dependent on values that are known/accessible when the process time is determined, you can write custom code in the Process Time field that does this. There is no need to set the process time from elsewhere.

process-time-fm.fsm

And even if the values are not known at that time, I would still recommend to write code that uses (for example) a label on the combiner to determine the process time and only change that label externally, not the entire code.

0 Likes
Message 10 of 10

Jeanette_Fullmer
Community Manager
Community Manager

Hi @Jon Perez, was one of Jason Lightfoot's or Iago MF's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.

0 Likes