Idea

Serge A avatar image
3 Likes"
Serge A suggested Serge A edited

[feature request] Table.sort should use a stable sort algorithm

This idea is a follow up to the question with the same name.

Unlike Table.query with "ORDER BY", Table.sort is not stable.

Feature request: Change Table.sort algorithm so that repeated calls to sort() method will not change the order of table rows.

How to reproduce:

Create a global table GlobalTable1 and run this script:

Table t = Table("GlobalTable1");
t.setSize(20, 4);
for (int i = 1; i <= t.numRows; i++) {
t[i][1] = 0;
t[i][2] = uniform(0, 1000);
t[i][3] = uniform(0, 1000);
t[i][4] = uniform(0, 1000);
}
t.setColHeader(1, "Time");
t.setColHeader(2, "A");
t.setColHeader(3, "B");
t.setColHeader(4, "C");

Each time you call

Table("GlobalTable1").sort("Time")

the order of rows in the global table will be different.

This is reproducible in FlexSim 21.2.3 and in earlier versions.

Rationale

So, if you call Table.sort on Reset, and the order of rows impacts simulation, then the results will be different each time you run this simulation.

Why it matters: If Table.sort is not stable, then simulation results may change according to how many times it is called or how many times Reset was pressed. This may be an issue if input or configuration data have to be sorted on reset or during simulation run, because each subsequent reset and run will produce different results. So simulation results are not reproducible if Table.sort is used (FlexSim has to be restarted to reproduce the first simulation run).

Existing Workarounds

1. Custom sort algorithms (less efficient than the builtin method implemented in the DLL), implementations are available in the answer to the original question.

2. Using Table.query and SQL ORDER BY (this sort implementation is stable).

flexscriptfeature requesttable
5 |100000 characters needed characters left characters exceeded

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

No Comments

· Write a Comment

Write a Comment

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

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.