MiniZinc模型的优化

时间:2017-08-06 20:59:08

标签: optimization constraint-programming nonlinear-optimization minizinc

我有一个MiniZinc模型应该找到d [1 .. n]和o [1..k,0 .. n]这样 x [k] = o [k,0] + d [1] * o [k,1] + d [2] * o [k,2] ... d [n] + o [k,n]和o [k,i]的绝对值之和最小化。

我有许多不同的x [i]和d [1..n]应该对所有人保持不变。

我有一个粘贴在下面的工作模型,它在n = 2的情况下很快就找到了一个很好的解决方案(不到一秒)但是,如果我去了n = 3(代码中的num_dims)小时我没有得到答案,除了琐碎的一个(xi = o0),即使问题有点递归,因为2维的好答案可以作为3维的起点,通过使用o0作为xi用于新的2维问题

我之前使用过MiniZinc,但是,我没有OR或优化的背景,因此我真的不知道如何优化我的模型。通过添加约束或以某种方式指导搜索,我会对任何有关如何执行此操作的提示有所帮助。有没有办法在MiniZinc中调试这样的性能问题?

我目前的模特:

% the 1d offsets
array [1 .. num_stmts] of int : x;
x = [-10100, -10001, -10000, -9999, -9900, -101, -100, -99, -1, 1, 99, 100, 101, 9900, 9999, 10000, 10001, 10100];
int : num_stmts = 18;

% how many dimensions we decompose into
int : num_dims = 2;

% the dimension sizes
array [1 .. num_dims] of var int : dims;

% the access offsets
array [1 .. num_stmts, 1 .. num_dims] of var int : offsets;

% the cost function: make access distance (absolute value of offsets) as small as possible
var int : cost = sum (s in 1 .. num_stmts, d in 1 .. num_dims) (abs(offsets[s,d]));

% dimensions must be positive
constraint forall (d in 1 .. num_dims) (dims[d] >= 0);

% offsets * dimensions must be equal to the original offsets
constraint forall (s in 1 .. num_stmts) (
  x[s] = offsets[s,1] + sum(d in 2 .. num_dims) (offsets[s,d] * dims[d-1])
 );

% disallow dimension crossing
constraint forall (s in 1 .. num_stmts, d in 1 .. num_dims) (
  abs(offsets[s,d]) < dims[d]
 );

% all dims together need to match the array size
constraint product (d in 1..num_dims) (dims[d]) = 1300000;

solve minimize cost;

output ["dims = ", show(dims), "\n"] ++
       [ if d == 1 then show_int(6, x[s]) ++ " = " else "" endif ++ 
       " " ++ show_int(4, offsets[s, d]) ++ if d>1 then " * " ++ show(dims[d-1]) else "" endif ++
       if d == num_dims then "\n" else " + " endif  |
   s in 1 .. num_stmts, d in 1 .. num_dims];

1 个答案:

答案 0 :(得分:0)

您是否正在使用MiniZinc IDE?您是否尝试过使用其他求解器?

我正在努力将n随机正整数划分为m组(m < n)的问题,其中每个组的总和应该尽可能地接近其他组数字。

n达到约100且m达到约10时,花费了更长的时间(超过30分钟),结果令人不满意。这是使用默认的地理编码(捆绑)求解器。偶然地,我遍历了每个求解器,发现 COIN-OR CBC(捆绑)在15秒内找到了最佳解决方案。