question

anon-user avatar image
0 Likes"
anon-user asked Ben Wilson commented

How to copy GlobalTable to ArrivalsSource

Multiple Arrivals Sources need to be rewritten at the start of the simulation,

So,

I want to be able to describe data collectively in a global table.


When I reset the simulation,

Is it possible to copy the specified row of GlobalTable to ArrivalsSource?


FlexSim 21.0.5
global tablesourcesource schedulearrival scheduleflexsim 21.0.5
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Hi anonymous user, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered

The only way to do this, that I know of, is to adjust the tree of the source.

I wrote a user command that allows copying (parts of) a global table into the source schedule or sequence. It has five parameters. (Code below or in the attached model)

- The first is a reference to the source object for which you want to adjust the table.
- The second is the global from which you would like to copy the entries.
- The third controls whether the changes are applied to the "schedule" or the "sequence" table, by given one of the two names.
- The fourth and fifth parameters are optional and let you specify the start and end row inbetween which you want to copy over the entries. If you don't pass these in, the entire table will be copied over, deleting any leftover rows, if there were more rows in the source table than the global one.

An example (also in the script window of the model) would be:

UpdateSchedule(Model.find("Source1"), Table("GlobalTable1"), "sequence", 1, 3);

This would adjust the first three rows of the arrival sequence of Source1 to be equal to the first three rows of GlobalTable1.

You can use this command in any reset trigger and loop through all sources you want to copy the changes to.

arrivals_fm.fsm


User command code:

/**Custom Code*/
Object Source = param(1);
Table Data = param(2);
string Mode = param(3);
int StartRow = param(4);
int EndRow = param(5);

int deleteFurtherEntries = 0;
if(!StartRow)
{
    StartRow = 1;
}
if(EndRow > Data.numRows)
{
    EndRow = Data.numRows;
}
if(!EndRow)
{
    EndRow = Data.numRows;
    deleteFurtherEntries = 1;
}

treenode schedule = Source.find(">variables/" + Mode);
treenode curRowNode;
treenode curColNode;

for(int row = StartRow; row <= EndRow; row++)
{
    if(schedule.subnodes.length < row)
    {
        schedule.subnodes.add();
    }
    curRowNode = schedule.subnodes[row];
    curRowNode.name = Data.getRowHeader(row).as(string);

    for(int col = 1; col <= Data.numCols; col++)
    {
    if(curRowNode.subnodes.length < col)
    {
        curRowNode.subnodes.add();
    }
    curColNode = curRowNode.subnodes[col];
    curColNode.name = Data.getColHeader(col).as(string);
    curColNode.value = Data[row][col];
    }
}

if(deleteFurtherEntries)
{
    while(schedule.subnodes.length > EndRow)
    {
        schedule.subnodes[schedule.subnodes.length].destroy();
    }
}


Note: Alternatively, you could use a process flow to create the items and reference the global table directly in the "Create Objects" activity.


arrivals-fm.fsm (52.4 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.