Send to script

All topics on coding 4Dscript in Enterprise Dynamics.
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

I guess I'm giving you a hard time here. I figured the arrivallist out and it seems to work as it should, yet when I try to give the products certain colors in the 4d script it gives a compile error. I now tried the codes below

Code: Select all

Case(
  Label([ProductID], i), 
  {ProductID = 1}
  Icon(i) := IconByName([CircleGreen]), 
  Label([ProductID],i),
  Icon(i) := IconByName([CircleGreen]),
  Label([ProductID],i),
  Icon(i) := IconByName([CircleBlue])
  )

Code: Select all

Case(
  Label([ProductID], i), 
  {ProductID = 1}
  Icon(i) := IconByName([CircleGreen]), 
  {ProductID = 2}
  Icon(i) := IconByName([CircleGreen]),
  {ProdictID = 3}
  Icon(i) := IconByName([CircleBlue]),
  {ProductID = 4}
  Icon(i) := IconByName([CircleBlue]), 
  {ProductID = 2}
  Icon(i) := IconByName([CircleBlue]),
  {ProdictID = 5}
  Icon(i) := IconByName([CircleBlue]),
  {ProductID = 6}
  Icon(i) := IconByName([CircleBlue]), 
  {ProductID = 7}
  Icon(i) := IconByName([CircleBlue]),
  {ProdictID = 8}
  Icon(i) := IconByName([CircleBlue]),
  {ProductID = 9}
  Icon(i) := IconByName([CircleBlue]), 
  {ProductID = 10}
  Icon(i) := IconByName([CircleBlue]),
  {ProdictID = 11}
  Icon(i) := IconByName([CircleBlue]),
  {ProductID = 12}
  Icon(i) := IconByName([CircleBlue]), 
  {ProductID = 13}
  Icon(i) := IconByName([CircleRed]),
  {ProdictID = 14}
  Icon(i) := IconByName([CircleRed]),
  {ProductID = 15}
  Icon(i) := IconByName([CircleRed]), 
  {ProductID = 16}
  Icon(i) := IconByName([CircleRed]),
  {ProdictID = 17}
  Icon(i) := IconByName([CircleRed]),
  {ProductID = 18}
  Icon(i) := IconByName([CircleRed]), 
  {ProductID = 19}
  Icon(i) := IconByName([CircleRed]),
  {ProdictID = 20}
  Icon(i) := IconByName([CircleRed]),
  {ProductID = 21}
  Icon(i) := IconByName([CircleRed]), 
  {ProductID = 22}
  Icon(i) := IconByName([CirclePurple]),
  {ProdictID = 23}
  Icon(i) := IconByName([CirclePurple]), 
  {ProductID = 24}
  Icon(i) := IconByName([CircleYellow]), 
  {ProductID = 25}
  Icon(i) := IconByName([CircleYellow]),
  {ProdictID = 26}
  Icon(i) := IconByName([CircleYellow]),
  {ProductID = 27}
  Icon(i) := IconByName([CircleYellow]), 
  {ProductID = 28}
  Icon(i) := IconByName([CircleRed]),  
)
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

Nevermind my last post! I found the comma >.<
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Send to script

Post by HarryBunnik »

No problem. Good you found it yourself :-)

Just an extra tip. Also here you can use a WhichIsTrue and an InList to make your code a bit more compact.

Code: Select all

Case(
  WhichIsTrue(
    InList(Label([ProductID], i), 1, 2) > 0, 
    InList(Label([ProductID], i), 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) > 0,   
    InList(Label([ProductID], i), 13, 14, 15, 16, 17, 18, 19, 20, 21, 28) > 0,  
    InList(Label([ProductID], i), 22, 23) > 0,      
    InList(Label([ProductID], i), 24, 25, 26, 27) > 0     
  ), 
  {ProductID = 1 - 2}
  Icon(i) := IconByName([CircleGreen]),
  {ProdictID = 3 - 12}
  Icon(i) := IconByName([CircleBlue]),  
  {ProductID = 13 - 21, 28}
  Icon(i) := IconByName([CircleRed]),
  {ProductID = 22 - 23}
  Icon(i) := IconByName([CirclePurple]),
  {ProductID = 24 - 27}
  Icon(i) := IconByName([CircleYellow])
)
Or another options is to compare them based on their upper value. Since the WhichIsTrue statement starts with the first and stops directly when a statement returns a true value, this also works well and simple. It's just what you find most easy to read.

