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:

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

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

node("Tools/ProcessFlow/ProcessFlowName", model()); //For General
or
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.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @Matt Long

Thank you for the comment! Your solution makes much more sense.

How would you know how many tokens there is in the resource so you know how far in the index to loop? Now I have used the stats information

getstat(resource, "Content", STAT_CURRENT);

and loop according to that. I tried to check for a NULL returned from the gettoken function when the index points to a token that does not exists, but I could not get it to work. Not sure what I did wrong. Anyhow, using stats does work, but was thinking if there would be a better solution for it.

Kind regards,

Axel

0 Likes 0 ·
Matt Long avatar image Matt Long Axel Kohonen commented ·

It does look like there's a slight bug in the gettoken() on a Resource such that when you ask for a index beyond the number of tokens that have acquired the Resource it throws an exception. We'll get that fixed.

If you open an Assign Labels and add a label and then use the Sampler for the Value field, you can hover over the Resource and it will give you a getstat() option which looks like this:

getstat(getactivity(processFlow, "Resource"), "Output", STAT_CURRENT, current)

Notice the difference between this code and the one you posted in your comment. The last parameter, current, is a reference to the instance object. When getting stats on Process Flow objects you need to pass the instance in as well. So to get the number of tokens that have acquired it would be:

getstat(resource, "Content", STAT_CURRENT, current)
1 Like 1 ·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered
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):

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

So the code to get the owner token is the following

//reference to process flow
treenode processFlow = ownerobject(activity);

//create reference string
string path = concat(">stats/instances/", getnodename(processFlow),"/tokens");

//get reference to tokens
treenode tokens = node(path, getactivity(processFlow, "Resource"));

//get the first token node as an example (it must exist so
//the first time we get into this code in the model it will not)
treenode firstToken = rank(tokens, 1);

//get the token reference from the data
var tokenTest = node("+", firstToken);

//the main token is the 
treenode theToken = up(up(tokenTest)); //HERE WE HAVE THE TOKEN ITSELF

//get label value
var labelValue = getlabel(theToken, "resource");
//get token id
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.