Use of variables / indices

68 views
Skip to first unread message

Paul René

unread,
Mar 31, 2025, 5:37:37 AM3/31/25
to JaamSim Users Discussion Group
Hello! I have been getting started with JaamSim, and so far it has been amazing, thank you and congratulations for this software!

However, I have been having a few issues, possibly because I missed important options:

1) I am trying to find the smallest difference (or distance) between all pairs of values in a given unsorted list, for instance f([12, 8, 13, 16]) should give 1, but so far I've been trying to do this into an ExpressionEntity's Expression with a manually entered list, to no avail ; is there a better way to do computation on lists?

2) Especially interesting to me is the difference between the two smallest values in a given list, but so far, still as an Expression, the only way I've found to get the smallest minimum is to manually write another list looking like:
[ [Apple].Value + 10^9*min([Apple].Value, [Banana].Value)==[Apple].Value , [Banana].Value + 10^9*min([Apple].Value, [Banana].Value)==[Banana].Value ], to get rid of the initial minimum.
Again, I feel like there must be a simpler way to perform basic computations like in Python, directly within JaamSim, but I haven't found it...


3) On a wholly different topic, I've been trying to compute the expected time until completion of a series of events of variable length :
To put it simply, it's probably badly modeled, but I setup the filling of a tank at a slightly variable rate as a filling of 1% every X ± y min.
An EntityGenerator follows an InterArrivalTime
which is a NormalDistribution, then there's a Server, then an AddTo, adding 100 "percents" to a ContainerUnit.

The two main ways I've found to estimate the instant at which the Container will be full are:
- '(([Simulation].PresentSimulationTime   +   (100  - [PercentQueue].QueueLength)*([ProductionRate].Mean))) ' --> "Now + expected time until full"
- '[Simulation].PresentSimulationTime - [PercentQueue].QueueTimes(1) + 100* [ProductionRate].Mean ' --> "Time at which an empty Container was plugged + expected total time of filling"

Is there a third, better option?

4) The first solution felt more accurate, but also way more janky, as the output is roughly a sawtooth curve ; my best attempt at smoothing it was to use a MovingAverage ; currently it uses a fixed NumberOfSamples, but I would have liked to average over more values as the filling goes on.
I have tried using a variant of  '[PercentQueue].QueueLength', so that it would average over something like that, without taking into the average the "TimeWhenFull" of the previous Container :
movingAverageSpan.png
But apparently, the MovingAverage really didn't like having a changing value as a NumberOfSamples and it always only used 1 sample (so not averaging anything), even though the Present Value from the input builder indeed showed the expression worked as intended. Do you know if that's normal and I missed something?

5) This above issue mostly stems from a need I may not have: one of the processes I would like to have in my model is simply a somewhat steady flow of fluid into a container that has a fixed capacity, and I would like to estimate either the time left until full, or the instant at which it will be full. I believe this is a pretty usual use case, so if there's a better way of modeling this than what I've been doing so far, I'm all ears!

6) As I'm using submodels that are near copies of one another, is there an easy way of gathering a value from each of the submodels?
For instance, is there an easier way to find the minimum of a value than:
'min([SubModel1.Queue].QueueLength, [...], [SubModel25.Queue].QueueLength)' ?

I would greatly appreciate some help over these points, and again I would like to thank you since other than that, there are many, many things that went really well with the software! I'm sorry if I haven't been clear enough with my issues, let me know if I should give additional details!

Thanks in advance!
- Paul

Paul René

unread,
Mar 31, 2025, 10:05:00 AM3/31/25
to JaamSim Users Discussion Group
I have been making some progress on these:

1/2/6) I completely missed the sort() function and the possibility of creating variables for some reason, now my best solution for 2 is:

'Values = {[Apple].Value, [Banana].Value, [...]}   ;   SortedValues = sort(|x,y|(x<y), Values)   ;   SortedValues(2)-SortedValues(1)'

However, one functionality I still haven't found is the capacity to compute an Entity somewhere and call it in different Entities. For instance, I would like to have one single place where I compute an Entity based on a criteria, for instance [Computation].Value would be [Banana] and then being able to use this computation in another entity, such as by calling [Computation].Value.Value, giving me the Value of the [Banana] Entity, but which could change if the [Computation] gave a different result. The closest I got is to use:
( {[Apple] , [Banana] , ...} ([ComputedIndex].Value) ).Value

For 6, it would also be useful if I could compute a list in a single place, such as having somewhere and uniquely, the collection SubmodelsQueueLengths, and call it in different entities the way we can call an expression's value in different entities... Am I missing something ?

Again, thanks in advance !
- Paul

Paul René

unread,
Apr 2, 2025, 7:42:23 AM4/2/25
to JaamSim Users Discussion Group
Hello! Thanks again for this great software!

I am currently trying to model a subprocess where there's a somewhat steady arrival of objects (SimEntities), which we would like to AddTo 100 of into an EntityContainer ; however, on a certain trigger ("Needing an early swap of container"), I would like the AddTo to immediately finish the packing even though it does not have the required 100 entities to pack. I've been trying to use NumberOfEntities = '[SwapASAP?].DataSource ? [ObjectQueue].QueueLength : 100', but that doesn't work ; likely for a reason similar to my earlier problem with having a MovingAverage whose NumberOfSamples should change over time... Any ideas?

The situation I'm trying to model is that one truck (resource) is used to transport multiple tanks (containers) to and from multiple sources (entity generators) into a single drain (entity sink), and so in some case, we might need the Truck to leave with a Tank that is not full yet, so that it can reach the Drain, then reach the next Source before the Tank being filled at that Source gets full. I'm not sure if there's a best practice for such a situation.

Many thanks in advance!
- Paul
Reply all
Reply to author
Forward
0 new messages