使用 Choco Solver 的 Var 数组中至少有一个 Var 等于 X
At least one Var equals to X within a Var array using Choco Solver
我正在使用 Choco Solver 并给定一个 int 变量数组,我想要一个约束来检查数组中的至少一个变量是否等于一个静态值...
类似于 IntConstraintFactory#count
但包含以下文档:
/**
* Let N be the number of variables of the VARIABLES collection assigned to value VALUE;
* Enforce condition N >= LIMIT to hold.
* <p>
*
* @param VALUE an int
* @param VARS a vector of variables
* @param LIMIT a variable
*/
public static Constraint at_least(int VALUE, IntVar[] VARS, IntVar LIMIT) {
return new Constraint("At least", /* help here ? */);
}
有人知道它是否存在或我如何有效地实施它吗?
如果你想在Choco Solver中post约束atLeast(VALUE,VARS, LIMIT)
,你可以简单地postcount(VALUE,VARS,X)
,用X
一个IntVar初始域 [0,VARS.length]
和 post arithm(X,">=",LIMIT)
。这将完成这项工作。不需要为此实施特定的约束。
如果要检查VARS
中至少有一个变量等于VALUE
,那就更简单了,只需postcount(VALUE, VARS, X)
和[=18] =] 作为 X
的初始域。因此 VALUE 的最小出现次数将至少为 1
。无需创建第二个变量和算术约束。
我正在使用 Choco Solver 并给定一个 int 变量数组,我想要一个约束来检查数组中的至少一个变量是否等于一个静态值...
类似于 IntConstraintFactory#count
但包含以下文档:
/**
* Let N be the number of variables of the VARIABLES collection assigned to value VALUE;
* Enforce condition N >= LIMIT to hold.
* <p>
*
* @param VALUE an int
* @param VARS a vector of variables
* @param LIMIT a variable
*/
public static Constraint at_least(int VALUE, IntVar[] VARS, IntVar LIMIT) {
return new Constraint("At least", /* help here ? */);
}
有人知道它是否存在或我如何有效地实施它吗?
如果你想在Choco Solver中post约束atLeast(VALUE,VARS, LIMIT)
,你可以简单地postcount(VALUE,VARS,X)
,用X
一个IntVar初始域 [0,VARS.length]
和 post arithm(X,">=",LIMIT)
。这将完成这项工作。不需要为此实施特定的约束。
如果要检查VARS
中至少有一个变量等于VALUE
,那就更简单了,只需postcount(VALUE, VARS, X)
和[=18] =] 作为 X
的初始域。因此 VALUE 的最小出现次数将至少为 1
。无需创建第二个变量和算术约束。