algorithm - 使用 OptaPlanner 将具有 z 分组约束的未定义数量的组中的 x 实体分组
问题描述
我正在尝试使用 OptaPlanner 对问题进行建模,但找不到建模。(我从 OptaPlanner 开始)。
我的问题如下:
- 我有 x 个命名
Process
为输入的对象 - 我想
Process
将Group
. - 我有 z 分组作为输入的标准
我希望每个
中的最小数量Group
和最大数量都是兼容的(按标准)。Process
Group
Process
Group
下面是一些标准示例:
Process
有字段name
,约束可以是Process must have name starting with 'a'
Process
有字段code
,约束可以是Process must have same code
Process
有字段dateMin
anddateMax
,约束可以是dateMin and dateMax overlap between Process
示例:我有 5 个Process
- P1(名称 = “ab”,代码 = 1)
- P2(名称 = “ac”,代码 = 2)
- P3(名称 = “广告”,代码 = 1)
- P4(名称 = “ba”,代码 = 1)
- P5(名称 = “ca”,代码 = 3)
我想使用上面的示例标准(P1,P2,P3),(P1,P3,P4),(P5)计算以下组合的分数。所有其他组合应排除为不兼容
有没有办法使用 OptaPlanner 做到这一点。我应该研究哪种方法来尝试解决我的问题。
解决方案
听起来大多类似于 CloudBalancing 问题。举个例子,重命名Computer
为Group
(并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(...);
推荐阅读
- laravel - 试图在视图 sev.blade.php 中获取非对象的属性“数量”
- asp.net-mvc - 使用 MVC 创建可变长度的项目符号列表
- linux - cmake_minimum_required 行出错
- javascript - Javascript动态格式化带有项目符号的项目列表
- javascript - 无法设置未定义的属性“functionName”
- bash - 无法通过 bash 创建 IAM 访问密钥
- python - Conda 和 Anaconda 都在 Windows 机器上。Jupyter notebook 无法导入 Python 包
- java - 我的方法的 JUnit 测试
- timer - 用于隐藏和显示表单的计时器算法
- php - Laravel 5.4 显示属于用户的结果