Code: Select all

Case(
  WhichIsTrue(
    Label([ProductID], i) <= 2, 
    Label([ProductID], i) <= 12,
    Or(
      Label([ProductID], i) <= 21, 
      Label([ProductID], i) = 28
    ),  
    Label([ProductID], i) <= 23,      
    Label([ProductID], i) <= 27
  ), 
  {ProductID = 1 - 2}
  Icon(i) := IconByName([CircleGreen]),
  {ProdictID = 3 - 12}
  Icon(i) := IconByName([CircleBlue]),  
  {ProductID = 13 - 21, 28}
  Icon(i) := IconByName([CircleRed]),
  {ProductID = 22 - 23}
  Icon(i) := IconByName([CirclePurple]),
  {ProductID = 24 - 27}
  Icon(i) := IconByName([CircleYellow])
)
Cheers,

Harry
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

I have managed to simplify my model to test the codes. See attachment.
Attachments
Arrivallist&Sendto test V1.mod
(42.57 KiB) Downloaded 281 times
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

The Arrival list seems to work, however I keep getting errors which I do not understand when I run the simulation.
Attachments
Arrivallist&Sendto test V1.mod
(43.14 KiB) Downloaded 293 times
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Send to script

Post by HarryBunnik »

First some general notes:
  • Label code in the arrival list, use first(c) instead of i.
  • The decimal indicator for numbers is an "." and not a "," (table Cycletime).
  • To use an uniform distribution for the CycleTime or arrival time is a good idea, but then the cell references to the outer numbers has to stand within uniform distribution:

    Code: Select all

    Uniform(cell(label([productID],first(c)) , 1, refCycletime), cell(label([productID],first(c)) , 2, refCycletime))
  • Or, when you want to use an uniform distribution to randomly select the CycleTime from either column 1 or 2, you need to use dUniform, which returns integers.

    Code: Select all

    cell (label([productID],first(c)) , dUniform(1,2), refCycletime) 


When I see you current setup, I'm not so sure any longer if an arrival list was the best way to do it, sorry. An arrival list works down the list and creates every ArrivalTime a certain quantity of products and then moves on to the next row. I think what you want is more that orders are arriving with a variable inter arrival time, but not according to a predefined list.
What I would do is create a source that produces orders. The orders are going into a MultiService atom (this is where your inter arrival time of the orders is calculated). When you limit it to a capacity of 28 (the number of product types you have), you can allow a new product (using code on the OnExit of the MultiSerive), every time an order is done (force the first empty order that is still waiting in the queue, to have the same product code as the order leaving). I've changed your model to give you an idea.
Arrivallist&Sendto test V2.mod
(38.8 KiB) Downloaded 303 times
Then all your products are arriving in your queue in a random order (based on the inter arrival time you gave in). The challenge will now be to make sure that orders are not waiting, while the server is actually free, but they are blocked by one of other orders that is waiting for its server to become available. Therefore you have to write some code on the Servers to make sure that when a process is done, the correct product is set in front of the queue and allowed to a server. I'm pretty sure there are some examples of such code on the community.

Cheers,

Harry
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

I have searched the community till page 9 but can not find the direct answer to the problem.

I have found an alternative to it:
Place a que in front of every server with capacity 1. This way the first queue can always send to the queues in front of the servers right? Then the queue in front of the servers can send it to the server whenever it is empty. I'm going to try this and let you know.

If you seem to have the answer how to script the servers to take their destined product out of the queue that would still be great!

btw you already helped me a lot, thank you!
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

As a reaction to my last post,

The queue's do not make any difference. Now I adjusted the queue discipline to "user defined: put the incoming product at location 1". This actually seems to wrok, although I am not certain if the first product in the lane is actually put to the back of the queue due to all other products being placed in location 1.
Smiliej
Posts: 13
Joined: Wednesday 22 April, 2015 - 12:18

Re: Send to script

Post by Smiliej »

I found the mistake, I forgot to send number 14 and 9 to a channel. Those made the queue jam. Now that I have added them it works like a charm! Now I can finally expand the model :D
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: Send to script

Post by HarryBunnik »

Ha,

It was not a direct answer, but a situation in which I think a similar problem is described (queue discipline) and might give you some ideas:

viewtopic.php?f=5&t=519

But good that you make progress! :)

Gr.

Harry
Post Reply