Server output channels
Server output channels
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
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
- HarryBunnik
- Posts: 362
- Joined: Monday 07 February, 2011 - 11:22
Re: Server output channels
Ha MartinL,
I hope I understood yout question correctly. You can write a case statement in the SendTo like the following:
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!
Cheers,
Harry
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!
Cheers,
Harry
Re: Server output channels
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
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
- Attachments
-
- SendToWithPreference2.mod
- (22.18 KiB) Downloaded 280 times
- HarryBunnik
- Posts: 362
- Joined: Monday 07 February, 2011 - 11:22
Re: Server output channels
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.
I hope that it now works the way you want.
Cheers,
Harry
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)))))
)
Cheers,
Harry
Re: Server output channels
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.
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.
- Attachments
-
- SendToWithPreference3.mod
- (28.76 KiB) Downloaded 293 times
-
- Posts: 7
- Joined: Monday 02 March, 2015 - 16:34
Re: Server output channels
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)?
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
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
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
- HarryBunnik
- Posts: 362
- Joined: Monday 07 February, 2011 - 11:22
Re: Server output channels
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:
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
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
![Wink ;-)](./images/smilies/icon_e_wink.gif)
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)))))
)
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
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
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