我有一个关于 Minizinc 语法的简单问题。我的输入 .dzn 文件包含一组 2 维数组(大约最多 30 个数组),声明如下:
rates_index_0 = array2d(1..3, 1..501, [ 15, 20, 23, ....
rates_index_12 = array2d(1..3, 1..501, [ 21, 24, 27, ....
...
注意:索引号中有间隔(例如,12 -> 20)
在我的模型中,我需要根据变量的值使用这些数组之一。在通用编程语言中,我会使用地图或字典数据结构来解决它。但在 Minizinc 中,我通过以下方式对其进行硬编码:
function var int: get_rate(int: index, var int: load, int: dc_size) =
if index == 0 then
rates_index_0[dc_size, load]
else if index == 12 then
rates_index_12[dc_size, load]
else if index == 16 then
rates_index_16[dc_size, load]
else if index == 20 then
rates_index_20[dc_size, load]
else
assert(false, "unknown index", 0)
endif endif endif endif;
这段代码的一个明显问题是每次更改输入时都需要更改模型。有没有更好的方法可以以通用方式对其进行编码?
谢谢!