【发布时间】:2019-09-04 15:00:17
【问题描述】:
我正在阅读车辆路线示例 (v 7.25.0),并偶然发现了一些关于什么是问题事实与规划实体的混淆。
第 4.3.5.4 节中的文档指出:
A planning variable that is chained either:
- Directly points to a problem fact (or planning entity), which is called an anchor.
- Points to another planning entity with the same planning variable, which recursively points to an anchor.
然后在它的正下方还声明:
Every chain always has exactly one anchor. The anchor is a problem fact, never a planning entity.
这种相互矛盾的信息导致了我的困惑 #1:锚总是一个有问题的事实,还是它可以是一个计划实体?
我问的原因是因为Vehicle(锚)实现了Standstill,它在vehicleRoutingSolverConfig.xml中定义为:
<entityClass>org.optaplanner.examples.vehiclerouting.domain.Standstill</entityClass>
这让我相信Vehicle 将“继承”规划实体属性。
然后,我尝试创建一个 drools 规则,该规则使用 Vehicle 上的实例方法对与车辆关联的最大客户数设置硬约束,该方法通过将 nextCustomer 阴影变量遍历到 null 来返回计数,例如:
when
Vehicle(totalCustomers > 5, $totalCustomers : totalCustomers)
then
scoreHolder.addHardConstraintMatch(kcontext, 5 - $totalCustomers)
它似乎不起作用:违反了硬约束并且硬分数保持为 0(没有其他硬约束,这只是一个测试——另外,我让计划器运行了很长时间使用 CH + 本地搜索和断点显示此方法在不同时间点返回 > 5,包括最终解决方案,因此这不仅仅是配置问题)。
我错过了什么?
【问题讨论】:
标签: optaplanner