简体   繁体   English

向 Minizinc model 添加“show”语句需要太长时间才能解决

[英]Adding "show" statement to Minizinc model takes too long to solve

I am currently trying to develop a (fairly basic) model in Minizinc.我目前正在尝试在 Minizinc 中开发一个(相当基本的)model。

I have reached a point up until now, where I can run the model and a satisfactory solution is found (basically calling "solve satisfy" gives a solution, haven't yet moved to optimization).到目前为止,我已经达到了一个点,我可以运行 model 并找到一个令人满意的解决方案(基本上调用“解决满足”给出了一个解决方案,尚未转向优化)。

With one particular instance I am getting the solution in about 3.5 minutes .对于一个特定的实例,我在大约 3.5 分钟内得到了解决方案 However, when I add an "output" statement, all of a sudden it gets way too slow (I stopped the run after around 2 hours ).但是,当我添加一个“输出”语句时,它突然变得太慢了(我在大约2 小时后停止了运行)。

For some more context, here is what the model looks like roughly:对于更多上下文,这是 model 大致的样子:

int: resource1; % to read from input file
int: resource2;
...
array [1..someBound] of float: prices;
...

% some modeling variables
array [1..someBound] of var 1..var1UpperBound: myvar1;
array [1..someBound] of var 1..var2UpperBound: myvar2;
....

% my model constraints here
....
....

solve satisfy;

As I said, this would take around 3.5 mins to come up with a solution.正如我所说,这需要大约 3.5 分钟才能提出解决方案。 However, as I was progressing through the modeling, I wanted to find the maximum value in the array prices , and display it just for a sanity check.但是,随着建模的进行,我想找到数组中的最大值prices ,并显示它只是为了进行健全性检查。 So I added:所以我补充说:

float: max_price = max(prices);
....

solve satisfy;
output[show(max_price)];

This suddenly made it so that it was not being solved at all (I stopped running after 2 hours, something is clearly wrong).这突然使它根本没有解决(我在 2 小时后停止运行,显然有问题)。

When playing around with it, I found that if I remove only the output statement from the model, then it is solved within the normal 3.5 minutes, which is weird to me because this should mean that the maximum price is still being found.在玩弄它时,我发现如果我只从 model 中删除output语句,那么它会在正常的 3.5 分钟内解决,这对我来说很奇怪,因为这应该意味着仍在找到最高价格。

Any idea on this?对此有任何想法吗? I did a bit of searching for similar questions / issues, but I could not find anything.我做了一些搜索类似的问题/问题,但我找不到任何东西。 Most results simply seem to point at the documentation, and I did not come across anything related there.大多数结果似乎只是指向文档,我没有遇到任何相关的内容。

I am fairly new to CSP and newer still to Minizinc, so it might be something very basic which I am missing, however I have had no luck so far.我对 CSP 相当陌生,对 Minizinc 还是较新,所以它可能是我所缺少的非常基本的东西,但是到目前为止我还没有运气。 Any input appreciated!任何输入表示赞赏! Thanks!谢谢!

EDIT 1: If this is related, I am using the Minizinc IDE with the default Gecode solver v6.3.0编辑 1:如果这是相关的,我使用 Minizinc IDE 和默认的 Gecode 求解器 v6.3.0

EDIT 2: I came across this so question from before.编辑2:我以前遇到过这个问题。 I believe it is different from my question, because my output does not depend on a modelling variable like in this question.我相信这与我的问题不同,因为我的 output 不依赖于这个问题中的建模变量。 In my case, the solver knows the whole unchanging contents of the array as part of the input.在我的例子中,求解器知道数组的整个不变内容作为输入的一部分。

Similarly to the upvoted solution in this question, I solved this by writing:与这个问题中赞成的解决方案类似,我通过写作解决了这个问题:

solve satisfy;
output[show(decisionVar1), show(decisionVar2), ..., show(decisionVarN), show(max_price)]

Essentially, I forced the output of ALL the decision variables first , and then the variable I was looking to output from the beginning.本质上,我首先强制所有决策变量的 output ,然后是我从一开始就寻找 output 的变量。

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

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