一次运行一个.mzn文件运行多个数据实例

问题描述 投票:0回答:1

想象一下,我有一个.mzn文件名,作为model.mzn,其中定义了一些参数(b,c,d),b,c,d参数的值包含在数据文件调用data1.dzn中。举个例子:

b=[component1];
c=[10,20,30];
d=[30]

想象一下,现在我可以从我的IDE以及命令行中获得结果。

想象一下,我想用相同的模型运行b,c,d的不同数据值(例如:我有3个不同的数据文件,其中b,c和d的数据值不同)

data1.dzn :b=[component1];c=[10,20,30];d=[30]
data2.dzn :b=[component2];c=[15,25,35];d=[35]
data3.dzn :b=[component3];c=[40,50,60];d=[70]

有没有一种方法可以一次运行所有这些数据实例(不分别运行每个模型和数据)并在IDE或命令提示符中一次获得最佳答案(就像对数据实例使用for循环一样)。

command-prompt minizinc
1个回答
0
投票

[一种可能性是概括问题的编码:bd可以是N个元素的数组,c是Nx3的维矩阵。

示例:(对于N=3

test.mzn

%%%%%%%%%%%%%%%%%%
%%% PARAMETERS %%%
%%%%%%%%%%%%%%%%%%

enum Component = { component1, component2, component3 };
array [1..3] of Component: b;
array [1..3, 1..3] of int: c;
array [1..3] of int: d;

%%%%%%%%%%%%%%%%%
%%% VARIABLES %%%
%%%%%%%%%%%%%%%%%

var 1..3: index :: output_var;
var int: goal;

% dummy optimization goal to showcase
% the encoding    
constraint goal = sum(i in 1..3)(c[index,i]);

%%%%%%%%%%%%
%%% GOAL %%%
%%%%%%%%%%%%

solve minimize goal;

output [""]
    ++ ["index = \(index);\n"]
    ++ ["b = \(b[index]);\n"]
    ++ ["c = \([c[index, i] | i in 1..3]);\n"]
    ++ ["d = \(d[index]);\n"];

test.dzn

b = [component1, component2, component3];
c = [|10, 20, 30,
     |15, 25, 35,
     |40, 50, 60|];
d = [30, 35, 70];

输出:

index = 1;
b = component1;
c = [10, 20, 30];
d = 30;
----------
==========
© www.soinside.com 2019 - 2024. All rights reserved.