Importing Data (Single data)

627 views
Skip to first unread message

Varsha Baghar

unread,
Jun 26, 2017, 7:36:01 PM6/26/17
to Jaamsim Users Discussion Group
Hi All, 

I am having troubles with importing data. My current data is in Excel and I understand that this needs to be converted into txt files before using the include statement in the configuration file. 

Unlike many posts in this forum, the data that needs to be imported into my JaamSim model is not many (i.e. not a time series and not many different inputs for one object like Interarrival times) but rather a single cell that should be linked with an ExpressionEntity (so different imported cells will have a different ExpressionEntity). The reason to why I have not just put the number in is because I would like it to be dynamic. 

My question is do I need to create a text file for each of the cell that I would like importing or is there a workaround to this like putting all the cells that I need to be imported into one text file and perhaps create variables tell JaamSim which position to use?

Right now I have tried using the FileToVector object (importing a text file that has one value) and without using include statements in the cfg file. However I am failing to get the .Value property of FileToVector object (when it is read into the ExpressionEntity) but from the output window it reads the file. I am attaching the text file and a sample file of what I mean as the syntax for the text might not be right for JaamSim. Please advise. 

Thanks very much. 

Varsha 

ImportingExample.cfg
V_Addition_cost_contact.txt

Harry King

unread,
Jun 27, 2017, 12:46:01 AM6/27/17
to Jaamsim Users Discussion Group
Hi Varsha,

I'm happy to see that you are putting the new FileToVector object to work!

My question is do I need to create a text file for each of the cell that I would like importing or is there a workaround to this like putting all the cells that I need to be imported into one text file and perhaps create variables tell JaamSim which position to use?
HK - Put all your values into one file. The output Value for FileToVector is a array, so all you need to do is to reference the correct index, e.g. '[V_Addition_cost_contact].Value(1)', '[V_Addition_cost_contact].Value(2)', etc. You can confirm the numbers that Values returns by looking in the Output Viewer.

Right now I have tried using the FileToVector object (importing a text file that has one value) and without using include statements in the cfg file. However I am failing to get the .Value property of FileToVector object (when it is read into the ExpressionEntity) but from the output window it reads the file.
HK - Your only mistake is that you didn't provide an index for the array returned by Value. The correct expression is '[V_Addition_cost_contact].Value(1)'. See the attached configuration file.

Incidentally, you don't need to include the full file path to your .txt file. A path relative to your configuration file is sufficient. This is done automatically when the drop down menu option in the Input Editor is used to browse to the desired file.

Harry


ImportingExample - HK.cfg

Varsha Baghar

unread,
Jun 27, 2017, 4:15:16 PM6/27/17
to Jaamsim Users Discussion Group
Thanks very much Harry! That cleared things up well! This FileToVector object is really useful! 

I do have another question. 

I would like to use the imported data in a DiscreteDistribution object that will be linked to a Branch object. I have attached an example of what I mean. Right now I have 0.623 0.377 (going into Sink1 and Sink2 respectively) as the ProbabilityList of the DiscreteDistribution. I have tried to have the following in the Choice of the Branch however it is giving me error of wanting a numeric input. 

'[BranchingPercentage1].Value' '[BranchingPercentage2].Value' 

Please advise on how I should go about with this.

Thanks very much!

Varsha
ImportingIntoDistributionsExample.cfg

Varsha Baghar

unread,
Jun 27, 2017, 5:48:13 PM6/27/17
to Jaamsim Users Discussion Group
Hi again Harry, 

I noticed that the file in the DataFile in the FileToVector does not update even if the simulation time is reset to 0. It only updates if I physically went to re-load the Input file in the FileToVector object (or close and open JaamSim again)

Anyway to make this work when simulation time is reset to 0?


Thanks

Varsha

Harry King

unread,
Jun 27, 2017, 6:17:04 PM6/27/17
to Jaamsim Users Discussion Group
Varsha,

DiscreteDistribution can only accept fixed values for the probabilities. Use the UniformDistribution object to select a random value between 0.0 and 1.0 and compare that value to your probability for branching.

Regarding your other question, the FileToVector and FileToMatrix objects will re-read the data file when they receive an entity. The solution is to generate an entity at time zero and send it to the File object.

Harry

Varsha Baghar

unread,
Jun 27, 2017, 7:11:32 PM6/27/17
to Jaamsim Users Discussion Group
Hi Harry, 
 
Regarding your other question, the FileToVector and FileToMatrix objects will re-read the data file when they receive an entity. The solution is to generate an entity at time zero and send it to the File object.

This works well, thank you! 

DiscreteDistribution can only accept fixed values for the probabilities. Use the UniformDistribution object to select a random value between 0.0 and 1.0 and compare that value to your probability for branching.

I'm not sure how to sample different random numbers as I'm not sure how to link the UniformDistribution object to sample everytime an entity passes through. I've used the generating and sending an entity to the object logic but I failed to sample. I've attached the file, please advise on how to sample the UniformDistribution. 

Regarding the comparing, would the following expression fit to be in the Choice section of the Branch object:

'[UniformDistribution1].Value <[BranchingPercentage1].Value ? [EntitySink1]:[EntitySink2]' 

Thanks 

Varsha

Harry King

unread,
Jun 27, 2017, 8:12:00 PM6/27/17
to Jaamsim Users Discussion Group
Varsha,
 
