Setting an array as attribute programatically

244 views
Skip to first unread message

Nepe51

unread,
Mar 26, 2021, 12:42:49 PM3/26/21
to Jaamsim Users Discussion Group
Hello

I am modeling a factory, with different routes by product. To do this, I added an attribute to a SimEntity like this:

{ route  '{1, 2, 3, 4, 5}' } 

where the numbers represent the machines to go to, so a Branch object can direct it.

I have a java class that reads the route from SQL as an array. How can I write the entity attribute from the java array? (I am doing this in the processStep() of an EntityGenerator)

Thank you

Carlos

Harry King

unread,
Mar 27, 2021, 11:03:44 AM3/27/21
to Jaamsim Users Discussion Group
Carlos,

Instead of writing directly to a named attribute, it would be better to create an new object that reads the SQL code from a file and creates a 'Value' output, similar to the FileToVector, FileToMatrix, and FileToHashMap objects. You could then set the attribute values in the normal way using an Assign object. The code for these three classes and their superclass FileToArray should give you the information you need.

Harry

Harry King

unread,
Mar 27, 2021, 11:24:45 PM3/27/21
to Jaamsim Users Discussion Group
Carlos,

Thanks for your emailed reply. A new object to handle SQL queries would be a useful addition to JaamSim.

If you can provide the code for the SQL query and an example database, I can build the JaamSim object and hook it up to the user interface. I am not familiar with SQL and databases myself. so I need to rely on you for that part.

Harry

Carlos A. Santiago

unread,
Mar 29, 2021, 6:29:28 AM3/29/21
to Jaamsim Users Discussion Group
Hi Harry

I´m confused, I did not send any email, and yesterday I replied here but can´t see the comment now. I had to change my Google user since I´m having troubles with my work email.

Anyway, I would be happy to contribute to JaamSim if I can, so will get back to you with the SQL code. Meanwhile I am still trying to figure out your approach to set the route argument using Assign.

Thank you

Carlos

Harry King

unread,
Mar 29, 2021, 9:41:11 AM3/29/21
to Jaamsim Users Discussion Group
Hi Carlos,

This was my mistake. I was confused by an email that I received from someone else. Incidentally, I did receive the reply from you yesterday, but it was just an email, not a forum post.

Once we create a new object that reads SQL code and returns the route data as its 'Value' output, all the Assign object will do is to pass this data to the 'route' attribute. The Assign input will probably be as simple as 'this.obj.route = [SQLreader].Value'.

Harry

Carlos A. García Santiago

unread,
Apr 13, 2021, 1:36:15 PM4/13/21
to Jaamsim Users Discussion Group
Hi Harry

Sorry for my delay, I get pulled from different projects and can hardly work on this for a few hours each week.

Finally, my solution was to create a SimEntity with the following output: 

{ route  '{1, 2, 3, 4, 5}' } { runtimes  '{10 [s], 20 [s], 30 [s], 40 [s]}' } { lastCompletedOp  0 } { next  1 }

Route defines the ID of the machines where the operations need to be performed
runtimes, the operation times in each of those machines
lastCompletedOp and next are assigned after every operation completed to allow re-routing:

{ 'this.obj.lastCompletedOp = this.obj.lastCompletedOp + 1 ' } { this.obj.next=this.obj.route(this.obj.lastCompletedOp+1) 

Carlos

Harry King

unread,
Apr 16, 2021, 10:07:14 AM4/16/21
to Jaamsim Users Discussion Group
Carlos,

Yes, that is a good design for a 'job shop' type model.
 
Do you still intend to use SQL in your model? If so, it would be nice to see your Java code.

Harry

Carlos A. García Santiago

unread,
Apr 24, 2021, 1:21:46 AM4/24/21
to Jaamsim Users Discussion Group
Hi Harry

Yes, we are using it. Let me tidy it up a little bit and I will email it to you

Carlos

Reply all
Reply to author
Forward
0 new messages