Jason Botha avatar image
Jason Botha asked Jason Botha commented

Pull data from a table during an experiment

Hi there,

I want add a row and then write data to a global table when an item leaves a processor (just Name and time as an example) but access this during an experimenter run.

I want to some how get all the data entries in the table and write them to a different table after an experiment replication has finished. So my plan was to put the data in to a table called "Processor Data" as items leave the processor. Then at the end of the experiment replication i want to move that data to a "Master" table that will be available at the end of the experiment but will contain columns for ScenarionNum, ReplicationNum, ProcessorName and Time so i have a reference to the experiment.

I have attached a small model but i am struggling to alter the End Replication to achieve this.

Could you guys maybe give me a hand. I know @phil.bobo and i talk briefly about this during the conference.


FlexSim 16.2.0
global tableexperimenterdatadata export
· 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 ·

@Jason Botha, have you checked out this answer? It seems to be pretty close to what you're trying to do.

0 Likes 0 ·

1 Answer

Phil BoBo avatar image
Phil BoBo answered Jason Botha commented

Attached is your model with custom code in the End of Replication trigger that will copy the data from each child replication's "Processor Data" table into the "Master" table on the main process:

/**Copy Processor Data to Master*/
double replication = param(1);
double scenario = param(2);
treenode childexpfolder = param(3);

treenode table = reftable("Processor Data");
string tablename = concat(getname(ownerobject(table)),"S",numtostring(scenario),"R",numtostring(replication));

if (objectexists(childexpfolder)) {  // End of Replication on the main process
	treenode savedtables = node("/savedtables",childexpfolder);
	treenode tablecopy = node(concat("/",tablename),savedtables);
	for (int r = 1; r <= gettablerows(tablecopy); r++) {
		settablenum("Master", gettablerows("Master"), 1, scenario);
		settablenum("Master", gettablerows("Master"), 2, replication);
		settablestr("Master", gettablerows("Master"), 3, gettablestr(tablecopy, r, 1));
		settablenum("Master", gettablerows("Master"), 4, gettablenum(tablecopy, r, 2));
} else {  // End of Replication on the child process
	treenode savedtables = assertsubnode(node("/Tools/Experimenter",model()),"savedtables");
	treenode tablecopy = last(savedtables);

· 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.

Jason Botha avatar image Jason Botha commented ·


You are a legend. Thank you very much!

Have a good day further!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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