I'm attempting to pair tasks (runs) and leverage a limited set of facts without instantiating all the possible combinations. While the following rule is not complete yet, performance is very slow. I'm looking for suggestions.
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)
then