使用 4 维数组
Using a 4 dimensional array
我正在尝试在 IBM OPL ILOG 中编写一个 4 维数组,但我不知道如何编写。如果您能提供一个数值示例来帮助我,我将不胜感激。
4维数组是一维、二维、三维数组的自然延伸。它们以完全类似的方式定义。例如
range A = 0..1;
range B = 0..2;
range C = 0..3;
range D = 0..4;
int array4D[A][B][C][D] = [[[[ 0000, 0001, 0002, 0003, 0004 ],
[ 0010, 0011, 0012, 0013, 0014 ],
[ 0020, 0021, 0022, 0023, 0024 ],
[ 0030, 0031, 0032, 0033, 0034 ]],
[[ 0100, 0101, 0102, 0103, 0104 ],
[ 0110, 0111, 0112, 0113, 0114 ],
[ 0120, 0121, 0122, 0123, 0124 ],
[ 0130, 0131, 0132, 0133, 0134 ]],
[[ 0200, 0201, 0202, 0203, 0204 ],
[ 0210, 0211, 0212, 0213, 0214 ],
[ 0220, 0221, 0222, 0223, 0224 ],
[ 0230, 0231, 0232, 0233, 0234 ]]],
[[[ 1000, 1001, 1002, 1003, 1004 ],
[ 1010, 1011, 1012, 1013, 1014 ],
[ 1020, 1021, 1022, 1023, 1024 ],
[ 1030, 1031, 1032, 1033, 1034 ]],
[[ 1100, 1101, 1102, 1103, 1104 ],
[ 1110, 1111, 1112, 1113, 1114 ],
[ 1120, 1121, 1122, 1123, 1124 ],
[ 1130, 1131, 1132, 1133, 1134 ]],
[[ 1200, 1201, 1202, 1203, 1204 ],
[ 1210, 1211, 1212, 1213, 1214 ],
[ 1220, 1221, 1222, 1223, 1224 ],
[ 1230, 1231, 1232, 1233, 1234 ]]]];
execute {
for (var a in A)
for (var b in B)
for (var c in C)
for (var d in D)
writeln("array4D[", a, ", ", b, ", ", c, ", ", d, "]=", array4D[a][b][c][d]);
}
我正在尝试在 IBM OPL ILOG 中编写一个 4 维数组,但我不知道如何编写。如果您能提供一个数值示例来帮助我,我将不胜感激。
4维数组是一维、二维、三维数组的自然延伸。它们以完全类似的方式定义。例如
range A = 0..1;
range B = 0..2;
range C = 0..3;
range D = 0..4;
int array4D[A][B][C][D] = [[[[ 0000, 0001, 0002, 0003, 0004 ],
[ 0010, 0011, 0012, 0013, 0014 ],
[ 0020, 0021, 0022, 0023, 0024 ],
[ 0030, 0031, 0032, 0033, 0034 ]],
[[ 0100, 0101, 0102, 0103, 0104 ],
[ 0110, 0111, 0112, 0113, 0114 ],
[ 0120, 0121, 0122, 0123, 0124 ],
[ 0130, 0131, 0132, 0133, 0134 ]],
[[ 0200, 0201, 0202, 0203, 0204 ],
[ 0210, 0211, 0212, 0213, 0214 ],
[ 0220, 0221, 0222, 0223, 0224 ],
[ 0230, 0231, 0232, 0233, 0234 ]]],
[[[ 1000, 1001, 1002, 1003, 1004 ],
[ 1010, 1011, 1012, 1013, 1014 ],
[ 1020, 1021, 1022, 1023, 1024 ],
[ 1030, 1031, 1032, 1033, 1034 ]],
[[ 1100, 1101, 1102, 1103, 1104 ],
[ 1110, 1111, 1112, 1113, 1114 ],
[ 1120, 1121, 1122, 1123, 1124 ],
[ 1130, 1131, 1132, 1133, 1134 ]],
[[ 1200, 1201, 1202, 1203, 1204 ],
[ 1210, 1211, 1212, 1213, 1214 ],
[ 1220, 1221, 1222, 1223, 1224 ],
[ 1230, 1231, 1232, 1233, 1234 ]]]];
execute {
for (var a in A)
for (var b in B)
for (var c in C)
for (var d in D)
writeln("array4D[", a, ", ", b, ", ", c, ", ", d, "]=", array4D[a][b][c][d]);
}