跳至主内容
框架 无框架

IloCount

public 'IloIntExprArg'IloCount(const 'IloIntExprArray'x, 'IloInt'价值)
定义文件: ilconcert/iloexpression.h
创建一个受约束的整数表达式,等于数组中固定为给定值的变量个数。

This function creates a new constrained integer expression equal to the number of variables in x that are fixed to the value value. 这种计数约束与 "IloDistribute约束关系密切,但通常更容易使用。 下面的示例展示了创建具有相同解决方案集的模型的两种方法。

使用 "IloCount

   IloIntVarArraycards(env, 10, 0, 100);
   forIloInti = 0; i < 10; i++)
     mdl.add(cards[i] ==IloCount(x,i + 1));
 

使用 "IloDistribute

   IloIntVarArraycards(env, 10, 0, 100);
   IloIntArrayvalues(env, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
   IloIntVarArrayx(env, 100, 1, 10);
   mdl.addIloDistribute(env,cards, values, x));
 

当 CP 优化器提取 "IloCount表达式时,会将其与计算同一变量集的其他表达式分组,以提供更强的推理能力。 这意味着用 "IloCount代替 "IloDistribute可以获得相同的推理强度。

另请参阅: