Make K different (cardinality) google OR-TOOLS

旧时模样 提交于 2021-01-28 11:06:15

问题


I'm wondering if there is a generalisation of solver.AllDifferent(x) in google or-tools that allows for the specification of how many different elements I allow.

So if len(x) = 4, then AllDifferent(x) means that len(set(x)) = 4. But what if I just want to enforce "at least 2 different", so: len(set(x)) >=2 ?

Is there a constraint that generalises AllDifferent to be able to set the cardinality of the solution variable ?

来源:https://stackoverflow.com/questions/48021694/make-k-different-cardinality-google-or-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!