Random Product Label Assignment at Source Creation

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Terril
Posts: 5
Joined: Monday 05 August, 2013 - 19:19

Random Product Label Assignment at Source Creation

Post by Terril »

I'm trying to write script for a Source's Trigger-on-Creation field, such that a product's label is assigned based on a uniform(0,1) draw. Here's my pseudo-code that's not a working 4DScript:

Case((x=uniform(0,1)),
(x<=0.3, setlabel([JobType],1,i)),
(x>0.3 & x<=0.8, setlabel([JobType],2,i)),
(x>0.8,setlabel([JobType],3,i))
)

I know this isn't right, but I hope it communicates my intent. Once the product's label is set, I will use another 4DS in the Send-To field to route it to the appropriate server. FYI, this is implementing the Job-Shop example in Section 2.7 of 4th ed. of Averill Law's Simulation Modeling and Analysis. It's the final thing that I need to do to illustrate this example using ED.
BartC
Posts: 47
Joined: Monday 05 November, 2012 - 17:05

Re: Random Product Label Assignment at Source Creation

Post by BartC »

Hi Terril,

You can use this:

Code: Select all

Do(
  var([valX], vbValue),
  
  valX := Uniform(0, 1),
  
  Case(
    WhichIsTrue(
      valX <= 0.3,
      valX <= 0.8,
      valX > 0.8
    ),
    SetLabel([JobType], 1, i),
    SetLabel([JobType], 2, i),
    SetLabel([JobType], 3, i)
  )
)
Regards,

Bart
Terril
Posts: 5
Joined: Monday 05 August, 2013 - 19:19

Re: Random Product Label Assignment at Source Creation

Post by Terril »

Thanks; I'll try this. One correction, though: The second case needs to include an "and" condition, i.e. Val >0.3 & <= 0.8. I'll try combining two conditions, but so far, I haven't yet got the syntax correct.

Thanks again.

-TH
Terril
Posts: 5
Joined: Monday 05 August, 2013 - 19:19

Re: Random Product Label Assignment at Source Creation

Post by Terril »

I'm still having difficulties implementing the Law's Job Shop example. So I've created and attached a simplified version for debugging.

After implementing Bart's 4DScript in the Source Trigger-on-Creation Field, the model "kind of" functions, sending a small number of products through some of the time (after reset) but not always. Then it stalls out as though deadlocked.

I believe that I've correctly connected everything, since if I randomly send products to the 3 queues/servers, then they roughly converge to equal utilizations. But somehow, I'm still not routing as desired according to the probabilities in the Source Trigger-on-Creation's case/label assignments and Send-To script.

I'm not sure it's a misunderstanding of 4DScript, the "Central Channel", referencing, or a combination of many things that's stopping me.

I appreciate any further help that you can provide.
dbg.mod
Debugging Model for Law's Job Shop Example
(21.12 KiB) Downloaded 357 times
Terril
Posts: 5
Joined: Monday 05 August, 2013 - 19:19

Re: Random Product Label Assignment at Source Creation

Post by Terril »

I think I figured out my problem: It had to do with the conditional statements' syntax. Here's what works in the Source's Trigger-On-Creation script:

Do(
var([valX], vbValue),

valX := Uniform(0, 1),

Case(
WhichIsTrue(
<=(valX,0.3),
&(>(valX,0.3),<=(valX,0.8)),
>(valX,0.8)
),
SetLabel([JobType], 1, i),
SetLabel([JobType], 2, i),
SetLabel([JobType], 3, i)
)
)

On to next challenge!
Post Reply