Lambda Function Help - Iteration

109 views
Skip to first unread message

evan stocker

unread,
Jul 26, 2021, 4:14:52 PM7/26/21
to Jaamsim Users Discussion Group
Hi, I am a new user to JaamSim and am attempting my first model to help in a facility layout at my company. I have previous experience in Arena so the learning curve hasn't been too steep so far. The main entities in my model are Lots, which have the attribute Lot Size.
I would like to write a lambda function which samples a normal distribution once for each part in the Lot to generate Service Times for a given process. To do this, I am thinking of using a for loop, but I don't see anything in the documentation about this. Is this possible?

Here is the non-working code I have so far:
|Qty,ServiceTime|(
for i in Qty {
ServiceTime = ServiceTime + [NormalDistribution2].Value
 }
)(this.obj.LotQty,0)

Another general question, can I write functions that will be used elsewhere in my mode, or am I limited to lambda functions?
Any help here would be much appreciated,

evan stocker

unread,
Jul 26, 2021, 5:38:23 PM7/26/21
to Jaamsim Users Discussion Group
Looks like I answered my own question.
I'll post it in case anyone else had a similar question:
'sum(map(|x|([NormalDistribution2].Value),range(this.obj.LotQty)))'

Harry King

unread,
Jul 26, 2021, 6:54:04 PM7/26/21
to Jaamsim Users Discussion Group
The following lambda function is another possibility:

'reduce(|x, accum|([NormalDistribution2].Value + accum), 0[s], range(this.obj.LotQty))'

It is a bit more efficient because it does not create the intermediate array of service times. Note that NormalDistribution2 must return a value with the units of TimeUnit.

Harry

Reply all
Reply to author
Forward
0 new messages