我尝试使用此规则:
rule "conformSyncConstraint"
when
$syn_con : SyncConstraint(
$left_stp_period : leftSTP.period,
$right_stp_period : rightSTP.period)
eval( ($left_stp_period.dayOfWeek == $right_stp_period.dayOfWeek &&
$left_stp_period.dayOrder == $right_stp_period.dayOrder) == false)
then
insertLogical(new IntConstraintOccurrence("conformSyncConstraint",
ConstraintType.NEGATIVE_HARD,
1,
$syn_con));
end
但我面对这个错误,这似乎是一个黑盒子:
Rule Compilation error : [Rule name='conformSyncConstraint']
in/co/technovia/timetabler/domain/Rule_conformSyncConstraint_4401252830cd4ee7bc49416ead3da86c.java (8:1459) : The field Period.dayOfWeek is not visible
in/co/technovia/timetabler/domain/Rule_conformSyncConstraint_4401252830cd4ee7bc49416ead3da86c.java (8:1490) : The field Period.dayOfWeek is not visible
at org.drools.planner.config.solver.SolverConfig.buildRuleBase(SolverConfig.java:238)
at org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:170)
at org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
at in.co.technovia.timetabler.TimeTableApp.createSolver(TimeTableApp.java:61)
at in.co.technovia.timetabler.TimeTableApp.main(TimeTableApp.java:45)
这里出了什么问题?
答案 0 :(得分:3)
无论何时使用eval,您都会回退到正在使用的方言。在您的情况下,您使用的是java方言,因此您必须使用java语法编写表达式:.getDayOfWeek()而不是.dayOfWeek。
如果您不使用evals,或者将方言切换为mvel,则可以使用简化语法。
E.g:
when
$syn_con : SyncConstraint(
leftSTP.period.dayOfWeek != rightSTP.period.dayOfWeek ||
leftSTP.period.dayOrder != rightSTP.period.dayOrder
)
then