/** * Penalize a match by the {@link ConstraintWeight} negated and multiplied with the specific weightMultiplier per score level. * Slower than {@link #penalize(RuleContext, int)}. * @param kcontext never null, the magic variable in DRL * @param hardWeightMultiplier at least 0 * @param softWeightMultiplier at least 0 */ public void penalize(RuleContext kcontext, int hardWeightMultiplier, int softWeightMultiplier) { reward(kcontext, -hardWeightMultiplier, -softWeightMultiplier); }
/** * Penalize a match by the {@link ConstraintWeight} negated. * @param kcontext never null, the magic variable in DRL */ public void penalize(RuleContext kcontext) { reward(kcontext, -1); }
/** * Penalize a match by the {@link ConstraintWeight} negated and multiplied with the weightMultiplier for all score levels. * @param kcontext never null, the magic variable in DRL * @param weightMultiplier at least 0 */ public void penalize(RuleContext kcontext, int weightMultiplier) { reward(kcontext, -weightMultiplier); }
/** * Reward a match by the {@link ConstraintWeight}. * @param kcontext never null, the magic variable in DRL */ public void reward(RuleContext kcontext) { reward(kcontext, 1); }
public void rewardPenalize(boolean constraintMatchEnabled) { HardSoftScoreHolder scoreHolder = new HardSoftScoreHolder(constraintMatchEnabled); Rule hard1 = mockRule("hard1"); scoreHolder.configureConstraintWeight(hard1, HardSoftScore.ofHard(10)); Rule hard2 = mockRule("hard2"); scoreHolder.configureConstraintWeight(hard2, HardSoftScore.ofHard(100)); Rule soft1 = mockRule("soft1"); scoreHolder.configureConstraintWeight(soft1, HardSoftScore.ofSoft(10)); Rule soft2 = mockRule("soft2"); scoreHolder.configureConstraintWeight(soft2, HardSoftScore.ofSoft(100)); scoreHolder.penalize(mockRuleContext(hard1)); assertEquals(HardSoftScore.of(-10, 0), scoreHolder.extractScore(0)); scoreHolder.penalize(mockRuleContext(hard2), 2); assertEquals(HardSoftScore.of(-210, 0), scoreHolder.extractScore(0)); scoreHolder.reward(mockRuleContext(soft1)); assertEquals(HardSoftScore.of(-210, 10), scoreHolder.extractScore(0)); scoreHolder.reward(mockRuleContext(soft2), 3); assertEquals(HardSoftScore.of(-210, 310), scoreHolder.extractScore(0)); }