如何在 drools 中实现低于 objective
How to achieve below objective in drools
我正在尝试做以下事情。请检查。
rule "new rule"
salience -101
dialect "mvel"
when
$pricingLineItem : PricingLineItem( $ackId : ackId, $prefix : prefix )
$baseUpChargeConfig : BaseUpChargeConfig( $baseOptionId : baseOptionId,
prefix == $prefix )
$pricingOptionType : PricingOptionType( ackId == $ackId,
$optionId : optionId, $optionValue : optionValue )
$baseOptionConfig : BaseOptionConfig( bOptionValue == $optionValue,
bOptionCode == $optionId ,id == $baseOptionId )
then
$pricingLineItem.increment($baseOptionId);
System.out.println("excuted - "+ $baseOptionId +" "+$baseOptionConfig);
end
一个 PricngLineItem 将有多个 BaseUpChargeConfig 对象匹配。在 BaseUpChargeConfig 对象中,我们获取所有相关的 BaseOptionConfig 对象,然后尝试与 PricingLineItem 的 PricingOptionType 对象匹配。我需要采用与 PricngLineItem 的 PricingOptionType 对象最大匹配的最佳 BaseUpChargeConfig 对象。
编辑
假设我有一个带有 ackID、前缀值的 PricingLineItem 对象。
现在,我有多组基于 PricingLineItem 前缀值的 BaseUpChargeConfig 对象。
现在关于 ackId 值,我在规则引擎中有一组特定的 PricingOptionType 对象。
并且在 baseOptionId 值上,我有多个 BaseOptionConfig 对象。
在 PricingOptionType 和 BaseOptionConfig 对象中,我需要比较选项代码和选项值。
如果两者都匹配,我需要为一个 perticuler BaseUpChrageConfig 收集所有匹配的定价选项类型。
以同样的方式,这将检查所有其他 BaseUpChrageConfig 对象 BaseOptionConfig 并匹配。
现在最高匹配的BaseOptionConfig对象;我们将 select 将 BaseUpChargeConfig 作为我们目的的最佳对象。
希望你明白。
目前我正在通过 java 方法通过传递所有三个并在 java 中计算。
public void matchOptions(BaseUpChargeConfig config, List pricingOptionList,
列表 baseOptionList) {
if ((pricingOptionList != null && !pricingOptionList.isEmpty())
&& (baseOptionList != null && !baseOptionList.isEmpty())) {
List<PricingOptionType> matchedOption = null;
matchedOption = new ArrayList<PricingOptionType>();
for (PricingOptionType pOption : pricingOptionList) {
int matchCount = 0;
for (BaseOptionConfig bConfig : baseOptionList) {
boolean optioncodeMatch = pOption.getOptionCode() == bConfig.getBaseOptionCode();
boolean optionValueMatch = pOption.getOptionValue() == bConfig.getBaseOptionValue();
if (optioncodeMatch && optionValueMatch) {
matchedOption.add(pOption);
matchCount++;
}
}
if (matchCount > 0) {
if (bestBaseUpChargeConfig != null) {
optionMatchCount = matchCount;
bestBaseUpChargeConfig = config;
matchedPrcOptionList = matchedOption;
} else if (matchCount == optionMatchCount) {
bestBaseUpChargeConfig = null;
matchedOption = null;
matchedPrcOptionList.clear();
} else if (matchCount > optionMatchCount) {
optionMatchCount = matchCount;
bestBaseUpChargeConfig = config;
matchedPrcOptionList = matchedOption;
} else {
// do nothing
}
}
}
} else {
// do nothing
}
}
谢谢
这是用 5.5 编译的,所以 6.x 也不应该有问题。
除非您考虑涉及派生事实的更复杂的评估,否则无法避免累加的重复。
rule "find best BaseUpChargeConfig"
when
// pick up some PricingLineItem
$pli: PricingLineItem( $prefix: prefix, $ackId : ackId )
// it should have a BaseUpChargeConfig with a matching prefix
$bucc: BaseUpChargeConfig( prefix == $prefix,
$baseOptionId : baseOptionId )
// count BaseOptionConfigs (linked to BaseUpChargeConfig) matching
// PricingOptionTypes, by option id/code and option value
accumulate(
BaseOptionConfig( id == $baseOptionId,
$ocod: bOptionCode, $oval: bOptionValue )
and
PricingOptionType( ackId == $ackId,
optionId == $ocod, optionValue == $oval );
$count: count(1) )
// The $count computed above is the maximum if we don't have another
// BaseUpChargeConfig (for that prefix) where the count of the
// subordinate BaseOptionConfigs is greater than $count
not(
( BaseUpChargeConfig( this != $bucc,
prefix == $prefix,
$baseOptionId2 : baseOptionId )
and
accumulate(
BaseOptionConfig( id == $baseOptionId2,
$ocod2: bOptionCode, $oval2: bOptionValue )
and
PricingOptionType( ackId == $ackId,
optionId == $ocod2, optionValue == $oval2);
$count2: count(1);
$count2 > $count ) ) )
then
System.out.println( "best BaseUpChargeConfig: " + $baseOptionId );
end
我正在尝试做以下事情。请检查。
rule "new rule"
salience -101
dialect "mvel"
when
$pricingLineItem : PricingLineItem( $ackId : ackId, $prefix : prefix )
$baseUpChargeConfig : BaseUpChargeConfig( $baseOptionId : baseOptionId,
prefix == $prefix )
$pricingOptionType : PricingOptionType( ackId == $ackId,
$optionId : optionId, $optionValue : optionValue )
$baseOptionConfig : BaseOptionConfig( bOptionValue == $optionValue,
bOptionCode == $optionId ,id == $baseOptionId )
then
$pricingLineItem.increment($baseOptionId);
System.out.println("excuted - "+ $baseOptionId +" "+$baseOptionConfig);
end
一个 PricngLineItem 将有多个 BaseUpChargeConfig 对象匹配。在 BaseUpChargeConfig 对象中,我们获取所有相关的 BaseOptionConfig 对象,然后尝试与 PricingLineItem 的 PricingOptionType 对象匹配。我需要采用与 PricngLineItem 的 PricingOptionType 对象最大匹配的最佳 BaseUpChargeConfig 对象。
编辑
假设我有一个带有 ackID、前缀值的 PricingLineItem 对象。 现在,我有多组基于 PricingLineItem 前缀值的 BaseUpChargeConfig 对象。
现在关于 ackId 值,我在规则引擎中有一组特定的 PricingOptionType 对象。
并且在 baseOptionId 值上,我有多个 BaseOptionConfig 对象。
在 PricingOptionType 和 BaseOptionConfig 对象中,我需要比较选项代码和选项值。
如果两者都匹配,我需要为一个 perticuler BaseUpChrageConfig 收集所有匹配的定价选项类型。
以同样的方式,这将检查所有其他 BaseUpChrageConfig 对象 BaseOptionConfig 并匹配。
现在最高匹配的BaseOptionConfig对象;我们将 select 将 BaseUpChargeConfig 作为我们目的的最佳对象。
希望你明白。
目前我正在通过 java 方法通过传递所有三个并在 java 中计算。
public void matchOptions(BaseUpChargeConfig config, List pricingOptionList, 列表 baseOptionList) {
if ((pricingOptionList != null && !pricingOptionList.isEmpty())
&& (baseOptionList != null && !baseOptionList.isEmpty())) {
List<PricingOptionType> matchedOption = null;
matchedOption = new ArrayList<PricingOptionType>();
for (PricingOptionType pOption : pricingOptionList) {
int matchCount = 0;
for (BaseOptionConfig bConfig : baseOptionList) {
boolean optioncodeMatch = pOption.getOptionCode() == bConfig.getBaseOptionCode();
boolean optionValueMatch = pOption.getOptionValue() == bConfig.getBaseOptionValue();
if (optioncodeMatch && optionValueMatch) {
matchedOption.add(pOption);
matchCount++;
}
}
if (matchCount > 0) {
if (bestBaseUpChargeConfig != null) {
optionMatchCount = matchCount;
bestBaseUpChargeConfig = config;
matchedPrcOptionList = matchedOption;
} else if (matchCount == optionMatchCount) {
bestBaseUpChargeConfig = null;
matchedOption = null;
matchedPrcOptionList.clear();
} else if (matchCount > optionMatchCount) {
optionMatchCount = matchCount;
bestBaseUpChargeConfig = config;
matchedPrcOptionList = matchedOption;
} else {
// do nothing
}
}
}
} else {
// do nothing
}
}
谢谢
这是用 5.5 编译的,所以 6.x 也不应该有问题。
除非您考虑涉及派生事实的更复杂的评估,否则无法避免累加的重复。
rule "find best BaseUpChargeConfig"
when
// pick up some PricingLineItem
$pli: PricingLineItem( $prefix: prefix, $ackId : ackId )
// it should have a BaseUpChargeConfig with a matching prefix
$bucc: BaseUpChargeConfig( prefix == $prefix,
$baseOptionId : baseOptionId )
// count BaseOptionConfigs (linked to BaseUpChargeConfig) matching
// PricingOptionTypes, by option id/code and option value
accumulate(
BaseOptionConfig( id == $baseOptionId,
$ocod: bOptionCode, $oval: bOptionValue )
and
PricingOptionType( ackId == $ackId,
optionId == $ocod, optionValue == $oval );
$count: count(1) )
// The $count computed above is the maximum if we don't have another
// BaseUpChargeConfig (for that prefix) where the count of the
// subordinate BaseOptionConfigs is greater than $count
not(
( BaseUpChargeConfig( this != $bucc,
prefix == $prefix,
$baseOptionId2 : baseOptionId )
and
accumulate(
BaseOptionConfig( id == $baseOptionId2,
$ocod2: bOptionCode, $oval2: bOptionValue )
and
PricingOptionType( ackId == $ackId,
optionId == $ocod2, optionValue == $oval2);
$count2: count(1);
$count2 > $count ) ) )
then
System.out.println( "best BaseUpChargeConfig: " + $baseOptionId );
end