Advice on using submodels

133 views
Skip to first unread message

Robert Mcanany

unread,
Apr 24, 2024, 2:48:35 PMApr 24
to JaamSim Users Discussion Group
Hi Harry,

I am attempting to model a production line.  The Line consists of 2 Lanes.  Each Lane has 9 Modules.  Each Module has 9 Racks and a Transport.  The Transport has 5 Stations.

Sub-models seem like the perfect way to attack this.  

We are in the design phase, so I won't be able to complete any sub-models ahead of time.  They will all change as we go.

My first thought was to create separate *.sub files and refine them as needed.  However, importing a sub-model seems to be a one-time thing.  When I tried to re-import, I got errors.

I tried a couple of other ways, but finally realized I should just ask the Master.  What is the best approach for this situation?

Robert

Robert Mcanany

unread,
Apr 24, 2024, 4:33:48 PMApr 24
to JaamSim Users Discussion Group
OK, that's a pretty vague question.  I guess I am looking for the "Best Practices for Sub-Models in JaamSim" whitepaper.  Is there such a thing or something similar?  I read through several forum posts regarding sub-models and got a lot of clues.  Just trying to put it all together in my head.

Harry King

unread,
Apr 24, 2024, 6:26:58 PMApr 24
to JaamSim Users Discussion Group
Hi Robert,

You are correct that your project will be much easier to build using SubModels. Unfortunately, there is no real documentation on how to use SubModels yet.

When modifying a SubModel, you can either do it in place and re-export and overwrite the .sub file, or you can edit your input file and add an 'Include' command to load the .sub file instead of importing it. The latter method has the advantage that the code for the SubModel is kept separately from the main model file, which makes the model and .sub files easier to understand and maintain. The user manual describes how to use the 'Include' statement.

Note that you should only use clones of the SubModel object in your model logic. The original SubModel object should not be used directly. Just leave it on the sidelines of your model where you can examine it when necessary.

Harry

Robert Mcanany

unread,
Apr 24, 2024, 6:46:52 PMApr 24
to JaamSim Users Discussion Group
That is very helpful.  Thank you!  

I haven't used your software in several years.  I'm amazed at how you keep finding ways to improve it.  It's awesome!

Anthony Earl

unread,
Apr 25, 2024, 8:35:00 PMApr 25
to JaamSim Users Discussion Group
You might find that nesting sub3-models will make your model-creation easier and more maintainable if there is a lot of consistency in the copies you describe.

Robert Mcanany

unread,
Apr 26, 2024, 5:39:57 PMApr 26
to JaamSim Users Discussion Group
I appreciate the feedback.  I'm currently trying to wrap my head around the whole thing.  

For example, I built a Module sub-model containing Rack and Station sub-models as I described in my previous post.  A Rack needs to know when to release something to a Station.  I have an Expression Threshold (ET) at the Module level to control that.  

Since everything is contained within the Module, I thought a clone would know that the ET should refer to the comparable entities in the clone.  Instead it still refers to the prototype sub-model.

I'm not complaining and it's not hard to fix.  I just wish I could get a better handle on the rules.

Robert Mcanany

unread,
Apr 28, 2024, 12:59:59 PMApr 28
to JaamSim Users Discussion Group
I'm making some headway on this.  My main issue was getting cloned submodels to reference the entities in the clone, rather than pointing back to the prototype.

It seems like clones respect "downhill" references.  For example, the NextComponent in a submodel object can point directly to a nested submodel within.  When the prototype is cloned, it knows to reference the nested submodel of the clone.

The reverse does not appear to be true.  If an entity in a nested submodel points to an entity in the parent, the cloned nested submodel will point back to the prototype.  The recommended way to handle that, as I understand it, it to leave those references blank in the prototype then populate them in the clone.  With many nested submodels and many clones, that's a lot to keep track of.

I got around it by using the syntax "this.Parent.Parent.[<entity_name>]" in the prototype nested submodel.  As far as I can tell, it seems to be working.  It's early days, though.  I'm sure there are more surprises in store for me!

