question

Noah Z avatar image
0 Likes"
Noah Z asked Noah Z commented

How to add code to switch MTBF/MTTR on and off during model run

I'd like to employ a user event to periodically check whether or not a condition has been met during a model run. If the condition has been met I want to add one or more processors in my model as members to a MTBF/MTTR. Is there a straightforward way to add members to a MTBF/MTTR using code?

FlexSim 17.0.0
mtbf mttrmemberadd
5 |100000

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

Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered Noah Z commented

There is a variable "enabled" in the MTBF/MTTR, but it has to be set before reset - it seems to be meant purely to enable/disable the event in its properties (checkbox at the top right) or from the Experimenter.

If you know beforehand on which object you may want the event to apply, you can also change the Down Function and Resume Function. For example, the Down Function by default does

stopobject(downobject ,state, id, priority);

It is pretty straightforward to put an if-statement with your condition around this and just make the trigger do nothing if the condition has not been met.

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

Noah Z avatar image Noah Z commented ·

Thank you!

0 Likes 0 ·
Joerg Vogel avatar image
2 Likes"
Joerg Vogel answered Noah Z commented

from the previous forum, I found this. The command is memberadd(). But you should look into the link, too.

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

Adrian Haws avatar image Adrian Haws commented ·

@Noah Zenker This is how you would add a processor to an MTBF/MTTR:

treenode theobject = model().find("Processor1");
memberadd(theobject, "MTBFMTTR1", 2);

However, as @phil.bobo mentioned in the forum post, this should be done before resetting your model. I don't think you would be able to do this during a model run, but I may be mistaken.

1 Like 1 ·
Phil BoBo avatar image Phil BoBo ♦♦ Adrian Haws commented ·

The Toolbox > Modeling Logic > Model Trigger > On Reset code fires before the reset triggers of all the objects, so if you need to execute code before your model is reset, you can execute it there.

1 Like 1 ·
Noah Z avatar image Noah Z commented ·

Thank you!

0 Likes 0 ·

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.