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.

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:

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

  1. string newValue = "Object current=ownerobject(c); \
  2.    double sampletime=normal(10,1,getstream(current)); \
  3.    return sampletime;";
  4. 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.

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:

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

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

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