简体   繁体   English

Cloud Balancing Optaplanner:实施过度约束的计划

[英]Cloud Balancing Optaplanner: implement an overconstrained planning

I'm trying to implement a simple cloud balancing system with an Overconstrained plannig with the Optaplanner with java. 我正在尝试使用带有Java的Optaplanner使用Overconstrained plannig实现一个简单的云平衡系统。

favorite I'm trying to implement a simple cloud balancing system with an Overconstrained plannig with the Optaplanner library for Java. 最喜欢的是,我正在尝试使用带有Java的Optaplanner库的Overconstrained plannig实现一个简单的云平衡系统。 I mapping the model to my problem (vehicles and assets) doing a variables substitution cpuPower -> weight, memory -> volume. 我通过将变量替换为cpuPower-> weight,memory-> volume来将模型映射到我的问题(车辆和资产)。 After rules definition for not exceed any of this 2 variables, the drl file: 在规则定义不超过这两个变量中的任何一个之后,drl文件:

package org.optaplanner.examples.cloudbalancing.solver;
    dialect "java"

import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScoreHolder;

import org.optaplanner.examples.cloudbalancing.domain.Mission;
import org.optaplanner.examples.cloudbalancing.domain.Vehicle;
import org.optaplanner.examples.cloudbalancing.domain.Asset;

global HardSoftScoreHolder scoreHolder;

// ############################################################################
// Hard constraints
// ############################################################################

rule "requiredVolumeTotal"
    dialect "mvel"
    when
        $vehicle : Vehicle($maxVolume : maxVolume)
        Number( $totalReqVolume : intValue() > $maxVolume ) from accumulate 
            ( Asset( vehicle == $vehicle , $volume : volume),
            sum($volume)) 
    then
        scoreHolder.addHardConstraintMatch(kcontext, -($totalReqVolume -$maxVolume));
end

rule "requiredWeightTotal"
    dialect "mvel"
    when
        $vehicle : Vehicle($maxWeight : maxWeight)
        Number( $totalReqWeight : intValue() > $maxWeight ) from accumulate 
            ( Asset( vehicle == $vehicle , $weight : weight),
            sum($weight)) 
    then
        scoreHolder.addHardConstraintMatch(kcontext, -($totalReqWeight -$maxWeight));
end

If I use the simple example, I receive a response with all processes asigned although if some of this cannot be assigned to computers. 如果使用简单的示例,尽管其中某些过程无法分配给计算机,但我会收到分配了所有进程的响应。 For this problem, optaplanner purpuse is to change the implementation to a overconstained plannig . 对于这个问题,optaplanner的目的是将实现更改为过度包含的计划 The documentation says: 该文件说:

  • Add a additional score level (usually a medium level between the hard and soft level) by switching Score type. 通过切换“分数”类型,添加一个额外的分数级别(通常是硬性和软性级别之间的中等级别)。
  • Make the planning variable nullable. 使计划变量可为空。
  • Add a score constraint on the new level (so usually a medium constraint) to penalize the number of unassigned entities (or a weighted sum of them). 在新级别上添加得分约束(通常是中等约束)以惩罚未分配实体的数量(或它们的加权总和)。

I'm doing the nullable annotation and the check in the compare method: 我正在做nullable注释和compare方法中的检查:

 @PlanningVariable(valueRangeProviderRefs = {"computerRange"},
        strengthComparatorClass = CloudComputerStrengthComparator.class,
        nullable = true)
public CloudComputer getComputer() {
    return computer;
}

_ _

@Override
public int compare(CloudComputer a, CloudComputer b) {
     if (a == null || b == null)
         return 0;
    return new CompareToBuilder()
            .append(a.getMultiplicand(), b.getMultiplicand())
            .append(b.getCost(), a.getCost()) // Descending (but this is debatable)
            .append(a.getId(), b.getId())
            .toComparison();
}

Whith this changes the processes after the solve method are all unasigned and the solution are incorrect cause ever is 0soft/0hard. 这完全改变了求解方法后,解决方案不正确的原因是0soft / 0hard。

How can define a new constraint (with medium level) to penalize the number of unassigned entities? 如何定义一个新的约束(中等级别)以惩罚未分配实体的数量?

Start by using HardMediumSoftScoreHolder in your DRL and HardMediumSoftScore in your domain. 首先在DRL中使用HardMediumSoftScoreHolderHardMediumSoftScore在域中使用HardMediumSoftScoreHolder Take a look at the hospital bed planning example for the DRL rule. 看一下DRL规则的医院床位规划示例。

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

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