【问题标题】:Minizinc lazyfd solution ignores constraintMinizinc lazyfd 解决方案忽略约束
【发布时间】:2017-11-10 19:43:39
【问题描述】:

问题是要找到一个时间表,让一些人以固定规模的团体打高尔夫球(或其他)。 我们必须保证每个玩家一次只在一个组中。

这是我的代码:

int: gr;             % number of groups
int: sz;             % size of groups
int: we;             % number of weeks

int: n=gr*sz;        % number of players

set of int: G=1..gr; % set of group indices
set of int: P=1..n;  % set of players
set of int: W=1..we; % set of weeks

% test instance
gr = 2;
sz = 2;
we = 2;

array[G,W] of var set of P: X;
   %X[g,w] is the set of people that form group with index g in week w


% forall group x, |x| = sz
constraint forall (g in G, w in W) 
  (card (X[g,w]) = sz);

% one person cannot play in two groups simultaneously
constraint forall (g in G, w in W, p in X[g,w], g2 in (g+1..gr))
  (not(p in X[g2,w]));

solve satisfy;

我现在的问题是,如果我使用 G12lazyfd 求解器,即

$ minizinc -b lazy this.mzn

我明白了

X = array2d(1..2 ,1..2 ,[1..2, 1..2, 1..2, 1..2]);
----------

这似乎忽略了我的第二个约束。 另一方面,使用没有lazy选项的G12,即

$ minizinc this.mzn

产量

X = array2d(1..2 ,1..2 ,[1..2, 1..2, 3..4, 3..4]);
----------

这是正确的。 G12 MIP 和 Gecode 也给出了正确的结果。

这怎么可能?以及如何使用惰性求解器以便我可以依赖它?还是只是我的安装搞砸了?

【问题讨论】:

  • 看起来像bug,举报here;除了lazy之外,还有什么理由不使用其他引擎?
  • 性能是我的原因,但我猜性能来自错误......我有一个更复杂的例子,只有惰性求解器能够在合理的时间内解决它 - 起初我没有意识到这是错误的解决方案!
  • 在这个例子中,fd 引擎在 1 秒内找到 36 不同的数组排列,而 lazy 引擎找到 777 不同的排列。所以,是的,这是由于我不知道的引擎本身的错误或其他一些内在限制。
  • 好的,因为这意味着我根本不能信任lazy 引擎,因为我真的不明白这个错误是什么。谢谢!

标签: constraint-programming minizinc


【解决方案1】:

众所周知,G12/lazyFD 在各个地方都被破坏了。问题是 G12 求解器已不再开发,很可能很快就会从发行版中删除。

我会提供 Chuffed 作为替代品。 Chuffed 是用 C++ 编写的具有惰性子句生成的 FD 求解器。它应该是正确的,并且会比 G12 求解器执行得更好(至少在解正确时)。

可以在 software page of the MiniZinc website 上找到 Chuffed 和其他 MiniZinc 求解器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2015-01-02
    相关资源
    最近更新 更多