record with var members of different index_set

21 views
Skip to first unread message

Samrat Kadge

unread,
May 5, 2026, 12:18:57 PMMay 5
to MiniZinc
Taking example from minizinc tutorial 2.5.3
data and decisions can be seperated as follows:

%%%%%%%%%%%%%%%%%
enum EmpId;
type EmployeeData = record(
  array[Timespan] of bool: available,
);
type EmployeeVar = record(
  array[Timespan] of var Shift: shifts,
);

array[EmpId] of EmployeeData: employee_data;
array[EmpId] of EmployeeVar: employee_var;
%%%%%%%%%%%%%%%%%%%%%%%%%

How to achieve the case where Timespan is EmpId dependent?
something akin to,

%%%%%%%%%%%%%%%%%%%%%%%%%
type EmployeeData = record(
  list of bool: available,
);
type EmployeeVar = record(
  array[index_set(available)] of var Shift: shifts,
);
%%%%%%%%%%%%%%%%%%%%%%%%%%%

Jip Dekker

unread,
May 6, 2026, 1:55:01 AMMay 6
to MiniZinc
This is possible, and your fragment is almost valid. You just need to use the following definition for EmployeeVar (also using "list of"):
type EmployeeVar = record(
  list of var Shift: shifts,
);

And then instantiate the "employee_var" explicitly:
array[EmpId] of EmployeeVar: employee_var ::output = [
  id: let { array[index_set(employee_data[id].available)] of var Shift: x} in (shifts: x)
  | id in EmpId
];

Samrat Kadge

unread,
May 7, 2026, 3:39:25 AMMay 7
to MiniZinc
Thanks 
1.  Never thought list of var can be "declared" and 'defined" later.
I  guess it can be when datafiles are being read.

2. I had used let, but mostly in functions/predicates or constraints, so this is new too.

3. array[EmpId] of EmployeeVar: employee_var ::output = [
  id: let { array[index_set(employee_data[id].available)] of var Shift: x} in (shifts: x)
  | id in EmpId
];
what is this "id:" for,?

Jip Dekker

unread,
May 10, 2026, 8:01:36 PMMay 10
to MiniZinc
The "id: " is the syntax used to make this an indexed-array-comprehension. Normally, any comprehension would be 1-indexed, and might require an "array1d(<index>, <arr>)" to correctly fit the declared index. With this syntax, that is not required.

This is more often an issue with multidimensional arrays, and there this syntax also works using tuples: `[(i, j): some_call(i + j) | i in X, j in Y]`. This produces an `array[X, Y] of ...`.
Reply all
Reply to author
Forward
0 new messages