Assign Attribute within custom objects

602 views
Skip to first unread message

Charlie Norton

unread,
Jun 6, 2017, 3:12:57 AM6/6/17
to Jaamsim Users Discussion Group
Hi,

How do I assign attributes within the JaamSim source code?
In previous versions, this line used to work.

ent.setAttribute("attributeName", value, DimensionlessUnit.class);

However now I need to use ExpParser types which I don't know how to create.

Thanks in advance,

Kind regards,
Charlie

Harry King

unread,
Jun 6, 2017, 5:42:14 PM6/6/17
to Jaamsim Users Discussion Group
Charlie,

Changing an attribute's value from code does not seem like a good idea. Attributes are assigned by user input, so your code would be making assumptions about these inputs.

If you want to make the result of an object's calculations available to the expression system, it would be much better to add an "output" that would return the calculated value. You could then assign the value of the output to an attribute or use it in an expression. It is very easy to add an output. Simply define a function that has simTime as an argument and that returns a double. Use the @Output annotation to assign the name of the output and a few other parameters. Look in the code for Server for examples of how to do this.

Harry

Charlie Norton

unread,
Jun 6, 2017, 7:12:53 PM6/6/17
to Harry King, Jaamsim Users Discussion Group

Hi Harry,

Thanks for your response.
If I set an output, could I then use that to determine the next component choice through a branch object?

Kind regards,
Charlie


--
You received this message because you are subscribed to a topic in the Google Groups "Jaamsim Users Discussion Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jaamsim-users/V3H-xcB6Jo4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jaamsim-user...@googlegroups.com.
Visit this group at https://groups.google.com/group/jaamsim-users.
To view this discussion on the web, visit https://groups.google.com/d/msgid/jaamsim-users/bccc060f-be13-4bfe-9845-fe1fd46b20c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harry King

unread,
Jun 6, 2017, 11:09:16 PM6/6/17
to Jaamsim Users Discussion Group, d.harr...@gmail.com
Charlie,
 

If I set an output, could I then use that to determine the next component choice through a branch object?


HK - Yes, the new output will appear in the Output Viewer along with the other outputs for that object. Anything you see in the Output Viewer can be referenced in an expression using the standard syntax: [Object_Name].output_name.

Harry

Charlie Norton

unread,
Jun 7, 2017, 3:56:09 AM6/7/17
to Jaamsim Users Discussion Group, d.harr...@gmail.com
Hi Harry,

Thanks again.
I'm trying to set the output and I'm having a little difficulty.

I'll give you a little background on my model.
I'm modelling queues that can be served by one of multiple resources. I would like to be able to test a few different queue selection strategies.
I've started by creating an extension of the seize class 'mySeize' which can check multiple resources and seize the next available one. I first ran into trouble sending it to a different next component, as nextComponent is protected, and I'd have to customise LinkedDevice to edit that. I elected to steer clear of this. Instead, now I hope to simply assign the person being served with an attribute/output which states which resource they've seized so that they can be redirected in a subsequent 'branch'.

The issue I've now come to is assigning the output for the personas opposed to 'mySeize'. I want to prevent the output from being updated before the person has been directed correctly.

Can I assign the output for an entity passing through?

I'd be interested to hear your thoughts.

Thanks again
Charlie

Harry King

unread,
Jun 7, 2017, 11:57:30 PM6/7/17
to Jaamsim Users Discussion Group, d.harr...@gmail.com
Charlie,

With a few refinements to Seize, I think that you can build your model without having to program a custom Seize object. See my comments below.
 
I'm modelling queues that can be served by one of multiple resources. I would like to be able to test a few different queue selection strategies.
I've started by creating an extension of the seize class 'mySeize' which can check multiple resources and seize the next available one.

HK - I assume that the various resources are interchangeable for some Seize objects but not for others. Otherwise, they should all be combined as multiple units of a single resource. I think that a suitable expression can be used with the NumberOfUnits keyword to determine which resource(s) to seize. I have an initial version of this, but there are a few bugs to work out.
 
I hope to simply assign the person being served with an attribute/output which states which resource they've seized so that they can be redirected in a subsequent 'branch'.

HK - Your have identified a shortcoming of the present Seize object -- there is no way for the processed entity to know what resources were seized. We can fix this by adding an output that records the number of units seized for each of the resources by the last entity that was processed. This will be an output for the Seize object, but an Assign object can be used to record this information to a suitable attribute for the entity. I'll experiment with this idea and get something into the next release (2017-06).
 
Can I assign the output for an entity passing through?

HK - The new output along with an Assign object, as described above, will solve this problem.

Harry

Harry King

unread,
Jun 14, 2017, 8:35:45 PM6/14/17
to Jaamsim Users Discussion Group, d.harr...@gmail.com
Charlie,

Release 2017-06 adds a new output "SeizedUnits" to Seize that returns the number of units for each resource that were seized by the last entity. This output along with the higher-order function "filter" will allow you to build the logic you want. Attached is an example to get you started.

Harry
First Available Resource Example.cfg

Charlie Norton

unread,
Aug 7, 2017, 10:25:44 PM8/7/17
to Jaamsim Users Discussion Group
Hi Harry,

I realised that I had never thanked you for this.
Thank you, it works really well,

Kind regards,
Charlie
Reply all
Reply to author
Forward
0 new messages