I have a simple question regarding the Minizinc's syntax. My input .dzn file contain a set of 2 dimentional arrays (approximately up to 30 arrays), declared as follows:
rates_index_0 = array2d(1..3, 1..501, [ 15, 20, 23, ....
rates_index_12 = array2d(1..3, 1..501, [ 21, 24, 27, ....
...
note: index numbers have gaps in them (e.g., 12 -> 20)
In my model, I need to use one of these arrays depending on the value of the variable. In common programming language I would solve it using a map or a dictionary datastructure. But in Minizinc I am hardcoding this in the following way:
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;
The one obvious problem with this code is that I need to change model each time I change input. Is there a better way how I can code this in a generic way?
Thanks!