question

Ab C avatar image
0 Likes"
Ab C asked Ab C answered

Please help with TaskExecuters and network nodes

How do I get the current Task Executer that activated the "On Arrival" trigger on a network node?


I want to specify the speed of a task executer based on its name
E.g.: the TaskExecuter1 pass on a network node > change its speed to x

the TaskExecuter2 pass on the same network node > change its speed to y

,

FlexSim 17.2.5
taskexecuternode
· 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.

Jeff Nordgren avatar image Jeff Nordgren commented ·

@Ab C,

You have an old version of FlexSim. Can you send us a model so that we can see what is happening? We would better be able to answer your question if we had your model or a sample model to look at.

Thanks.

0 Likes 0 ·
Ab C avatar image
0 Likes"
Ab C answered

the switch code works just fine, thank you.

Anyway, for anyone that's wondering how to setup the speed of any traveler that passes through a network node, this can be done using the following code:

double velocidade = getvarnum(traveler, "maxspeed") * 0.8; /** "velocidade" and "0.8" are just examples **/
setvarnum(traveler, "maxspeed", velocidade);
5 |100000

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

Ab C avatar image
0 Likes"
Ab C answered Steven Hamoen commented

I think I got it. I assigned a value for every TaskExecuter in a label that I created ("Test"), after that I wrote the following code on a network node, on the trigger "On Arrival":

if(traveler.labels["Test"].value == 1){
    model.find("TaskExecuter1>variables/maxspeed").value = 53; /** just an example of value**/
}
if(traveler.labels["Test"].value == 2){
    model.find("TaskExecuter2>variables/maxspeed").value = 35; /** just an example of value**/
}

But this way I have to make a code for every TaskExecuter, that's why I think there's a clever way do to it.
This code is working so far, however with it I can't change the speed of a generic Task Executer i.e. multiply the speed of every Task Executer that passes through that network node by a certain constant (let's say 80% or 0.8, for example)

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

Steven Hamoen avatar image Steven Hamoen commented ·

@Ab C

The trick with the label is nice to distinguish between taskexecuters but actually your code already contains the pointer to the taskexecuter because the variable "traveler" is the pointer. (just as you used it to get the label from) So your code can be shorter (I still prefer the getvarnum and setvarnum functions over the dot notation for the variables because they are so much shorter):

if( traveler.test == 1){
	setvarnum( traveler, "maxspeed", 53);
}

If the labels are actually nicely numbered you could also use the switch statement:

switch( traveler.test)
{
	case 1: 
		setvarnum( traveler, "maxspeed", 53);
	break;
	case 2: 
		setvarnum( traveler, "maxspeed", 35);
	break;
}
2 Likes 2 ·

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.