question

Pinakin K avatar image
0 Likes"
Pinakin K asked Jordan Johnson commented

Any other way to loop the tokens using If Loop?

loop-test.fsm

Hello!

In the attached model, I have a process flow, in which a decide activity uses if loop to check if the state of the processors is idle or not. If the state of the processors is idle, the token would move further, else it would got to a delay activity, where after a very short delay (0.0001 sec), the token would again come back to the decide activity to check for the condition. This will take place until the condition is true.

P.S. in my attached model, the condition is always false, so you will see the token looping.

I thought of using wait for event activity, but was not able understand how to use it to wait for two state changes.

The reason I want to get rid of the loop with the delay, is because this makes my model run really slow.

Thanks!

FlexSim 18.1.2
wait for eventif loop
loop-test.fsm (21.7 KiB)
· 3
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·

Please test the run speed with a single wait for event activity. Maybe this activity won't accelerate your model as you expect. Perhaps you can set the delay time to last longer. 1/10000 second lasts shorter than any real event activity beside of electronic communication. 1/10 second delay would probably accelerate your model. You can adjust the delay time dynamically depending on the possible next event in your model or process, too. You can use a label at the token to do that. If you need the delayed token earlier in the process then you preempt the token in delay activity.

0 Likes 0 ·
Pinakin K avatar image Pinakin K Joerg Vogel commented ·

Thank you for a prompt response!

Yes i get what you are recommending. But there are 2 issues issue,

1. The processing time in my original model is as low as 0.25 sec. so if i add 1/10th of second as the loop delay, then its going to add on to it.

2. I have like at least 6 conditions that need to be satisfied in order to break the loop. The model is just an example, I have this model that has a subflow, so there are around 6 tokens entering the subflow at a time. I cannot share the model, but i would share the code from one of the decide activity.

I apologize. The code got disorganized when I pasted it here

Object current = param(1);
treenode activity = param(2);
Token token = param(3);
treenode processFlow = ownerobject(activity);


Object Station2 = token.Station2;
Object Station3 = token.Station3;
Object Station4 = token.Station4;
Object PrevStation = token.PrevStation;
Object PrevModule = token.PrevModule;
Object PrevMoveout = token.PrevMoveout;
Object FirstHandover = token.FirstHandover;
Object SecondHandover = token.SecondHandover;




if(Table("TerminalCount")[token.Indexx][7] == 1)
{
	return 2;
}
else
{	
	if(token.PAP?)
	{
		Object PAP = token.PAP;
		if((objectexists(PrevMoveout.first) | objectexists(PrevStatio		n.first) |
		objectexists(FirstHandover.first)) && (PrevModule.color == Col		or.silver))
		{
			if(objectexists(FirstHandover.first))
			{
				if ((Station2.stats.state().value == 6 && PAP.				stats.state().value == 6 
				&& Station3.stats.state().value == 6 && Statio				n4.stats.state().value == 6) &&
				!objectexists(SecondHandover.first))
				{
					return 1;
				}
				else
				{
					return 2;
				}
			}
			else
			{
				return 2;
			}
		}
		else
		{
			if ((Station2.stats.state().value == 6 && PAP.stats.st			ate().value == 6 
			&& Station3.stats.state().value == 6 && Station4.stat			s.state().value == 6) &&
			!objectexists(SecondHandover.first))
			{
				return 1;
			}
			else
			{
				return 2;
			}
		}
	}
	else  // No PAP
	{
		Object Station1 = token.Station1;
		Object Stitcher2 = token.Stitcher2;
				
		if((objectexists(PrevMoveout.first) | objectexists(PrevStatio		n.first) |
		objectexists(FirstHandover.first)) && (PrevModule.color == Col		or.silver))
		{
			if(objectexists(FirstHandover.first))
			{
				if ((Station1.stats.state().value == 6 && Stat				ion2.stats.state().value == 6 
				&& Station3.stats.state().value == 6 &					& Station4.stats.state().value == 6) &&
				!objectexists(SecondHandover.first)
				&& (Stitcher2.stats.state().value == 3					| Stitcher2.stats.state().value == 1 					|Stitcher2.stats.state().value == 6))
				{
					return 1;
				}
				else
				{
					return 2;
				}
			}
			else
			{
				return 2;
			}
		}
		else
		{
			if ((Station1.stats.state().value == 6 && Station2.sta			ts.state().value == 6 
			&& Station3.stats.state().value == 6 && Station4.stat			s.state().value == 6) &&
			!objectexists(SecondHandover.first)
			&& (Stitcher2.stats.state().value == 3 | Stitcher2.sta			ts.state().value == 1 |
			Stitcher2.stats.state().value == 6))
			{
				return 1;
			}
			else
			{
				return 2;
			}
		}
	}
}

If its clear, all the conditions in the If loops need to be satisfied in order to move the token out of the loop. The code is from Decide8 from the picture below. Connector 1 is going to "to station2/PAP" and connector 1 is going to the delay.

This is the reason I am not sure how to use the wait fro event activity.

I hope this is clear enough!

0 Likes 0 ·
decide.png (49.1 KiB)
Joerg Vogel avatar image Joerg Vogel Pinakin K commented ·

Comment: The logical OR is ||.

Comment2: Please use more activities instead of FlexScript.

Comment3: Please document your code.

Comment4: Please use the global state macros instead of the integer number if you compare state values: STATE_EMPTY is 6

1 Like 1 ·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Jordan Johnson commented

You should not use the current state to drive your logic. Even if you check the processor state, and find that it is idle, there is no guarantee that it will stay in that state (or any given state) for any amount of model time. Here is a table produced by listening to the OnStateChange of a simple processor model:

Look how many states last for 0 time. This can happen with the idle state as well. If you check the state in a loop, or if you listen to the OnStateChange event, you can easily catch the processor in the state you are looking for, but there is no guarantee that it will stay in that state long enough for your logic to work.

Usually, the real question is "how can I know when my processors are ready to handle a task?" That question depends on what you are trying to do, but it will likely involve pushing tasks to a list, and having processors pull those tasks. If you describe what your system needs to do, we can better answer your question.


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

Pinakin K avatar image Pinakin K commented ·

Thank you @Jörg Vogel and @jordan.johnson for your replies.

@jordan.johnson In my model I give the states through processflow, so the change of state is controlled by the processflow

I have a sensitive model. I would post a private question and would tag you both into it. The model I have is comparatively complex to the one I posted.

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Pinakin K commented ·

If you are putting items in the 3D objects, they will set their own states as well. You are welcome to post a private question.

0 Likes 0 ·
Joerg Vogel avatar image
1 Like"
Joerg Vogel answered

Instead of a delayed loop you use a Wait for event activity that evaluates the value of a tracked variable. The answer by @jordan.johnson might help you with this.

Or you pull a list entry that creates instantly a back order. The list entry contains field values that you changes by pushing the same entry value whenever a condition of your loop becomes logical true. If all conditions are true the list entry fulfills the requirement of the back order. This procedure uses the internal event mechanism. The back order is reevaluated each time a value is pushed to the list.

5 |100000

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

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.