有没有办法提高规则绩效?

时间:2015-01-07 21:46:27

标签: drools optaplanner

我试图配对任务(运行)并利用一组有限的事实而不实例化所有可能的组合。虽然以下规则尚未完成,但性能非常缓慢。我正在寻找建议。

when
$rp : RoutePair()

accumulate( RouteRun( routePair == $rp,  $runId : runId);
            $routeRunListAm : collectList($runId),
            $count : count();
            $count == 4)
accumulate( $pr : PairableRuns( (runId1 == $routeRunListAm.toArray()[0] && runId2 == $routeRunListAm.toArray()[1])
                             || (runId1 == $routeRunListAm.toArray()[0] && runId2 == $routeRunListAm.toArray()[2])
                             || (runId1 == $routeRunListAm.toArray()[0] && runId2 == $routeRunListAm.toArray()[3])
                             || (runId1 == $routeRunListAm.toArray()[1] && runId2 == $routeRunListAm.toArray()[2])
                             || (runId1 == $routeRunListAm.toArray()[1] && runId2 == $routeRunListAm.toArray()[3])
                             || (runId1 == $routeRunListAm.toArray()[2] && runId2 == $routeRunListAm.toArray()[3]));
            $pairableRunsListPm : collectList($pr),
            $count : count();
            $count >= 2)
accumulate( RouteRun( routePair == $rp,  $returnRunId : returnRunId);
            $routeRunListPm : collectList($returnRunId))
accumulate( $pr : PairableRuns( (runId1 == $routeRunListPm.toArray()[0] && runId2 == $routeRunListPm.toArray()[1])
                             || (runId1 == $routeRunListPm.toArray()[0] && runId2 == $routeRunListPm.toArray()[2])
                             || (runId1 == $routeRunListPm.toArray()[0] && runId2 == $routeRunListPm.toArray()[3])
                             || (runId1 == $routeRunListPm.toArray()[1] && runId2 == $routeRunListPm.toArray()[2])
                             || (runId1 == $routeRunListPm.toArray()[1] && runId2 == $routeRunListPm.toArray()[3])
                             || (runId1 == $routeRunListPm.toArray()[2] && runId2 == $routeRunListPm.toArray()[3]));
            $pairableRunsListPm : collectList($pr),
            $count : count();
            $count >= 2)

然后

1 个答案:

答案 0 :(得分:1)

我必须(ab)使用答案,以便我可以提出问题来理解问题。

class RoutePair{...}
class RouteRun( 
    RoutePair routePair;
    RunId runId
}
class PairableRuns(
    RunId runId1; // maybe String or int - doesn't matter
    RunId runId2;
}

第一次收集后,$routeRunListAm是4个RouteRun对象的列表,按任意顺序。但是,如果某些PairableRuns中的runId1和runId2的顺序被该列表中以某种不确定顺序累积的顺序反映,则复杂的布尔表达式将仅返回true。

我发现这个列表必须有完全 4个RouteRun对象 - 为什么不> = 4?条件的第二部分包含几乎相同的CE和约束组合,除了这里第三个累积CE中缺少条件$count == 4

我不确定复杂的布尔表达式应该确定什么,但我认为更简单

$pr: PairableRuns( runId1 memberOf $routeRunListAm,
                   runId2 memberOf $routeRunListAm )

应该达到同样的目的。

但是,我不确定这是否足够。考虑$ routeRunListAm包含7, 12, 14, 22和PairableRuns {7,12}{7,14}{7,22}。这将匹配原始约束以及我提议的形式三次 - 这是期望的吗?

如果没有简明的规范(显示的规则绝对不是),就不可能提出建议。