Page 1 of 1

Server output channels

Posted: Thursday 19 February, 2015 - 22:07
by MartinL
Hello,

I would like to ask your help with one 4DS script. I have a server with multiple output channels and I'm trying to create the following "Send" function:

If "labelname" = 1, then channel 1 or 2 ( First channel first),
If "labelname" = 2, then channel 3 or 4 ( Third channel first, then 4 )
If "labelname" = 3, then channel 5,6 or 7 ( Fifth channel first, then 6,7 )

Is this achievable with 4DS script and how the code should like if this is possible?

Best Regards

Re: Server output channels

Posted: Friday 20 February, 2015 - 16:14
by HarryBunnik
Ha MartinL,

I hope I understood yout question correctly. You can write a case statement in the SendTo like the following:

Code: Select all

Do(
  var([valStartExitChn], vbValue), 
  
  Case(
    Label([Test], first(c)), 
    valStartExitChn := 2,
    valStartExitChn := 4,
    valStartExitChn := 6
  ), 
  Max(valStartExitChn - 1, valStartExitChn + 1 - IndexMatch(2, 1, ICReady(1, out(valStartExitChn + 1 - Count, c))))
)


A short explanation:

First I declare a variable which is assigned the start of its 2 possible exit channels based on the Label named [test]. This is either a value 1, 2 or 3.
So a product with Label([Test], ...) = 2 will go to either exit channel 3 (if open) or 4 (if open).

IndexMatch will return me the last occurrence where the condition was met. This is something we can use nicely for this problem.
I start with checking the highest exit channel (in this case 4) and check if the outgoing atom is ready to receive (ICready returns a 1 if open and a 0 when closed). Then I check the lower exit channel, nr. 3. By looping down in the IndexMatch, I always get the lowest channel that is ready.

To prevent errors, I send it to the lowest channel anyway, when both objects are not available.

I also included a small test model to show you what the code does. I hope it helps you!
SendToWithPreference.mod
(32.19 KiB) Downloaded 290 times
Cheers,

Harry

Re: Server output channels

Posted: Sunday 22 February, 2015 - 12:38
by MartinL
Hi Harry,

First, thanks for your help and reply. I experimented with the model you sent and one question occured.

If the label [Test] = 1 , then only output channel 1 and 2 should be available, and channel 1 is prefered. I switched the source for ArrivalList and simultaneously released 4 products with a labe [Test]=1 and the outcome was following:

Product nr.1 - Channel1 - Server2-1
Product nr.2 - Channel2 - Server2-2
Product nr.3 - Channel3 - Server2-3

My question is why product nr.3 (label [Test]=1) went to Channel3 - Server2-3. Only Channels 1 and 2 should be available for this product. Similar problem also occured with the other labels (2,3)

Also attached the model and if possible need some help modify the script so that only Channel 1 and 2 are availabe for [Test]=1 products, Channel 3,4 for [Test]=2 products, and Channel 5,6 for [Test]=3 products.

Best Regards

Re: Server output channels

Posted: Monday 23 February, 2015 - 10:33
by HarryBunnik
Ha MartinL,

I see that for your case I missed one occurance. And that is when both lines are full. The IndexMatch will then return a 0, which send it to an unwanted channel.

I've made a small adjustment (addin the Max(1, around the indexMatch ) to the SendTo statement, which seems to do the trick.

Code: Select all

Do(
  var([valStartExitChn], vbValue), 
  
  Case(
    Label([Test], first(c)), 
    valStartExitChn := 2,
    valStartExitChn := 4,
    valStartExitChn := 6
  ), 
  Max(valStartExitChn - 1, valStartExitChn + 1 - Max(1, IndexMatch(2, 1, ICReady(1, out(valStartExitChn + 1 - Count, c)))))
)
I hope that it now works the way you want.

Cheers,

Harry

Re: Server output channels

Posted: Tuesday 24 February, 2015 - 18:14
by MartinL
Hello Harry,

The last adjustment worked fine, but I have another question regarding this topic.

It seems that the last script works only if label[Test] values have same number of output channels. Is it possible to modify the script so that the different label[Test] values (1,2,3) have different number of output channels.

For example: lable[Test]=1 - Channel 1
lable[Test]=2 - Channels 2,3,4,5,6 ( prefered order 2,3,4,5,6)
lable[Test]=3 - Channels 7,8,9 (prefered order 7,8,9)

BR.

Re: Server output channels

Posted: Monday 02 March, 2015 - 17:25
by tobias.reithmann
Hello MartinL,

Well, you could program your whole model into one atom only. However, SendTo has already the functionality you need.

- SendTo No. 2: An open channel (First channel first)
- SendTo No. 7: By label value (direct)

Why don't you build a first queue sorting by label (No. 7) and for each output channel an additional queue sorting by preferences (No. 2)?

Re: Server output channels

Posted: Monday 02 March, 2015 - 21:52
by MartinL
Hi,

First, thanks for the reply! Using two separet queue atoms seems to the trick regarding functionality. In that case, I should also use Lock and multiple Unlock atoms to control the flow and restrict the number of allowed products in two following queue atoms (in reality, there is only room for one product in the "crossroad")

But as an alternative, how the one atom solution could look like? It would better in that sense, then there are less atoms in the model and it is more easy to follow.

BR.
Martin

Re: Server output channels

Posted: Wednesday 04 March, 2015 - 17:21
by HarryBunnik
Ha MartinL,

What Tobias is saying that by splitting it up, it might be easier to model and also easier for someone else to understand what is happening, is true.

However, since it is a nice subject ;-), I think that with some adjustments the code I gave earlier can do the trick for you as well:

Code: Select all

Do(
  var([valStartExitChn], vbValue), 
  var([valNrOfChannels], vbValue), 
  
  Case(
    Label([Test], first(c)), 
    Do(
      valStartExitChn := 1,
      valNrOfChannels := 1
    ), 
    Do(
      valStartExitChn := 4,
      valNrOfChannels := 3
    ), 
    Do(
      valStartExitChn := 6, 
      valNrOfChannels := 2
    )
  ), 
  Max(valStartExitChn - (valNrOfChannels - 1), valStartExitChn + 1 - Max(1, IndexMatch(valNrOfChannels, 1, ICReady(1, out(valStartExitChn + 1 - Count, c)))))
)
With the valStartExitChannel, which is the highest channel through with the product with a label is allowed to leave. From that point we count down the channels. The lowest channel that is available will be chosen. And the variable valNrOfChannels tells how many channels we are allowed to count down.

So products with:

label([Test], first(c)) = 1 will only use channel 1.
label([Test], first(c)) = 2 will use channel 2 up to 4
label([Test], first(c)) = 2 will use channel 5 up to 6

As you see, this needs some maintenance when you want to set up a different distribution.

I hope it helps you a bit.

Cheers,

Harry

Re: Server output channels

Posted: Wednesday 04 March, 2015 - 18:12
by MartinL
Hi,

Thanks a lot, both ideas worked great! In my case, the one atom solution was little better, because then I would not have to use so many Lock and Unlock atoms and modifying the script is quite easy and logical.

BR.
Martin