简体   繁体   English

OptaPlanner最佳实践,用于处理确定布尔返回值的计算要求

[英]OptaPlanner Best Practices for handling a requirement for calculations to determine a boolean return value

Consider the cloud computer example. 考虑云计算机示例。 What if the problem set has just been altered just a tad, so it changes the overall equation like this: 如果问题集只是稍作改动,该怎么办?它会像这样改变整个方程:

Suppose one of the requirements (say memory requirement) just had to return a boolean true or false if the processes memory requirement would fit on that cloud computers stock memory allocation or not. 假设其中一个要求(例如,内存要求)仅需返回布尔值true或false,则无论进程内存要求是否适合该云计算机存储的内存分配。

But in order to do so - it first had to perform some java calculations to come up with that determination - like examine values in an array in some way. 但是,为此,它首先必须执行一些Java计算以得出该确定结果,例如以某种方式检查数组中的值。

What are the OptaPlanner best practices for (a) handling the boolean return value (it fits or not) and (b) handling the requirement to perform some java calculations to determine the boolean return value? (a)处理布尔返回值(是否合适)和(b)处理执行一些Java计算以确定布尔返回值的要求时,OptaPlanner最佳做法是什么?

I could be a lot more specific, but I not muddy the waters until required to do so ... 我可以说得更具体些,但是直到需要时我才将水弄糊涂。

this is valid: 这是有效的:

@PlanningEntity class MyEntity {

    private MyValue var;

    @PlanningEntity
    public MyValue getVar() {...}


    // Smart getters
    public boolean isVarCool {
        return var != null && var.isCool();
    }
    public boolean isVarCoolAndalive {
        return var != null && var.isCool() && var.isAlive(); 
    }
    public int getVarWeight {
        return var == null ? 0 : var.getAge() * this.getSomethingElse();
    }

} 

And then use that in a constraint: 然后在约束中使用它:

 rule x when MyEntity(varCool = false) then ... end

 rule y when MyEntity(varWeight > 10) then ... end

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

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