仅初始化dzn文件中数组的某些元素 [英] Initialize only certain elements of array in dzn file

查看:104
本文介绍了仅初始化dzn文件中数组的某些元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把minizinc弄乱了,我想有一个静态的mzn文件,我只用dzn进行求解. 为了更好地理解这个问题,下面是一个示例:

I'm messing arround with minizinc and I want to have a static mzn file where I make the solving using only the dzn. For a better understanding of the question, here's a sample:

include "globals.mzn";
include "data.dzn";
int: time;
int: n;
int: l=n*n;
array[1..4,0..time,1..l] of var bool: X;
solve satisfy;

我现在只想使用dzn文件初始化X的几个元素(其他元素应该是vars).

I now want to initialize only few elements of X using the dzn file (the other elements should be vars).

dzn看起来像这样

time=1;
n=3;
X[4,1,7]=true;

由于不可能进行初始化,因此我还尝试使用X=array3d(1..4,0..time,1..l,[false,...,false],其中位置(4,1,7)处的元素以外的每个元素均为false.但这会初始化每个元素,由于无法满足我的约束,我无法获得想要的结果.

Since this initialization is impossible, I also tried using X=array3d(1..4,0..time,1..l,[false,...,false] where every element other than the element in position (4,1,7) is false. However this initializes every element and I cannot obtain the result I wish since it cannot satisfy the constraints I have.

是否可以使用dzn文件初始化此数组的一个或某些元素?

Is there a way to initialize only one or some elements of this array using the dzn file?

推荐答案

一种方法是在dzn文件的数据矩阵中使用匿名变量(_).这是一个简单的示例:

One way to do this is to use the anonymous variable (_) in the data matrix in the dzn file. Here is a simple example:

% mzn file 
include "data.dzn";
int: time;
int: n;
array[1..time,1..n] of var bool: X;
solve satisfy;

数据文件:

% data.dzn
time=3;
n=2;
X = array2d(1..3,1..2,
   [_,_,
   _,_,
   _,false
   ]);

请注意,此方法至少需要一个非匿名值,否则将抛出此消息:array literal must contain at least one non-anonymous variable.

Note that this approach requires at least one non-anonymous value, otherwise this message is thrown: array literal must contain at least one non-anonymous variable.

这篇关于仅初始化dzn文件中数组的某些元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