question

Jon Perez avatar image
0 Likes"
Jon Perez asked Jeanette F commented

Define process time using Code Snippet

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

FlexSim 23.2.1
processtime
code-snippet.png (18.2 KiB)
· 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.

Jeanette F avatar image Jeanette F ♦♦ commented ·

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 0 ·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Felix Möhlmann commented

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.


· 4
5 |100000

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

Jon Perez avatar image Jon Perez commented ·

Thank you! Can I add here on code snippet?

Screenshot flexsim.png

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Jon Perez commented ·

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 0 ·
Jon Perez avatar image Jon Perez Jason Lightfoot ♦♦ commented ·

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 0 ·
code-snippet.png (18.2 KiB)
Show more comments
Iago MF avatar image
0 Likes"
Iago MF answered Iago MF commented

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!


1704801188752.png (17.6 KiB)
· 2
5 |100000

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

Jon Perez avatar image Jon Perez commented ·

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

0 Likes 0 ·
Iago MF avatar image Iago MF Jon Perez commented ·

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