question

Laurenz Peleman avatar image
0 Likes"
Laurenz Peleman asked Laurenz Peleman commented

Delay when changing the rank of items in Object

Hello everyone

I encountered a problem when I was trying to change the order of items in a queue based on a label value. Any time an item with label "label" = 5 enters, it should be processed before any other item in the queue. I wrote the code below for the OnEntry trigger.

Now, the code results in the outputport being opened before the items are shuffled. Hence, the item initially at rank 1, so before the entry trigger, is passed to the processor, not the one I want. Only after the wrong item was passed, the remaining items are ordered correctly.

Is there an easy way to overcome the apparent delay on the item sorting step, or am I doing something wrong?

Many thanks in advance

Object item = param(1);
Object current = ownerobject(c);
int port = param(2);
{ // ************* PickOption Start ************* //
if (item.label == 5) {
	treenode itemConsidered = current.subnodes[current.subnodes.length];
	itemConsidered.rank = 1;
	openoutput(current);
}
} // ******* PickOption End ******* //
FlexSim 17.0.0
rank in queue
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

Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered Laurenz Peleman commented

@Laurenz Peleman Have you tried using a senddelayedmessage with delay 0 and in that onmessage trigger open the output? This usually solves these types of problems.

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

Laurenz Peleman avatar image Laurenz Peleman commented ·

Hi Steven

Thanks for your reply. This would indeed work around the problem, however it creates an additional layer of communication to a model which is already quite complex. If there is no other solution, I can solve it this way, but a more direct solution would be interesting, if available of course.

Another question related to this topic: is it normal that I have to declare the item explicitly as the treenode itemConsidered to make the command itemConsidered.rank work? If I replace itemConsidered.rank by item.rank, I get an exception in the system console.

0 Likes 0 ·
Steven Hamoen avatar image Steven Hamoen Laurenz Peleman commented ·

@Laurenz Peleman Having to use the senddelayedmessage is a very common practice within Flexsim. I understand why try to avoid it but I don't think you get around it with this problem because opening the output straight away doesn't give the object enough time to perform what it has to do on the onentry.

Concerning the item.rank not working, I have tested a bit with 17.0.3 and there it doesn't give any error reports, so maybe updating will fix it for you. The dot notation is new to Flexsim and still constantly in development so keeping up with the updates might help you here.

0 Likes 0 ·
Laurenz Peleman avatar image Laurenz Peleman Steven Hamoen commented ·

Thank you @steven.hamoen, the update solved the issue.

0 Likes 0 ·