Reputation: 3598
I am trying to model something similar to a job shop problem. There are multiple jobs, which can be done in multiple ways, which use a varying number of tasks to accomplish the job.
I have set up this data structure to represent that information:
enum Job;
enum Option;
int: maxTasks;
set of int: TaskIndex = 1..maxTasks;
enum Task;
array[Job, Option, TaskIndex] of opt Task: jobOptions;
If jobOptions[j, o, index]
exists, it is the index
th task of option o
of job j
. If it is missing, that option for that job does not use the maximum number of tasks, and this is one of the empty slots.
I am failing to see how I can initialize this array. If it was a 2d array, I could do
jobOptions = [|
T1, T2 |
T3, <>
|];
Since it is 3d, want to do something like
jobOptions = array3d(Job, Option, TaskIndex, [
% Job 1
T1, T2, % Option 1
T3, <>, % Option 2
% Job 2
T2, T4, % Option 1
<>, <>, % No second option
|];
However, this fails, because there are three versions of array3d, which take arrays of (par) int
, var int
and var opt int.
I need a fourth version, taking (par) opt int
, since <>
is of type var opt int
.
I initially tried to do something like
array[Job] of array[int] of array[int]: jobOptions
to make a "non-square" array, but if that if feasible, I was not able to figure out the correct syntax.
Is there a way to initialize a 3d parameter array with missing optional elements? Alternatively, is there a better way to present this data?
Upvotes: 0
Views: 155
Reputation: 5786
UPDATE: The issue has been resolved on the develop
branch of the MiniZinc compiler. In the next release, >2.1.6
, it should be possible to use the array3d
function for optional parameter types.
The array3d
function for opt
parameters is a feature that is currently missing in the compiler. I would suggest creating an Issue in the GitHub repository: https://github.com/MiniZinc/libminizinc/issues
Normally I would suggest changing the type to its variable counterpart as an alternative (array[Job, Option, TaskIndex] of var opt Task: jobOptions;
). Although this is not ideal for type checking, it can still be assigned like the parameter version (and will work with the current version of array3d). Furthermore, assigned variables will behave as parameters in the compiler. If you get into any problems with the type checker you could always call the fix
intrinsic to bind it to a parameter.
However, when I tried this locally it seems I'm running into a segmentation fault in the compiler. I would suggest you try the same and if you run into the same problem, then, again, report the issue in the GitHub repository: https://github.com/MiniZinc/libminizinc/issues
Upvotes: 1