One place I couldn't get it to work was with Thresholds.  Not sure what's going on -- it acts like the error checker, rather than trying to resolve the reference, only checks the literal input list.  The way I got around that was to add a (seemingly redundant) ExpressionThreshold in the nested submodel.  That entity type allows and correctly resolves the "this.Parent.Parent.[]" syntax.

Anyway, here's a picture.  My model is attached.

nested_submodel_test.png
nested_submodel_test.cfg

Harry King

unread,
May 2, 2024, 10:26:44 PMMay 2
to JaamSim Users Discussion Group
Hi Robert,

See my replies in blue below.

I'm making some headway on this.  My main issue was getting cloned submodels to reference the entities in the clone, rather than pointing back to the prototype.

It seems like clones respect "downhill" references.  For example, the NextComponent in a submodel object can point directly to a nested submodel within.  When the prototype is cloned, it knows to reference the nested submodel of the clone.

The reverse does not appear to be true.  If an entity in a nested submodel points to an entity in the parent, the cloned nested submodel will point back to the prototype.  The recommended way to handle that, as I understand it, it to leave those references blank in the prototype then populate them in the clone.  With many nested submodels and many clones, that's a lot to keep track of.

I got around it by using the syntax "this.Parent.Parent.[<entity_name>]" in the prototype nested submodel.  As far as I can tell, it seems to be working.  It's early days, though.  I'm sure there are more surprises in store for me!

HK - Yes, your syntax is correct. However, it is best to avoid external references in a SubModel as much as possible. In the case of your SubModelEnd object, you can leave the NextComponent blank in which case it passes the entity back to its parent SubModel which can then send it to Sub.SubSub1 using its NextComponent input.
 
One place I couldn't get it to work was with Thresholds.  Not sure what's going on -- it acts like the error checker, rather than trying to resolve the reference, only checks the literal input list.  The way I got around that was to add a (seemingly redundant) ExpressionThreshold in the nested submodel.  That entity type allows and correctly resolves the "this.Parent.Parent.[]" syntax.

HK - Most objects do not accept an expression for their NextComponent input. The pop-up description for the input in the Input Editor will tell you what types of input can be used.

Harry

Robert Mcanany

unread,
May 3, 2024, 11:32:11 AMMay 3
to JaamSim Users Discussion Group
I appreciate the feedback! 

A question about avoiding external references in SubModels.  Is that because in the general case you don't control how or where a SubModel will get used, or are there other gotchas? 

On the other question, I wasn't seeing the distinction between an entity and an expression.  Thank you for clearing that up!

Harry King

unread,
May 3, 2024, 12:46:25 PMMay 3
to JaamSim Users Discussion Group
Ideally, the user of a SubModel should not need to know how it is constructed. All inputs to the SubModel should be made directly to the SubModel object, not its components. An external reference in the inputs to a component requires a detailed knowledge of how the SubModel works, breaking this rule. It invites the user to make input errors. This principal is called "encapsulation" in object-oriented programming.

I've attached a revised version of your test model that avoids external references. You can see the changes to the .cfg file using the 'Compare' feature in Notepad++. Note the use of the KeywordList input to SubSub.

Harry

nested_submodel_test - HK.cfg

Robert Mcanany

unread,
May 3, 2024, 1:03:59 PMMay 3
to JaamSim Users Discussion Group
Oh, wow I didn't expect that!   I'm studying it now.  I really appreciate your help!

Roberto Bianchi

unread,
Nov 30, 2024, 5:04:31 PM (2 days ago) Nov 30
to JaamSim Users Discussion Group
Hello Harry,

I see this conversation is an old one, but the topic is still interesting for me.
I was playing whit SubModel features in the last days trying to understand how they should work.

I agree with you, the SubModel should allow to reproduce a kind of "encapsulation", that why is a good practice to use the KeywordList feature to interface with the SubModel, instead to access what is inside the SubModel throught the SubModel.Entity mechanism.

Therefore I use the KeywordList feature, but I am not sure I 'm using its full potential.

A) Is there any way to give a KeywordList element a "default value"? I mean a kind of initialization value. I tried the same for the AttributeDefinitionList, but unsuccessfully.

