Batch similar products in queue

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Thore
Posts: 16
Joined: Sunday 28 October, 2018 - 13:27

Batch similar products in queue

Post by Thore »

Hi folks!
I'm building a model where I have a server that is able to process x number of similar products with a constant processing time. Meaning that it does not matter wheter it is 1, 2...X number of products and the idea is therefore that all similar products in the queue should be "batched" together, forwarded to the server and processed as one entity, no matter their current position in the queue.

I therefore need a logic similar to:
1) Based on the first (longets waiting time) product in queue, identify all similar products.
2) Batch these products and send them to the server, where they are processed as a batch.

I know how to identify the total number of products in the queue that have the same type as the first product in queue, but not have to "collect" these similar products and send them to the server.

I hope you can help :)

BR
Thore
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Batch similar products in queue

Post by HarryBunnik »

Ha Thore,

What I have in mind is, when you have the batch complete in the queue, sort the queue on the OnEntry code (otherwise keep the Queue closed using CloseOutput(c)) and place this batch of products in front of the Queue by looping over the Queue and setting the rank to 1:

Repeat(
Content(c),
If(
Label([BatchID], rank(count, c)) = Label([BatchID], i), {Last entered}
Rank(count, c) := 1
)
)

Then open the Output of the Queue (OpenOutput(c)) and leave all atoms out, until the entire Batch is out (you can set a label with the batch size and decrement it every time a product leaves the queue. When this label is 0, all products left the queue and it can be closed again).

If you then use a multiserver, all products can enter together, get the same process time and are leaving the multiservice as a batch that is kept together.

If only one batch can be processed at once, you can manipulate the entry again using CloseInput(c) and OpenInput(c).

I hope this helps you further!

Regards,

Harry
Thore
Posts: 16
Joined: Sunday 28 October, 2018 - 13:27

Re: Batch similar products in queue

Post by Thore »

Hi Harry
Thank you for your detailed answer :)

I understand the logic in your suggestion and have tried to implement it, but I get an error regarding the second "count" whenever more than one atom is in the queue. The error is:

22 Access violation at address 0000000001C2BFBC in module 'EDStudent.exe'. Read of address 0000000000000031 -> QCRAWQ (AtomID: 172), ATTRIBUTE: EntryTrigger (Ln: 7, Col: 79) "Count" | Time: 21, c: QCRAWQ (AtomID: 172), i: Product (AtomID: 765), OnEntered, EventCode: 2
CallStack: EntryTrigger|SCRIPTTYPE_ATT|QCRAWQ (172),OnEntered|SCRIPTTYPE_EVENT|Queue (11),OnOcReady|SCRIPTTYPE_EVENT|Source (10),OnEvent(2)|SCRIPTTYPE_EVENT|Source (10)

Any ideas why?
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Batch similar products in queue

Post by HarryBunnik »

Ha Thore,

Can you show me your model so I can have a look at it, or create an example model where the error also pops up? So on first sight, I don't see it, I must admit.

You can also send me your model in a private message if you don't want to share the complete model on the community.

Regards,

Harry
Thore
Posts: 16
Joined: Sunday 28 October, 2018 - 13:27

Re: Batch similar products in queue

Post by Thore »

The model is attached :)
Attachments
DemandSim1.mod
(46.47 KiB) Downloaded 203 times
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Batch similar products in queue

Post by HarryBunnik »

Ha Thore,

Ok, I found it... You can only set the rank, when the atom is already directly selected (like rank(animatom) := 1, Rank(i) := 1 etc...).

In this particular case, you can use SetRank(1, Rank(count, c)).
Or you use a local variable in which you store the atom reference and then you move it with the following code snippets:
  • var([atmA], vbAtom),

    atmA := rank(count, c),
    Rank(atmA) := 1
I think that the code is then working.

Cheers,

Harry
Thore
Posts: 16
Joined: Sunday 28 October, 2018 - 13:27

Re: Batch similar products in queue

Post by Thore »

It works, thank you very much! :)
Post Reply