Send alternately

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Robin
Posts: 5
Joined: Friday 17 July, 2020 - 11:48

Send alternately

Post by Robin »

Hello, everybody,

At the moment I'm working on a project where the first batch has to go through cabin 1 and the next batch has to go through cabin 2. The first next batch after that has to go through cabin 1 and the batch after that has to go through cabin 2. So always alternately. I've tried to change the code of round Robin, so the ouput channel is only changed when the full batch is passed, but unfortunately I didn't get it right yet.
Can somebody help me with this?

Thanks in advance,

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

Re: Send alternately

Post by HarryBunnik »

Hi Robin,

I'm not exactly sure how your model looks like, but there must be a way how you can identify your batches. What type of atom are you using, where the decision must be made if a product goes to cabin 1 or 2?
  • Is it possible to place a label on the product when it is created (source or arrival list), identifying to which batch a product belongs? Then you could test on this label at the atom where the product needs to be "send to" a certain direction.
  • Or is a batch always the same size? In that case you could try to use a conditional statement, where the condition is identifying the batch (I wrote the code with some local variables, to make it a bit easier to read):

    Code: Select all

    Do(
      var([valProductsEnteredAtom], vbValue, {Input(c)}13),
      var([valBatchSize], vbValue, 4), 
      
      If(
        Mod(valProductsEnteredAtom - 1, valBatchSize * 2) + 1 <= valBatchSize, 
        1, 
        2
      )
    )
  • You could write code on the "Trigger on entry", settings a batch size in a label (when this label is not existing, the value is then 0), and then decrement it every time a product arrives. Additionally, every time you set this batch size label, you set a related label which is alternating between 1 and 2, to indicate the outgoing channel to the corresponding cabin.
So, it is a bit depending on which way makes you feel more comfortable and how your model is set up.

Success,

Harry
Robin
Posts: 5
Joined: Friday 17 July, 2020 - 11:48

Re: Send alternately

Post by Robin »

Hi, Harry,

Thank you for your reaction. I put the code on the trigger on entry and it's working now.
However, I still have 1 question because I first tried to make it with a label, but I didn't get it right yet to place the labels alternatly (the label 1 and 2 ) on the batches. I tried the code below but didn't get it right yet.

Do(
label([cab],i):= {choose right distribution}1,2,
Case(
label([booth],i),
Label([cab],i):=1,
Label([cab],i):=2
)
)

Could you maybe help me get this code?
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Send alternately

Post by HarryBunnik »

Hi Robin,

I'm a bit wondering what you try to achieve with the first line?

Code: Select all

label([cab],i):= {choose right distribution}1,2,
The comma is an indicator for a new line of code, so what is standing here is:

Code: Select all

Do(
  label([cab],i):= {choose right distribution}1,
  2,
  ...
This means that the 2 is not really doing anything.

Secondly I'm wondering where the label booth is set? And what does it mean? Because if it is already containing a 1 or a 2 (and the way you use the case statement it should, otherwise it will give wrong answers), why not use it dirrectly?

For the Entry Trigger I would have written something like:

Code: Select all

Do(
  If(
    Input(c) = 1, 
    {**
      Here I set the labels back to zero when the first product arrives in this atom. So a sort of reset. 
      That way we ensure that we always start at the same cabin, which is better for reproducability of simulation runs. 
      Also we are not starting with half a batch left from the previous simulation.
    **}
    Do(
      Label([SendToCabinNr], c) := 0,
      Label([CurrentBatchSize], c) := 0
    )
  ),  

  If(
    Label([CurrentBatchSize], c) = 0, 
    Do(
      Label([BatchSize], c) := 4 - 1, {** The minus one, since the first product for this batch just entered. **}
      If(
        Label([SendToCabinNr], c) := 1, 
        Label([SendToCabinNr], c) := 2,
        Label([SendToCabinNr], c) := 1
      )
    ),
    {Everytime a product arrives, decrement the current batch with one.}
    Dec(Label([BatchSize], c)) 
  )
)
I hope this helps you in understanding how you can use labels. I didn't test the code, but it should get you in the right direction.

Success,

Harry
Robin
Posts: 5
Joined: Friday 17 July, 2020 - 11:48

Re: Send alternately

Post by Robin »

Hi Harry

Thanks, I think I've got it now.
Post Reply