Simio
  • Randomrow function for a table with foreign key relationship

  • General Simio discussions. THIS IS *NOT* A GOOD PLACE FOR SUPPORT QUESTIONS.
    To limit spam this and all Public Forums have very limited ability to attach files. We recommend that support issues and more technical topics be initiated inside one of the Simio Insider (SI) forums below where you can attach your model and see example solutions. See above Welcome forum to join Simio Insiders.
General Simio discussions. THIS IS *NOT* A GOOD PLACE FOR SUPPORT QUESTIONS.
To limit spam this and all Public Forums have very limited ability to attach files. We recommend that support issues and more technical topics be initiated inside one of the Simio Insider (SI) forums below where you can attach your model and see example solutions. See above Welcome forum to join Simio Insiders.
 #3430  by haoh7493
 Wed Mar 20, 2013 11:15 pm
Hi All simio users

I have a problem on using the the randomrow function.
I use foreign key connection to assign the entity a part of the table, and I want to pick row with a column's value by randomrow.

However, although I only assign part of the table to the entity, the randomrow still randomly pick row from the entire table. It ends up picks some row number is invalid.

Is the randomrow function just designed which can't implement this way? or some method to avoid it? or some other way to achieve the same result?

Thanks

Hao Huang
 #4551  by MikeKk
 Tue Sep 10, 2013 9:55 pm
Hi,

I have also come across this issue, I find it irritating because with the "Set Row" step, I can use the Mix.RandomRow to set a weighted table row, but I cannot specify to use only relational rows. Whereas with the "search" step I can specify relational rows only, but not use the Mix.RandomRow for the weighted selection of the specified rows.

Mike
 #5222  by gdrake
 Wed Mar 05, 2014 11:25 am
Just a note that in Simio Sprint 102 software, the TableName.PropertyName.RandomRow function will have been fixed to respect primary-foreign key relationships. Thus, if the executing token or associated object as a reference to a selection set into the table, then the 'RandomRow' function will return a random row index just within the related row set, not an index into the entire table.
 #5889  by fpeschiera
 Mon Aug 25, 2014 12:20 pm
Sorry to bring an old post but I think we are having a behavior similar to the explained here:

We have test this with Simio 106.
We have a data table being read from Excel. This specific table has 3 columns: node_in, node_out and probability (with the two first being keys).

In Simio we plan to use the table in the following way:
Every time an entity arrives at node "node_in" we want to assign the entity a destination taken from "node_out" with the probability "probability", this will be stored in the entity "node_in" for later use.

Our main problem is that we do not understand how to do this query.

We have used the "randomRow" function before to pick a random row from a table with just one key but we have not arrived to mix this with a "search" function to get a subset of the rows with the correct "node_in" before doing the randomRow.

Our Search step (that executes inside the "node_in") has the following content:
Match condition: Data.node_in==currentnode
Search Expression: Data.probability.RandomRow

As a test, we assigned the probability of 100 for a given row but Simio returns all (any) rows in the search step.

any help is greatly appreciated.
 #5891  by gdrake
 Tue Aug 26, 2014 4:31 pm
A possible rough approach:

1) Add a data table. Let's name it 'Node_In_KeyTable' table. This table has a single column named 'Node_In' of type Node property (to take a node name). Set that column to be a Key column.

2) Add another data table. Let's name it 'Node_Out_ProbabilityTable'. This table has three columns. It has a FOREIGN Key column named 'Node_In'. Specify the Table Key of that foreign key column to be 'Node_In_KeyTable.Node_In'. Then add a 'Node_Out' node property column and a 'Probability' numeric column to that table.

3) So...above, you have set up two tables with primary-foreign key relationships.

4) In some model logic, you want to assign an entity a destination from the 'Node_Out_ProbabilityTable', First, use a SetRow step to assign the entity a row in the 'Node_In_KeyTable' that corresponds to the 'Node_In' that you are interested in. Because there is a primary-foreign key relationship between that table and the probability table, that is going to automatically filter down the selected row set to just be the referenced rows.

5) You could then do something like this: SetNode step whereby the Node Name is specified as Node_Out_ProbabilityTable[Node_Out_ProbabilityTable.Probability.RandomRow].Node_Out. Looking at that expression, what you are doing is you are going into that table, you are indexing into that table looking at the probability column by picking a random row using probabilities (which will only be the selection set corresponding to the 'Node_Out' key)...and pulling out a 'Node_Out' node reference.