[英]is there a way to provide search annotation in minizinc predicate?
I am wondering if I could provide search order in a minizinc predicate. 我想知道是否可以在minizinc谓词中提供搜索顺序。 For instance I have code like this
例如我有这样的代码
predicate numbers_falling_within_range (var int:a, var int:b)=
let {
var 213233..4535553: num;
} in
(a+b<num*64+64) /\ (a+b>num*64); %% pick a and b such that their sum fall within a range
Here I would prefer when it executes the predicate, it solves for num
first, before a
or b
. 在这里,我希望在执行谓词时先在
a
或b
之前先求解num
。 Is there a way to do it? 有办法吗? I am looking for something similar to solve order annotation we provide at end of model.
我正在寻找类似于解决模型末尾提供的订单注释的内容。
The only place where you can devise a search strategy is in you solve item, but you might also ask: "Can I devise a search strategy over (to a predicate) local variables?" 可以设计搜索策略的唯一地方是解决项目,但是您可能还会问:“我可以针对局部变量设计一个搜索策略吗?”
Since MiniZinc is a scoped language, you can't really access these variables outside of the predicate, but you can elevate them to the global scope: 由于MiniZinc是一种作用域语言,因此您不能真正在谓词之外访问这些变量,但可以将它们提升为全局作用域:
int num_num = ???;
array[1..num_num] of var 213233..4535553: nums;
predicate numbers_falling_within_range (var int: a, var int: b, var int: num) =
(a+b<num*64+64) /\ (a+b>num*64);
% a call to the predicate
constraint numbers_falling_within_range(x, y, nums[1]);
solve ::int_search(nums, input_order, indomain_min) minimize cost;
Note that this kind of approach is only possible if the can (over-)estimate the number of calls to the predicate and give each call a different (now global) variable. 请注意,只有在可以(高估)谓词的调用次数并为每个调用赋予不同的变量(现在是全局变量)的情况下,这种方法才可行。 Unless your predicate is recursive, this should be relatively straightforward.
除非您的谓词是递归的,否则这应该相对简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.