Optaplanner with Drools score director——为什么不空解
Optaplanner with Drools score director -- why not empty solution
我一直在研究 Cloud Balancing demo OptaPlanner 与 Drools 的实施。
这个demo有2条规则(实际有4条,但其中3条规则是同一个逻辑)--
rule "requiredCpuPowerTotal"
when
$computer : CloudComputer($cpuPower : cpuPower)
accumulate(
CloudProcess(
computer == $computer,
$requiredCpuPower : requiredCpuPower);
$requiredCpuPowerTotal : sum($requiredCpuPower);
$requiredCpuPowerTotal > $cpuPower
)
then
scoreHolder.addHardConstraintMatch(kcontext, $cpuPower - $requiredCpuPowerTotal);
end
和
rule "computerCost" // "Minimize the total maintenance cost."
when
$computer : CloudComputer($cost : cost)
exists CloudProcess(computer == $computer)
then
scoreHolder.addSoftConstraintMatch(kcontext, - $cost);
end
按照这些规则,最佳解决方案是不将任何进程分配给任何计算机。这将完美满足第一条规则——cpuPower
容量永远不会耗尽,更不用说超过了。
并且不会使用计算机,因此没有维护成本。
但系统仅使用这 2 条规则找到了解决方案 -- 次优化以将现有进程分配给计算机。
我错过了什么,在哪里?
在哪里告诉OptaPlanner/Drools分配尽可能多的进程?
Drools 新手。请原谅这个天真的问题,如果是的话。
//--- 更新
要初始化的@PlanningEntity()
实例放在@PlanningSolution()
上是我认为的关键。要么明确地在代码中,要么通过 @yurloc 建议的 Construction Heuristic 配置,或者 .. {不知道这里还有什么,如果有的话}
https://docs.optaplanner.org/latest/optaplanner-docs/html_single/#localSearchOverview:
Local Search needs to start from an initialized solution, therefore it’s usually required to configure a Construction Heuristic phase before it.
默认情况下,本地搜索期望所有实体都已初始化,并且不允许在对解决方案进行更改时取消初始化它们。您最后一个问题的答案是 Construction Heuristic 阶段为每个进程分配一台计算机,即使它实际上会使分数变差。本地搜索将在下一阶段提高分数。
由于这种默认行为,您不必编写规则来惩罚尚未分配任何计算机的进程。
为了完整起见,请注意您可以制定计划变量 nullable 但这是一个高级主题。可为空的规划变量通常仅对过度约束规划有用。
我一直在研究 Cloud Balancing demo OptaPlanner 与 Drools 的实施。
这个demo有2条规则(实际有4条,但其中3条规则是同一个逻辑)--
rule "requiredCpuPowerTotal"
when
$computer : CloudComputer($cpuPower : cpuPower)
accumulate(
CloudProcess(
computer == $computer,
$requiredCpuPower : requiredCpuPower);
$requiredCpuPowerTotal : sum($requiredCpuPower);
$requiredCpuPowerTotal > $cpuPower
)
then
scoreHolder.addHardConstraintMatch(kcontext, $cpuPower - $requiredCpuPowerTotal);
end
和
rule "computerCost" // "Minimize the total maintenance cost."
when
$computer : CloudComputer($cost : cost)
exists CloudProcess(computer == $computer)
then
scoreHolder.addSoftConstraintMatch(kcontext, - $cost);
end
按照这些规则,最佳解决方案是不将任何进程分配给任何计算机。这将完美满足第一条规则——cpuPower
容量永远不会耗尽,更不用说超过了。
并且不会使用计算机,因此没有维护成本。
但系统仅使用这 2 条规则找到了解决方案 -- 次优化以将现有进程分配给计算机。
我错过了什么,在哪里?
在哪里告诉OptaPlanner/Drools分配尽可能多的进程?
Drools 新手。请原谅这个天真的问题,如果是的话。
//--- 更新
要初始化的@PlanningEntity()
实例放在@PlanningSolution()
上是我认为的关键。要么明确地在代码中,要么通过 @yurloc 建议的 Construction Heuristic 配置,或者 .. {不知道这里还有什么,如果有的话}
https://docs.optaplanner.org/latest/optaplanner-docs/html_single/#localSearchOverview:
Local Search needs to start from an initialized solution, therefore it’s usually required to configure a Construction Heuristic phase before it.
默认情况下,本地搜索期望所有实体都已初始化,并且不允许在对解决方案进行更改时取消初始化它们。您最后一个问题的答案是 Construction Heuristic 阶段为每个进程分配一台计算机,即使它实际上会使分数变差。本地搜索将在下一阶段提高分数。
由于这种默认行为,您不必编写规则来惩罚尚未分配任何计算机的进程。
为了完整起见,请注意您可以制定计划变量 nullable 但这是一个高级主题。可为空的规划变量通常仅对过度约束规划有用。