B) This second point is tricky, it is strictly related with the solution you gave above.
Let's have a SubModel having inside only a EntityConveyor.
Let's whish that conveyor being activated/deactivated by an external SignalThreshold.
My understanding is that the code should be as follow:
1. Define SignalThreshold { SignalThreshold1 }
2. Define SubModel { SubModel1 }
3. Define EntityConveyor { SubModel1.EntityConveyor }
4. Define SubModelEnd { SubModel1.SubModelEnd }
5. Define SubModelStart { SubModel1.SubModelStart }
6. SubModel1 KeywordList { { External_Threshold_Link } }
# *** SubModel ***
7. SubModel1 External_Threshold_Link { [SignalThreshold1] }
# *** EntityConveyor ***
8. SubModel1.EntityConveyor ImmediateThresholdList { SignalThreshold1 }
9. SubModel1.EntityConveyor NextComponent { SubModel1.SubModelEnd }
# *** SubModelStart ***
10. SubModel1.SubModelStart NextComponent { SubModel1.EntityConveyor }
The above code is what I obtained by JaamSim itself, but I have the feeling I made some missclick, because, in order to have "encapsulation", nor external entities should "point" to SubModel.Entities neither SubModel.Entities should "point" to external entities.
I mean that at line 8 I was expecting to find a "External_Threshold_Link" reference instead of "SignalThreshold1".
I had that expectation because, when a SubModel is imported, the line 1 wouldn't be present and the User may ignore he has to enter the SubModel1.EntityConveyor ImmediateThresholdList and set the right reference (given the SubModel is not written by the User).
I tried to figure out what should be changed if line 1 is missing. My feeling is that line 7 and 8 should be modified in something like that:
7. SubModel1 External_Threshold_Link { Some_kind_of_threshold_prototype }
8. SubModel1.EntityConveyor ImmediateThresholdList { External_Threshold_Link }
just in order to allow JaamSim to solve the ImmediateThreshold connection, but I couldn't find the right expression (something like the "NextComponent" keyword and its "Required Input" field ).

I worked around simply considering "External_Threshold_Link" a TRUE/FALSE value and adding a ExpressionThreshold to the SubModel working as a Threshold for the Conveyor.

But I am still courious, there is a way to write line 7 in such a way that line 8 doesn't rise the error "External_Threshold_Link not existing" when line 1 is not there?

Ooops, I wrote a lot, but JaamSim is superinteresting.
Thanks in advance for any suggestion.

Best regards
Roberto

Harry King

unread,
Dec 2, 2024, 1:06:09 PM (15 hours ago) Dec 2
to JaamSim Users Discussion Group
Hi Roberto,

A) Is there any way to give a KeywordList element a "default value"? I mean a kind of initialization value. I tried the same for the AttributeDefinitionList, but unsuccessfully.
HK - No you cannot define a default value. However, if the SubModel is a clone of a 'prototype' SubModel, then the clone will inherit the value entered for the prototype.
 
B)  in order to have "encapsulation", nor external entities should "point" to SubModel.Entities neither SubModel.Entities should "point" to external entities.

I mean that at line 8 I was expecting to find a "External_Threshold_Link" reference instead of "SignalThreshold1".
I had that expectation because, when a SubModel is imported, the line 1 wouldn't be present and the User may ignore he has to enter the SubModel1.EntityConveyor ImmediateThresholdList and set the right reference (given the SubModel is not written by the User).
I tried to figure out what should be changed if line 1 is missing. My feeling is that line 7 and 8 should be modified in something like that:
7. SubModel1 External_Threshold_Link { Some_kind_of_threshold_prototype }
8. SubModel1.EntityConveyor ImmediateThresholdList { External_Threshold_Link }
just in order to allow JaamSim to solve the ImmediateThreshold connection, but I couldn't find the right expression (something like the "NextComponent" keyword and its "Required Input" field ).
HK - Yes, you were correct to try this input, but it doesn't work because the ImmediateThresholdList input does not accept expressions at present. 
 
I worked around simply considering "External_Threshold_Link" a TRUE/FALSE value and adding a ExpressionThreshold to the SubModel working as a Threshold for the Conveyor.
HK - This is probably the best solution. 

Harry
Reply all
Reply to author
Forward
0 new messages