简体   繁体   English

MiniZinc-(多维)数组的数组

[英]MiniZinc - Array of (multidimensional) array

I would like to know if it's possible to have array of (multidimensional) array in MiniZinc language. 我想知道MiniZinc语言是否可以包含(多维)数组的数组。

Indeed, I would like to resolve a timetabling problem with workers. 确实,我想解决工人的时间表问题。 My goal is to check if they are available at least 1 day per week. 我的目标是检查每周至少有1天是否有空。 Each worker is indexed by an integer and I have their schedule per week. 每个工人都用一个整数索引,我每周有他们的时间表。

For me, an array like : [[number_of_week, weekday]] could be a solution. 对我来说,类似[[number_of_week, weekday]]的数组可能是一个解决方案。

For example, worker 1 who is available monday/friday in week 1 and tuesday/thursday in week 2 can be modeled by the following array : (« 1 » means that the worker is available) 例如,可以通过以下数组来模拟第1周的星期一/星期五和第2周的星期二/星期四可用的工作人员1 :(“ 1»表示该工作人员有空)

[[| 1,0,0,0,1, | 0,1,0,1,0 |], [...], ...]

If it's possible, how to declare this kind of array ? 如果可能,如何声明这种数组? And I'm also open to any advice on modeling this constraint. 而且,我也乐于接受任何有关建模此约束的建议。

Sorry for my imperfect English and thank you in advance, Nicolas. 抱歉,我英语不完美,在此先谢谢您,尼古拉斯。

I'm not sure I understand your question fully, but you can have multi dimensional arrays as follows: 我不确定我是否完全理解您的问题,但是您可以按如下所示使用多维数组:

array[1..3,1..3] of int: a = array2d(1..3,1..3,
    [1,0,0,
     0,1,0,
     1,1,0]);

or using another syntax: 或使用其他语法:

array[1..3,1..3] of int: a = 
  [|1,0,0
   |0,1,0
   |1,1,0|];

However, you cannot have arrays in arrays, ie this is not allowed: 但是,你不能在阵列阵列,即这是不允许的:

% This is NOT valid MiniZinc code! 
array[1..3,1..3] of int: a = 
  [[[1,0,0],[1,0,1]],
   [[0,1,0],[0,1,1]],
   [[1,1,0],[0,0,0]]];

Note also that one cannot have "ragged" arrays: the number of element in each row and each column must be the same. 还要注意,不能有“参差不齐”的数组:每一行和每一列中的元素数必须相同。

Regarding you specific constraint you might - if I understand your description - define a 3D array like this: 关于您的特定约束,如果我理解您的描述,则可以这样定义3D数组:

int:_num_workers = 2;
int: num_weeks = 3;
int: num_days = 4;
array[1..num_workers,1..num_weeks,1..num_days] of int: a =
     array3d(1..num_workers,1..num_weeks,1..num_days,
  [
   % worker 1
   % week1   week2     week3
   1,0,0,1,  1,1,0,1,  0,0,1,1,

   % worker 2
   % week1   week2      week3
   1,0,0,0,  0,0,0,1,   1,1,1,0
  ]);

Note especially the array3d construct which creates a 3D array. 特别要注意创建3D数组的array3d构造。 So you can access day d of week e for worker w with a[w,e,d] . 因此,您可以使用a[w,e,d]为工作人员w访问第e周的第d天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM