简体   繁体   English

Optaplanner with Drools score Director——为什么不是空解决方案

[英]Optaplanner with Drools score director -- why not empty solution

I've been looking at the Cloud Balancing demo of OptaPlanner with Drools implementation.我一直在看带有 Drools 实现的 OptaPlanner 的云平衡演示

There are 2 rules for this demo (there actually are 4, but 3 of those rules are of the same logic) --此演示有 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

and

rule "computerCost"  // "Minimize the total maintenance cost."
when
    $computer : CloudComputer($cost : cost)
    exists CloudProcess(computer == $computer)
then
    scoreHolder.addSoftConstraintMatch(kcontext, - $cost);
end

Going by these rules, the optimum solution is NOT to assign ANY of the processes to anyone of the computers.按照这些规则,最佳解决方案是不要将任何进程分配给任何计算机。 This will satisfy the first rule perfectly-- the cpuPower capacity is never exhausted, let alone gone over.这将完美满足第一条规则cpuPower容量永远不会耗尽,更不用说超过了。 And no computers will be used and thus no maintenance cost.并且不会使用计算机,因此没有维护成本。

But the system finds a solution with these 2 rules only-- suboptimizes to assign the processes there are to the computers.但是系统仅通过这 2 条规则找到了解决方案 - 进行次优化以将存在的进程分配给计算机。

what am i missing, where?我错过了什么,在哪里?

Where is OptaPlanner/Drools told to allocate as many processes as possible? OptaPlanner/Drools 在哪里被告知分配尽可能多的进程?

new to Drools. Drools 的新手。 excuse the naive question, if it is.原谅这个幼稚的问题,如果是的话。

//--- UPDATE // - - 更新

the @PlanningEntity() instances to be initialized and put on @PlanningSolution() is the key I think.要初始化并放在@PlanningSolution()上的@PlanningEntity()实例是我认为的关键。 either explicitly in the code, or by a Construction Heuristic configuration as @yurloc suggested, or .. {don't know what else here if any}要么在代码中明确显示,要么通过@yurloc 建议的构造启发式配置,或者.. {不知道这里还有什么}

https://docs.optaplanner.org/latest/optaplanner-docs/html_single/#localSearchOverview : 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.本地搜索需要从一个初始化的解决方案开始,因此通常需要在它之前配置一个构造启发式阶段。

By default, Local Search expects that all entities are initialized and is not allowed to uninitialize them when making changes on the solution.默认情况下,本地搜索期望所有实体都已初始化,并且在对解决方案进行更改时不允许取消初始化它们。 The answer to your last question is that the Construction Heuristic phase assigns a computer to each process even though it actually worsens the score.您最后一个问题的答案是,构造启发式阶段会为每个过程分配一台计算机,即使它实际上会使分数变差。 The Local Search will improve the score in the next phase.本地搜索将在下一阶段提高分数。

Thanks to this default behavior you don't have to write rules that penalize processes that haven't been assigned any computer.由于这种默认行为,您不必编写惩罚尚未分配任何计算机的进程的规则。

For completeness, note that you can make planning variables nullable but that is an advanced topic.为完整起见,请注意您可以将计划变量设为可空,但这是一个高级主题。 Nullable planning variables are usually only useful for over-constrained planning.可空规划变量通常仅对过度约束的规划有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM