question

Axel Kohonen avatar image
0 Likes"
Axel Kohonen asked Matt Long commented

Is it possible to get the references to the tokens reserved by a resource?

Hi,

Is it possible to get the token references of the tokens that have reserved a numeric resource somewhere else in the code? I have paired tokens and would like to create a "zone" that can be entered only if the ID of a token already in the zone matches the ID of the token now entering the zone and the token "weight" can fit into the resource reservation.

In the attached example model I look at the model tree for the resource in process flow, but I cannot figure out a way to access the tokens.

Any clue on how to do this?

Thank you!

Kind regards,

Axel

20161212-howdoigetreferncetotokensthathavereserved.fsm

FlexSim 16.2.1
process flowtokensreference
5 |100000

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

Matt Long avatar image
2 Likes"
Matt Long answered Matt Long commented

There are reasons we removed the "Explore Tree" option from the Process Flow view. We do not recommend diving into the tree and messing with or getting data directly from the nodes. The structure is not guaranteed to always be the same. Things can get quite confusing when dealing with instances as well.

Instead, use the given commands to access tokens. If your code is in the same Process Flow as the Resource, then 'current' is the instance. To get a reference to the tokens that have acquired a Resource use the following code:

  1. gettoken(current, "Resource", 1);
  2. or
  3. gettoken(current, getactivity(processFlow, "Resource"), 1);

If you're in a different Process Flow then the instance would either be:

  1. node("Tools/ProcessFlow/ProcessFlowName", model()); //For General
  2. or
  3. node("Processor1", model()); //For a FR or TE

This is a lot simpler than trying to access tokens through the tree.

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

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered
  1. gettoken(<processflow/instance>,<activity>,<index>)

can also be used.

5 |100000

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

Axel Kohonen avatar image
0 Likes"
Axel Kohonen answered

Hi,

Found the answer myself. The nodes inside tokens are coupling nodes and the nodes they are linked to can be found with the following "+" syntax (where firstToken is the coupling node):

  1. var tokenTest = node("+", firstToken);

So the code to get the owner token is the following

  1. //reference to process flow
  2. treenode processFlow = ownerobject(activity);
  3.  
  4. //create reference string
  5. string path = concat(">stats/instances/", getnodename(processFlow),"/tokens");
  6.  
  7. //get reference to tokens
  8. treenode tokens = node(path, getactivity(processFlow, "Resource"));
  9.  
  10. //get the first token node as an example (it must exist so
  11. //the first time we get into this code in the model it will not)
  12. treenode firstToken = rank(tokens, 1);
  13.  
  14. //get the token reference from the data
  15. var tokenTest = node("+", firstToken);
  16.  
  17. //the main token is the
  18. treenode theToken = up(up(tokenTest)); //HERE WE HAVE THE TOKEN ITSELF
  19.  
  20. //get label value
  21. var labelValue = getlabel(theToken, "resource");
  22. //get token id
  23. int theTokenID = gettokenid(theToken);

And the model file with the same code is this

20161212-fixed-howdoigetreferncetotokensthathavere.fsm

Axel


5 |100000

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