question

shanice.c avatar image
0 Likes"
shanice.c asked Felix Möhlmann commented

Is Tracked Variable Data only can used to track numeric value?

I would like to use wait for event to listen to a cell util it's filled in with a pointer data.

But I found if I assign a cell to tracked numeric value, then I cannot write an object value into that cell. Then how can I write an object value in to a cell, and I can tracked that cell at the same time.

I want to write a taskexecuter name to a cell, and whenever the cell value is updated, Then the token continues the rest of flow.

testlisten to GTparameter.fsm

FlexSim 21.2.0
tracked variables
5 |100000

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

1 Answer

·
Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Felix Möhlmann commented

If you set the type of tracked variable (tv) to "categorical", you can assign string values to it. (A categorical tv is how FlexSim tracks the states of objects for example)

1634192543951.png

There is also a pointer type for tracked variables, though for some reason it's not available in the dropdown menu.

To make a table cell into a pointer tv, you can use the following code:

TrackedVariable.init(Table("TableName").cell(row, col), STAT_TYPE_POINTER);

Note: Overwriting an existing tv seemed to not work properly for me. It might be better to delete the cell and recreate it before running that code.

The pointer tv works like the categorical one, just with pointers instead of strings. In both cases, calling the value of the table cell will return the row number of the current category/pointer in the node. To return the actual text/object you can use the following:

TrackedVariable TV = Table("TableName").cell(row,col).as(TrackedVariable);
Object obj = TV.profile.as(Table)[TV.value+1][1]; // "+1" because data is 0-indexed

testlisten-to-gtparameter_1.fsm


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

Allyson avatar image Allyson commented ·

I'm struggling with the above solution. Is this something that has been deprecated in 23.0.0?

What's happening is that it won't let me set a non-numeric value for the tracked variable despite setting the type as a pointer. This is consistent with the TrackedVariable init method which always has the start value as a double, even when omitted. I tried manually setting a treenode as the startValue and the code would not compile. Is there a way around this?

The purpose of having a TrackedVariable as a pointer type is so that I can monitor for a label change event when the pointer value changes.

Here is my code:

  
                    
  1. Object current = param(1);
  2. treenode activity = param(2);
  3. Token token = param(3);
  4. Variant assignTo = param(4);
  5. string labelName = param(5);
  6. treenode processFlow = ownerobject(activity);
  7.  
  8. /***popup:AddTrackedVariable*/
  9. /**Add Tracked Variable*/
  10. int type = /** \nType: *//***tag:type*//**/STAT_TYPE_POINTER/**list:STAT_TYPE_LEVEL~STAT_TYPE_TIME_SERIES~STAT_TYPE_CUMULATIVE~STAT_TYPE_CATEGORICAL*/;
  11. treenode startValue = /** \nStart Value: *//***tag:value*//**/nullvar/**/;
  12. int trackHistory = /** \nTrack History: *//***tag:trackHistory*//**/0/**/;
  13. int trackProfile = /** \nTrack Profile: *//***tag:trackProfile*//**/1/**/;
  14. int ignoreWarmup = /** \nIgnore Warmup: *//***tag:ignoreWarmup*//**/0/**/;
  15. int flags = 0;
  16. if (trackHistory)
  17. flags |= STAT_USE_HISTORY;
  18. if (trackProfile)
  19. flags |= STAT_USE_PROFILE;
  20. if (ignoreWarmup)
  21. flags |= STAT_IGNORE_WARMUP;
  22. treenode theLabel = assignTo.labels.assert(labelName);
  23. //return TrackedVariable.init(theLabel, type, startValue, flags);
  24. return TrackedVariable.init(theLabel, type);

When I have the second-to-last line activated, my code doesn't compile when I hit 'Apply'. When I have the last line activated, I can't set the pointer variable later on in the simulation because I get a type mismatch error.


Edit: I am also trying to make a categorical/string-based tracked variable and this, too, is not compiling for the same reasons.

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Allyson commented ·

Each entry of a categorical tracked variable consists of three values: The name/value, the time spend at that value and a third value that denotes whether that value is "active" or not (the structure used for states).

1672903091570.png

Each of these entries belongs to a numerical identifier. So you would first initialize the variable with an empty "state" 0. When you then assign a new pointer/string value to it, a new entry with a new "state number" will be created.

When you read the label via dot syntax, it will return this number. To access the actual pointer/string, you have to cast the node as a Tracked Variable and use the corresponding method "getCategoricalValue()"/"getCategoricalName()".

Object curPointerVal = token.labels["TrackVar"].as(TrackedVariable).getCategoryValue(token.TrackVar)

categoricalTrackedVariable.fsm

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.