首页 > 解决方案 > 使用 OptaPlanner 将具有 z 分组约束的未定义数量的组中的 x 实体分组

问题描述

我正在尝试使用 OptaPlanner 对问题进行建模,但找不到建模。(我从 OptaPlanner 开始)。

我的问题如下:

我希望每个 中的最小数量Group和最大数量都是兼容的(按标准)。ProcessGroupProcessGroup

下面是一些标准示例:

示例:我有 5 个Process

我想使用上面的示例标准(P1,P2,P3),(P1,P3,P4),(P5)计算以下组合的分数。所有其他组合应排除为不兼容

有没有办法使用 OptaPlanner 做到这一点。我应该研究哪种方法来尝试解决我的问题。

标签: algorithmoptaplanner

解决方案


听起来大多类似于 CloudBalancing 问题。举个例子,重命名ComputerGroup(并Process保持Process)。

然后你可以做约束流

// Process have field code, the constraint can be Process must have same code
from(Process)
.groupBy(Process::getComputer, countDistinct(Process::getCode)
.filter((computer, codeCount) -> codeCount > 1)
.penalize(...);

推荐阅读