AnswerHub Upload Issue
Our AnswerHub community currently has a bug that prevents you from attaching your model or other files to your questions. AnswerHub is aware of this issue and they are working on a fix. Until we receive their patch, you can upload your models and other files to FlexSim's file share site. Include the file name in your question so that we know which upload to reference.

question

Ines L avatar image
0 Likes"
Ines L asked Ines L commented

Calculate the content of a queue

Hello,

I have the processors, each of them has a queue. I want to know the content of the queues and then program the source to send the item to the queue with one object. That is, i want to priorize the queue with one item.

FlexSim (other)
FlexSim (other - please specify)
queue contentprogramming
· 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.

FLEXSIM 7.1.4

0 Likes 0 ·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Ines L commented

Use this in the sendtoport to prioritse queues with one item first and then send to the shortest queue.

treenode item = parnode(1);
treenode current = ownerobject(c);
/**Queues with 1 items then Shortest Queue if Available*/
/**Send to the port corresponding to the shortest queue downstream that is available.*/

treenode tempobject;
int curmincontent =  1000000000; // this sets the integer to the largest possible value that an integer can hold.
double curminindex = 0;

for (int index = 1; index <= nrop(current); index++) {
   tempobject = outobject(current, index);
   if (opavailable(current,index) && (content(tempobject) ==1)) {
        return index;
   }
}

for (int index = 1; index <= nrop(current); index++) {
   tempobject = outobject(current, index);
   if (opavailable(current,index) && content(tempobject) < curmincontent) {
        curmincontent = content(tempobject);
        curminindex = index;
   }
}

return curminindex ;

Model attached.

SentToQueuesWithOneItemThenShortest.fsm


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

Thank you so much!!!!!
0 Likes 0 ·
Begoña Espiñeira avatar image
0 Likes"
Begoña Espiñeira answered

select_queue_2.fsm

@Ines L

Firstly, your code has differents lines that you should correct. You can't compare a treenode variable with an integer, so you have to declarate contenidoM1, contenidoM2 and contenidoM3 as an integer. Moreover, i think that this code is not going to work properly because you are going to send only the items to the first port, because in the initial moment you are going to have 0 content for all queues, so you going to send one item for the first queue. Then, you are going to send other item to the first queue because you are going to be in the case: contenidoM1=1 contenidoM2=0 contenidoM3=0, and then, you are going to be in this case: contenidoM1=2, contenidoM2=0 contenidoM3=0 so you are going to send the item to the queue 1 . Then, when the items exit the queue 1,you are going to be back to the previous cases (in which you always send the item to the first queue). So I recommend you to set this code in send to port (SCMarcado) :

Don´t forget to have the correct conexions!

I attach the model, if you have problems for open it, you can download the latest version of flexsim and open it with this version, you don´t need license to open this example. I hope it helps!

5 |100000

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

Begoña Espiñeira avatar image
0 Likes"
Begoña Espiñeira answered Begoña Espiñeira converted comment to answer

Hi @Ines L , I have created an example trying to get the solution that you are looking for. I have done a simple process with two processors that have do decide to what port send the processed item. I've created a simple processFlow logic for decide and send the box to the correct queue.To do this, I made a custom code within the decision activity in which we decided to queue by prioritizing the queue with content 1 and then the queue with content 0. If these conditions are not met, the queue is chosen randomly. I've attached the example model, if you have any questions please tell me.


select_queue.fsm


1607943528798.png (455.5 KiB)
1607944043503.png (129.8 KiB)
select-queue.fsm (33.6 KiB)
· 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.

Hi Begoña,

I can´t oper your model. In my process, I want to send the items from "SCM marcado" to "MM1 MM2 o MM3" when the queue content =1.


I have used an exit trigger on SMC marcado but it doesn't work:

/**Custom Code*/

treenode item = parnode(1);

treenode current = ownerobject(c);

treenode station = parnode(2);


double tiempo=time();

setlabelnum(item, "SCMarcado",tiempo);

treenode contenidoM1=outobject(current,2);

treenode contenidoM2=outobject(current,3);

treenode contenidoM3=outobject(current,4);

if (contenidoM1==0 && contenidoM2==1 && contenidoM3==0)

{return 3;}

else if (contenidoM1==0 && contenidoM2==0 && contenidoM3==3)

{return 4;}

else

{return 2;}

0 Likes 0 ·
1607944924545.png (178.9 KiB)

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.