Boolean Logic in Branch Choice

361 views
Skip to first unread message

Andres Collart

unread,
Mar 31, 2016, 9:54:56 AM3/31/16
to Jaamsim Users Discussion Group
Hi Harry,

I'm trying to set up a model where I need to use boolean logic in the branch choice to help direct entities. However, nothing has worked thus far. 

I want to route things based on simulation time as shown below

([Generator1].SimTime < 17h)*1+([Generator1].SimTime >=17h)*2


Thanks,
Andres

Harry King

unread,
Mar 31, 2016, 10:51:32 AM3/31/16
to Jaamsim Users Discussion Group
Andres,

Two changes are needed:
1) enclose the whole expression in single quotes (because it includes spaces)
2) enclose the unit h in square brackets (because a unit is an object)

Your final expression will be:

     '([Generator1].SimTime < 17[h])*1+([Generator1].SimTime >=17[h])*2'

You can write this expression more clearly using the ternary operator:

     '[Generator1].SimTime < 17[h] ? 1 : 2'

Also, every entity has the output SimTime, including the Branch object, so you can write the expression as:

     'this.SimTime < 17[h] ? 1 : 2'

Harry


Andres Collart

unread,
Apr 1, 2016, 10:43:13 AM4/1/16
to Jaamsim Users Discussion Group
Harry,

Thank you, that worked perfectly!

-Andres

Andres Collart

unread,
Apr 4, 2016, 12:50:03 PM4/4/16
to Jaamsim Users Discussion Group
Hi Harry,

I'm running into a similar issue with some Thresholds. I have an entity generator that I want to operate if a certain Queue Length is <5. I tried using the OperatingThresholdList within the generator object but that didn't seem to work with the below expression. Given that I created a SignalThreshold object and a Signal, I'm trying to set the Signal.NewState input to the below expression too but it isn't taking it because it "expects a boolean value". Any idea how do this?

'[TruckGenQueue].QueueLength > 5 ? False: True'


Thank you,
Andres

Harry King

unread,
Apr 4, 2016, 1:03:26 PM4/4/16
to Jaamsim Users Discussion Group
Andres,

You cannot use the names True and False in an expression. Use their numerical equivalents: 1 for TRUE and 0 for FALSE.

In any case, you can simplify your expression by writing it as the following:

     '[TruckGenQueue].QueueLength <= 5'

There is no need to use the ternary operator (?) in this case because the comparison already provides a boolean value.

Lastly, the NewState keyword for EntitySignal does not accept an expression. It would be better to use an ExpressionThreshold for this purpose, as you had originally intended.

Harry

Andres Collart

unread,
Apr 4, 2016, 1:39:40 PM4/4/16
to Jaamsim Users Discussion Group
Harry,

Worked perfectly as an ExpressionThreshold, thanks!

-Andres
Reply all
Reply to author
Forward
0 new messages