我正在分析一个类似课程的时间折叠项目,其中每个
Lesson
都有一个Timeslot
作为计划变量。我通过在全局单例中使用状态来显着改进分数计算。此全局状态会在每次 Timeslot
更改时重新计算,并通过以下约束在分数计算中得到尊重:
factory.forEach(Lesson.class).groupBy(t->0,ConstraintCollectors.toList()).impact(
HardMediumSoft.ofHard(1),(key,list)->GlobalState.getSingleton().getImpact()).asConstraint(id);
分组可确保全局状态的影响在
Lesson
的每次更改时更新,并且所有课程仅一起计入一次。现在,这个约束定义会导致一些浪费的操作,例如空的 groupKey t->0
和有些不必要的 toList()
操作,但这些不必要的操作似乎是我的热路径的原因,即以下方法调用
Group1Mapping0CollectorUniNode.createGroupKey
是否有这样一个约束的更少浪费的定义,以便我可以进一步优化我的热路径?
注意:使用像
这样的约束factory.forEach(GlobalState.class).impact(t->t.getImpact())
如本答案中所述不起作用,因为每次更改Lesson
对象时都需要重新计算约束。
.forEach(MyEntity.class)
.join(MyConstraintConfiguration.class)
.filter((entity, constraintConfig) -> entity.foo > constraintConfig.pauze)
.penalize(..., (entity, constraintConfig) -> entity.foo - constraintConfig.pauze)
该单例通常是 @PlanningSolution 类上的 @ProblemFactProperty 或 @ContraintConfigurationProperty。