Hi all, 

It is 2 days I am fighting with a strange behaviour of insertLogical in rules 
having from pattern in conditions : it works the first time, and not after ... 

----------------------------------------- 
Here is my use-case (simplified) : 

I have a class that represent a Flight. A Flight has a start/end datetime and 
is associated with a Airplane and a list of Crew : 
class Flight { 
String airplaneId; 
List<String> crewIds; 
Date start; 
Date end; 
} 

I want to maintain an alert list that contains all overlaps for each airplane 
and each crew. So I have rules like: 

rule "Overlap Airplane" 
when 
$f1 : Flight($airplaneId : airplaneId) 
$f2 : Flight(this != $1, airplaneId == $airplaneId, ... and periods 
intersecting ... ) 
then 
insertLogical(new Alert(...)); 
end 

rule "Overlap Crews" 
when 
$f1 : Flight() 
$crew : String from $f1.getCrewIds() 
$f2 : Flight(this != $1, eval($f2.getCrewIds().contains($crew)) , ... and 
periods intersecting ... ) 
then 
insertLogical(new Alert(...)); 
end 


----------------------------------------- 
Ok. So what I do to test all that stuff : 
- create a new session 
- add a first single Flight --> no alerts at all, normal 
- add a second Flight insersecting the first one with same airplane and same 
crews list --> 3 new alerts inserted (one for airplane, one for each crew) : 
normal 
- remove this second Flight --> the 3 preivous alerts are retracted : still ok 
- re-add this second Flight --> only the 'airplane' rule triggers, I only get 
one new alert insteads of the previous same 3 .... The alerts not inserted 
correspond to the rule having 'from' in it 


----------------------------------------- 
To test that it is the source of the problem, I add a new explicit association 
object that I insert in WM : 
class CrewAffectation { 
String idCrew; 
String idFlight; 
} 

For each inserted Flight, I also insert corresponding new CrewAffectation 
objects. (in case of retract, I retract them of course). 
I change the last rule to something like : 

rule "Overlap Crews" 
when 
$f1 : Flight($id1 : id 
$f2 : Flight(this != $1, $id2 : id, ... and periods intersecting ... ) 
$crewAff1 : CrewAffectation($idCrew : idCrew, idFlight== $id1) 
$crewAff2 : CrewAffectation(idCrew == $idCrew, idFlight== $id2) 
then 
insertLogical(new Alert(...)); 
end 
And with this 'no-from' approach, everything is working as expected. 

----------------------------------------- 
In addition, I suspect the truth maintenance system to have leaks, and notably 
in the source kBase. 
Why ? Because I was facing problems by reusing the same kBase to generate 
multiples kSessions : The first session created reacted well, while all the 
folowing not. 
And it was in fact the same problem as the one described here : usage of from 
and insertLogical in the same rule. 
The first created session adds and retract my 3 alerts, the second created 
session only adds the airplane alert. 

With using the explicit association object, I can reuse my kBase and everything 
is working well. 

----------------------------------------- 
Does someone already faced the problem ? 
Does it looks like a real bug to dev team or am I doing something wrong (but as 
it work once, I guess it is a bug) ? 


Vincent 

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to