I'm not sure how to sample different random numbers as I'm not sure how to link the UniformDistribution object to sample everytime an entity passes through.

HK - The distribution will be sampled every time [UniformDistribution1].Value is evaluated within an expression.
 
I've used the generating and sending an entity to the object logic but I failed to sample. I've attached the file, please advise on how to sample the UniformDistribution. 

HK - You forgot to attach the file. 
 
Regarding the comparing, would the following expression fit to be in the Choice section of the Branch object:

'[UniformDistribution1].Value <[BranchingPercentage1].Value ? [EntitySink1]:[EntitySink2]' 

HK - The input to the NextComponentList would be EntitySink1  EntitySink2. The input to Choice would be '[UniformDistribution1].Value < [BranchingPercentage1].Value ? 1 :2'.

Harry

Varsha Baghar

unread,
Jun 27, 2017, 11:40:41 PM6/27/17
to Jaamsim Users Discussion Group
Harry, 

This helps, thank you!

I understand that the UniformDistribution is sampled everytime it is called, however when I tried with using the value of the UniformDistribution in the AttributeDefinitionList, I realised that the Attributes only take a fixed value (evaluated at the beginning)

I would like to have the Attribute of my entity to be changed (when it is at a server) only if the the value of UniformDistribution (the random number) is less than some variable X. All entities start with Att_Contact_Age of 30 and depending on the random number, Att_Contact_Age will change to 4.

The following is what I tried but failed.

Object : Assign1
AttributeDefinitionList: {Att_Contact_Age 30}
AttributeAssignmentList: {  '[Random].Value <[X].Value ? this.obj.Att_Contact_Age = 4 : this.obj.Att_Contact_Age = 30'}

Please advise.

Sorry for bombarding you with messages!

Thanks

Varsha

Harry King

unread,
Jun 27, 2017, 11:48:59 PM6/27/17
to Jaamsim Users Discussion Group
Hi Varsha,
 
I would like to have the Attribute of my entity to be changed (when it is at a server) only if the the value of UniformDistribution (the random number) is less than some variable X. All entities start with Att_Contact_Age of 30 and depending on the random number, Att_Contact_Age will change to 4.

The following is what I tried but failed.

Object : Assign1
AttributeDefinitionList: {Att_Contact_Age 30}
AttributeAssignmentList: {  '[Random].Value <[X].Value ? this.obj.Att_Contact_Age = 4 : this.obj.Att_Contact_Age = 30'}

HK - The attribute to be assigned MUST appear on the left-hand side of the statement. The correct way to write it is:

  'this.obj.Att_Contact_Age = [Random].Value < [X].Value ? 4 : 30'

Sorry for bombarding you with messages!

HK - I'm happy to help!

Harry 

Varsha Baghar

unread,
Jun 28, 2017, 12:02:44 AM6/28/17
to Jaamsim Users Discussion Group
Harry, 
 
That solves my problem!

Thanks very much Harry :) 

Varsha 

Harry King

unread,
Aug 10, 2017, 8:14:33 PM8/10/17
to Jaamsim Users Discussion Group
Varsha,

The following reply to your question above is no longer correct.
 
Regarding your other question, the FileToVector and FileToMatrix objects will re-read the data file when they receive an entity. The solution is to generate an entity at time zero and send it to the File object.

We changed the FileToVector and FileToMatrix objects in release 2017-08 to re-read the data file every time the simulation is started. The data file is not read when the model is first loaded. This means that you don't need to generate the entity at time zero that I described in my early reply.

Harry

Peter Holland

unread,
Nov 22, 2021, 12:18:42 PM11/22/21
to Jaamsim Users Discussion Group
Apologies for reviving a long-dead conversation, but similar to Varsha I've become stuck trying to link FileToMatrix to DiscreteDistribution, which then in turn feeds into a Branch.
Following your advice above, I note that this is impossible, as DiscreteDIstribution requires fixed values, and a solution involving UniformDistribution should instead be found.
However, unlike Varsha, my attribute can take one of 4 values, rather than 2. What would be the most efficient way to read the probability of being assigned one of these attributes from file, and then using that to randomly assign an attribute.
Many thanks,
Peter

Harry King

unread,
Nov 22, 2021, 1:02:47 PM11/22/21
to Jaamsim Users Discussion Group
Peter,

Use a UniformDistribution to create a dimensionless random number between 0 and 1. Then create an ExpressionEntity with the following input to the 'Expression' keyword:

'val = [UniformDistribution1].Value;
val <= this.probs(1) ? 1 :
val <= this.probs(1) + this.probs(2) ? 2 :
val <= this.probs(1) + this.probs(2) + this.probs(3) ? 3 :
4'

This will return the a random index between 1 and 4. In this example, I have assumed that the attribute 'probs' contains the four probabilities. You can replace the entries of 'this.prob' in the expression with direct references to your FileToMatrix object.

Note that it is important to use the local variable 'val' in the expression so that the UniformDistribution is sampled just one time.

Harry

Peter Holland

unread,
Nov 23, 2021, 7:50:57 AM11/23/21
to Jaamsim Users Discussion Group
Many thanks for your details response Harry, that has perfectly clarified what I needed to know.
Reply all
Reply to author
Forward
0 new messages