question

Joe S2 avatar image
0 Likes"
Joe S2 asked Jordan Johnson answered

N-Dimensional Tables

Good Morning,

I've recently been working with tables and expanding tables to cover more cases and it got me wondering...

Is it possible to create N-dimensional tables in Flexsim? (example: table[row][column][dim3][...][dimN])

I'm currently working around this by using subnodes to account for higher dimensions but the code is getting a bit busy with Table(node.subnodes[dim3].subnodes[...],subnodes[dimN])[row][col].


FlexSim 20.2.3
flexscripttables
5 |100000

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

1 Answer

Jordan Johnson avatar image
2 Likes"
Jordan Johnson answered

The Table class itself is designed to be a 2D table. If the depth is a multiple of two, you could maybe chain Table calls. The .cell() method gets a node, which you can then treat as a Table:

// Access deep nodes
// .value accesses the value on the final node
Table(node).cell(dim1, dim2).as(Table).cell(dim3, dim4).as(Table).cell(dim5, dim6).value

The [] syntax is also available on the Array class, and Arrays can contain other arrays. So the following code would work:

Array deepArray = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
someNode.value = deepArray;
int value = someNode.value[2][2][1];

The downside of this approach is that it can be harder to investigate the structure; it's not as easy to investigate in the tree as a treenode structure. You can right-click a node with Array data, and choose Explore->As Table. but that view shows a list of entries.

If syntax is the main concern, and you want to have a shorter way of accessing a deep tree structure, you could add a user command, something like this:

// You can make a user command that takes a node and an array,
// and returns a value from the substructure
double someValue = getDeepData(node, [2, 1, 3, 1, 2]);

The code for that command would look like this:

/**Custom Code*/
treenode target = param(1);
Array keys = param(2);

for (int i = 1; i <= keys.length; i++) {
    // this could throw exceptions if the key requests a nonexistant subnode
    target = target.subnodes[keys[i]];
}

return target.value;

See the attached example for an example of each of these approaches.

IndexExample.fsm


indexexample.fsm (23.6 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.