record with var members of different index_set

17 views
Skip to first unread message

Samrat Kadge

unread,
May 5, 2026, 12:18:57 PM (4 days ago) May 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 AM (3 days ago) May 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 AM (2 days ago) May 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,?
Reply all
Reply to author
Forward
0 new messages