Conditional branch

1,268 views
Skip to first unread message

Jean-Christophe Sapin

unread,
Jun 16, 2014, 5:10:26 AM6/16/14
to jaamsi...@googlegroups.com
Hello,

I tried to make a conditional branch, using an ExpressionTreshold Object (This object is really great). But it seems that the branch object doesn't evaluate the expression [ExpressionThreshold].Open +1. (see attached file)

In the second hand, it's more a DIY.

It would be nice to have conditional formulas in the ExpressionThreshold like this: If(test;Expression if true;Expression if false)

In the attached file, there is also some troubles with the queue object.

Indeed, when the position of the Queue is relative to an other object, the entities in the queue are actually displayed at the absolute position.

Thanks for your help and your disponibility

EACAR-test.cfg

Harry King

unread,
Jun 16, 2014, 6:58:31 PM6/16/14
to jaamsi...@googlegroups.com
Jean-Christophe,

The problem with your conditional branch is that a mathematical expression cannot accept a Boolean value. The "true" or "false" value returned by the expression '[ExpressionThreshold].Open' is not converted automatically to 0 or 1, so you cannot perform addition with it. This functionality is something that we may add in the future -- I've asked the programmer to look into it. The solution for your model is to replace '[ExpressionThreshold].Open + 1' with the expression you used in the ExpressionThreshold, i.e. '([Branch1_1].obj.Controlled==1||[EntityConveyor2_1].NumberAdded-[EntityGate2_1].NumberProcessed!=0) + 1'. This change has been made in the attached model.

The problem with the queues in your model -- entities are not queuing up next to the triangular queue objects -- is caused by a known bug in Queue when the RelativeEntity input is set. If you delete this setting for each queue, they will behave properly. I've done this for Queue1_1 in the attached version of your model. I'll see about getting this bug fixed now that it has become a nuisance.

Lastly, the conditional formula you mention is one of the things on our wish list. I'll look into this as well.

Harry
EACAR-test-HK.cfg

Harry King

unread,
Jun 16, 2014, 9:30:41 PM6/16/14
to jaamsi...@googlegroups.com
Jean-Christophe,

Further to my previous post, it turns out that we have already implemented the conditional statement -- I just didn't know about it. It uses the "ternary" operator syntax from the C programming language:

(condition) ? (true-expression) : (false-expression)

The attached file uses this operator in your model.

Also, it turns out that it will be easy for us to allow an output that returns a boolean to be used in a mathematical expression. This will allow you to use your original input for the Branch object. This feature will be implemented in the next release of JaamSim (2014-25).

Harry




EACAR-test-HK2.cfg

Jean-Christophe Sapin

unread,
Jun 17, 2014, 2:32:14 AM6/17/14
to jaamsi...@googlegroups.com
Hello Harry

Thank you for your quick answer.

It's a good new that the connditional expression is already implemented,

and since there is this this possibility, I think I can use it for the conditional branch instead of adding a boolean with an integer.

I continue and give you the feed back. 

Harry King

unread,
Jun 20, 2014, 9:50:22 PM6/20/14
to jaamsi...@googlegroups.com
Jean-Christophe,

The problem with boolean-valued outputs has been fixed in JaamSim2014-25. Your test model now works correctly.

A further improvement would be to use the conditional function in your expression for Branch1_1. Replace the expression '[ExpressionThreshold7_1].Open+1' with '[ExpressionThreshold7_1].Open ? 2 : 1'

Harry

Jean-Christophe Sapin

unread,
Jun 25, 2014, 11:17:56 AM6/25/14
to jaamsi...@googlegroups.com
Hello Harry,

I tested the if function in the conditional branch in the joined model (see Branch_1_1 for example). Unfortunatly, it doesn't work. 

I think it's a problem of circular reference, as the threshold object which contains the test make reference to the branch that uses the result of the threshold object.

There is another problem on the joined model with the Text9. The OutputName should be 'Assign1 Pace'. (Pace is an attribute I created for the Assign1 Object).

But everytime I close the model, and reopen it, the OutputName is empty.

Thank you for your help.
EACAR-test.cfg

Harry King

unread,
Jun 26, 2014, 3:01:46 PM6/26/14
to jaamsi...@googlegroups.com
Jean-Christophe,

I tried the configuration file you attached with JaamSim2014-25 and it looks to me that Branch1_1 works correctly. Can you confirm that you are using the latest release? It will not work with JaamSim2014-24. Otherwise, can you describe what is wrong with the operation of Branch1_1 -- perhaps I am missing something.

The problem with Text9 that you report is a bug related to the way we save the configuration file. The attribute "Pace" for Assign1 is referenced by Text9 before it is defined. I should be able to fix this in time for our next release (tomorrow).

Harry

Jean-Christophe Sapin

unread,
Jun 27, 2014, 4:17:57 AM6/27/14
to jaamsi...@googlegroups.com
Hello Harry,

Sorry, I should have modify all the branches, and give you some explanation.

When a part is controlled it shouldn't enter a next control station.

But if you follow a controlled part (the first one for exemple), you can see that it will enter the first empty control station, although it is already controlled (Controlled attribute = 1)

You can check this in the joined file.

Jean-Christophe
EACAR-test.cfg

Harry King

unread,
Jun 27, 2014, 8:12:37 PM6/27/14
to jaamsi...@googlegroups.com
Jean-Christophe,

This is a problem with the order of operations in the model. When a palette entity arrives at the branch object, the choice of which branch to take and the updating of ExpressionThreshold object's state are simultaneous events -- events at the same simulated time. You cannot rely on the order in which simultaneous events are executed. As it turns out, the choice of branch is made before the ExpressionThreshold is updated, which is why the palette takes the wrong branch.

Simultaneous events are a common source of logical errors in all types of simulation software. It is best to design your model to avoid them even if by luck you get the right order of operations. For your model, you could either go back to your previous input for the Choice keyword, or you could set the ExpressionThreshold's state prior to the palette's arrival at the branch object.

Harry

Harry King

unread,
Jul 4, 2014, 8:33:08 PM7/4/14
to jaamsi...@googlegroups.com
Jean-Christophe,

The problem with the ExpressionThreshold output "Open" is fixed in the latest release (2014-27). The value for Open is now calculated on demand instead of using a store value. This avoids the problem of order of operation I described in my previous post.

Harry

Harry King

unread,
Jul 18, 2014, 8:36:43 PM7/18/14
to jaamsi...@googlegroups.com
Jean-Christophe,

The problem with Queue objects that have the RelativeEntity set has been fixed in the latest release (2014-29).

Harry

Harry King

unread,
Aug 22, 2014, 12:34:29 AM8/22/14
to jaamsi...@googlegroups.com
Jean-Christophe,

Your EACAR model runs about 10 times faster with the latest release of JaamSim (2014-34). This speedup is a result of a big improvement to ExpressionThreshold -- see the release notes for 2014-34.

Harry

Jean-Christophe Sapin

unread,
Aug 22, 2014, 11:37:13 AM8/22/14
to jaamsi...@googlegroups.com
Hello Harry,

Incredible, it runs really much faster. 

Thank you very much for this improvement. I can imagine it wasn't so easy to do.

Jean-Christophe
Reply all
Reply to author
Forward
0 new messages