[英]Get number of attached constraints on a variable in MiniZinc
I have two sets of variables in my Minizinc program.我的 Minizinc 程序中有两组变量。 Each variable from the first set necessarily has several constraints placed on it, but the variables in the second set are only implicitly constrained via their interactions with variables in the first set.
第一组中的每个变量都必然有几个约束,但第二组中的变量仅通过它们与第一组中的变量的交互而受到隐式约束。 This means that each of the variables in the second set may have anywhere from 0 to ~8 constraints placed on it, depending on the values taken by the variables in the first set.
这意味着第二组中的每个变量可能具有从 0 到 ~8 的任何约束,具体取决于第一组中的变量所取的值。
I see that there is a way to reference the number of constraints placed on a variable at search time via the dom_w_deg
search annotation, but I was wondering if there was anyway to access this information at runtime?我看到有一种方法可以通过
dom_w_deg
搜索注释在搜索时引用放置在变量上的约束数量,但我想知道是否有任何方法可以在运行时访问这些信息? I want to do this because I would like to specify additional constraints related to the number of constraints already placed on the variables.我想这样做是因为我想指定与已经放置在变量上的约束数量相关的附加约束。
I realize this is a weird question, and I may be approaching this whole thing the wrong way, but I've been banging my head against this problem for a while now, so figured I'd ask.我意识到这是一个奇怪的问题,我可能以错误的方式处理整个事情,但我一直在努力解决这个问题一段时间,所以我想我会问。
As a general rule, I think that you are approaching your problem erroneously.作为一般规则,我认为您正在错误地处理您的问题。 There are several mis-conceptions in the approach that I can identify leading to this:
我可以识别出导致这种情况的方法中有几个误解:
Without knowing what you are actually trying to achieve, as a general technique you might be interested in using reification, where the truth of a constraint is reflected onto a binary Boolean variable.在不知道您实际尝试实现什么的情况下,作为一种通用技术,您可能对使用具体化感兴趣,其中约束的真实性反映到二进制 Boolean 变量上。 In general, it is good practice to have as little reification as possible, since it does not propagate much, but sometimes it is needed.
一般来说,最好的做法是尽可能少地进行具体化,因为它不会传播太多,但有时需要它。
As a very simple example of using reification, this is a (probably not very good) model that tries to maximize the number of constraints satisfied.作为使用具体化的一个非常简单的示例,这是一个(可能不是很好)model,它试图最大化满足的约束数量。
set of int: Domain = 1..10;
var Domain: x;
var Domain: y;
var Domain: z;
array[1..3] of var bool: holds;
constraint holds[1] <-> x < y;
constraint holds[2] <-> y < z;
constraint holds[3] <-> z < x;
var int: goal;
constraint goal = sum(holds);
solve maximize goal;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.