| 概述 | 组 | 树 | 图形 | 不推荐 | 索引 | 概念 |
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可以获得相同的推理强度。
另请参阅: