question

Jason Merschat avatar image
1 Like"
Jason Merschat asked Jason Lightfoot edited

How to update Process Flow Variables by Changes in Model?

I would like to use Process Flow Variables to be set to a current condition in the model say: the number of resources acquired from various Acquire Resource activities. I would use this to limit the number of tokens entering a zone. The issue I am seeing is that there is no way to update these variables except manually. I would think that I could define a variable and set it wherever I wanted and am confused by the literature and explanation of this. I don't want to use a token label in this case as a variable would be much easier should I have access to set it or link it to nodes/activities. It would dynamically update and reflect the current condition for which my expression to be evaluated against anywhere in the model.

So the question is, Can I update the Process Flow Variable in the model using Custom Code activity? If so how?

FlexSim 18.0.2
process flow variable
· 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.

Sam Stubbs avatar image Sam Stubbs ♦ commented ·

If you want to limit the number of tokens in a Zone. Could you not simply use Partition or Subset constraints?

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

The Process Flow object itself can also have labels. You just use current.MyLabel instead of token.MyLabel.

0 Likes 0 ·
Joaquin G9 avatar image Joaquin G9 commented ·

Hello everyone, I'm trying to update a process flow variable with a Custom Code in Set Variable activity, but nothing works. I need to do something very easy, like that:

Variable=Variable+1;1655790721314.png

Does anyone know how to do it?

0 Likes 0 ·
1655790721314.png (33.7 KiB)
Joerg Vogel avatar image Joerg Vogel Joaquin G9 commented ·
Hello, @Joaquin G9 , welcome to FlexSim answers site. Unfortunately this answers site has got a different philosophy than a bulletin board. Please ask new questions rather than append an own question at an already accepted answer. If you do so, you can provide more details like a version you need an answer for. It is a good practice to reference an accepted answer which relates to your question, too. If you want to get familiar with this answers site, please consider to take a look into best practices for using this answers site. You find it under the headline things to know on every page of this site.
2 Likes 2 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Joaquin G9 commented ·

Make sure you have the variable window open showing the value - use the "View Variable" button.

dynamic-flowitem-request_jl.fsm

0 Likes 0 ·

1 Answer

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Kurt De Cock commented

You can set the value of the variable to be a snippet of code. Then whenever something gets the value of the variable that code is executed which could return different values.

For example, you could set the value to be:

Table("GlobalTable1")[1][1]

This will return the value of the first cell in GlobalTable1. You can update the value of that global table cell and then the process flow variable will have a different value when it is used later.

In your case, if you want the variable to be set to the number of resources acquired you could set the value to be:

getstat(getactivity("ProcessFlow", "Resource"), "Content", STAT_CURRENT)
· 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.

Jason Merschat avatar image Jason Merschat commented ·

Thank you Matt. I appreciate the answer. I would expect we would be able to update a Process Flow Variable based on a Discrete Event in the system. Is there a way to write directly to (i.e. set) the Process Flow Variable instead of updating the reference that the variable uses, in this case the Global Table?

0 Likes 0 ·
Matt Long avatar image Matt Long Jason Merschat commented ·

Process Flow Variables are really there for two reasons. The first is to give you a value or piece of code that can be evaluated from any number of activities fields using Variable: Variable Name (for universal edits) or through the getprocessflowvar() command. The second reason is to allow you to expose the variable to other users. If you create User Accessible variables, they appear in quick properties and can be set on a per instance basis to allow customizing Process Flow logic without having to get in and mess with activities.

Process Flow Variables were not designed to hold state, so you don't set them, only get them.

What you have just described sums up the new Variable shared asset that will be released in 2018 Update 1. These Variables can store any kind of data or link to other nodes, variables, values etc. Two new activities are also being added. The Get Variable and Set Variable activity. You can use Event Triggered Source and Wait For Event activities to listen to the Variable's value to change. This new feature will be available in April. Until then, using a label on the Process Flow or on the Instance Owner Object is probably your best bet as Matthew said.

1 Like 1 ·
Jason Merschat avatar image Jason Merschat Matt Long commented ·

Matt,

This Variable shared asset is exactly what I am looking for! I look forward to the update.

Jason

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Jason Merschat commented ·

Not currently. I believe PF variables were designed to be an input mechanism and not hold state like labels.

0 Likes 0 ·
Kurt De Cock avatar image Kurt De Cock commented ·
getstat(getactivity("ProcessFlow", "Resource"), "Content", STAT_CURRENT)
This doesn't return the number of resources acquired but the number of tokens that already acquired resources
0 Likes 0 ·