Jump to content

Accessing Table Columns By Name Using a Model-Level Table Property


ryanengle14
 Share

Recommended Posts

How do I access a table column by name using a table property defined for the model?  

In my model, I have multiple data tables each with the same named columns defined for each. Each table has a different number of rows.  For a run or a set of replications, I want to select a table to use. I have defined a model-level table property named _SelectedTable to support this. During simulation runs, I want to access this selected table's data by row and column name. Specifically, I want to use this data to update model entity state variables. I also want to stop creating entities when all of the rows of the table have been accessed.

I've tried two partial solutions to this problem (attached), but neither are ideal.
1. Create a large set of decide add-on processes to choose the decide the correct table and explicitly reference it by its name. This requires a lot of redundant steps and maintenance if tables are added or removed. 
The attached example contains just two tables. Controls OptionId and _SelectedTable must be set to either (Option1 and tableOption1) or (Option2 and tableOption2). The first control selects the Entity Type and the second selects the Table.

2. Using the column index number instead of the column name, I found I can use the table property to access the selected table. This method is prone to error if the table schema changes.  It is also unclear which table properties, such as "AvailableRowCount" are accessible via this approach.
The attached example contains two tables just as the previous. The control _SelectedTable chooses which table from which data is acccessed. 

In practice, the data tables will be substantially larger than the ones included in the attachments.

Looking forward to constructive guidance,
Ryan

table_selection_by_name.spfx

table_selection_by_column_number.spfx

Edited by ryanengle14
Link to comment
Share on other sites

Let's see if I can elaborate... 

The following outlines the relevant characters in simio file "table_selection_by_name.spfx." 

Model->Definitions:
Properties:
    OptionId (Entity Property, default=null)
    _SelectedTable (Table Property, default=tableOption1)
States:
    RowId (integer, default=1)
    maxEntities (integer, default=2)

ModelEntity->Definitions:
States:
    _id (Integer, default=0)
    row_num (integer, default=0)
    temp (integer, default=0)

Model->Facility:
ModelEntity Types: Option1, Option2
Source1, Server1, Sink1

Source1->Entity Arrival Logic:
    Entity Type = OptionId (Reference Property)
    InterarrivalTime = 1 second
Source1->Stopping Conditions->Maximum Arrivals = maxEntities
Source1->Add-On Process Triggers->Created Entity = Source1_CreatedEntity

Sink1->Add-On Process Triggers->Entered=Input_Sink1_Entered

Model->Facility->Controls->General:
OptionId = Option1
_SelectedTable = tableOption1

 

Model->Processes:
Input@Sink1 Add-On Processes
Input_Sink1_Entered:
[Begin->
    Tally(temp = ModelEntity.temp)
End]

Source1 Add-on Processes:
Source1_CreatedEntity:
*************************
[Begin->Decide1(IsOption1 = True)->
        Assign(maxEntities = tableOption1.AvailableRowCount)->
        SetRow(tableOption1, RowId)->
        Assign(ModelEntity._id = tableOption1.id, ModelEntity.row_num = tableOption1.row_num, ModelEntity.temp = tableOption1.temp)->
        Assign(RowId = RowId + 1)->End
   Decide1(IsOption1 = False)->
         Decide2(IsOption2 = True)->
              Assign(maxEntities = tableOption2.AvailableRowCount)->
              SetRow(tableOption2, RowId)->
              Assign(ModelEntity._id = tableOption2.id, ModelEntity.row_num = tableOption2.row_num, ModelEntity.temp = tableOption2.temp)->
              Assign(RowId = RowId + 1)->End
         Decide2(IsOption2 = False)->
End]
*************************
It is here that I could like to simply the logic using something like _SelectedTable instead of tableOption1 and tableOption2. I would like to know how to replace Source1_CreatedEntity's above step definitions with something like:

[Begin->
    Assign(maxEntities = _SelectedTable.AvailableRowCount)->
    SetRow(_SelectedTable, RowId)
    Assign(ModelEntity._id = _SelectedTable.id, ModelEntity.row_num = _SelectedTable.row_num, ModelEntity.temp = _SelectedTable.temp)->
    Assign(RowId = RowId + 1)->
End]

But this replacement does not work. 

The following works, but I'm searching for a way to do this without replacing the column name with an indexed value:
[Begin->
    Assign(maxEntities = _SelectedTable.AvailableRowCount)->
    Assign(ModelEntity._id = _SelectedTable.id[RowId, 1], ModelEntity.row_num = _SelectedTable[RowId, 2], ModelEntity.temp = _SelectedTable[RowId, 3] )->
    Assign(RowId = RowId + 1)->
End] 


 

 

 

 

Link to comment
Share on other sites

×
×
  • Create New...