<br> Regis,<br><br> You are probably having problems with mutable predicates, when using "<span><font face="Arial" size="2">subject.allocatedDays</font></span>". As a first step to understand your problem, I strongly encourage you to make constraints flat, i.e., avoid using nested accessors. After you get used to what can and what can't be done, you can go back to use nested accessors. <br>
Also, I suggest you use modify() block instead of update():<br><br><span><b><font color="#960000">
<p align="left"><font face="Arial" size="2">rule <br></font></p></font></b><font face="Arial"><font size="2"><font color="#008000">"allocate"</font></font></font>
<p align="left"><b><font color="#960000"><font face="Arial" size="2">when</font></font></b></p>
<p align="left"><font size="2"><font face="Arial">$lesson : Lesson(allocated ==
</font><b><font color="#960000"><font face="Arial">false</font></font></b></font><font face="Arial" size="2">, session.type
== Session.DISTINCT )</font></p><p align="left"><font face="Arial" size="2">$subject : Subject( $allocatedDays : allocatedDays ) from $lesson.subject<br></font></p>
<p align="left"><font size="2"><font face="Arial">$availableHour : Hour(allocated ==
</font><b><font color="#960000"><font face="Arial">false</font></font></b></font><font face="Arial"><font size="2">, day
<b><font color="#960000">not</font></b></font></font><font face="Arial"><font size="2"> <b><font color="#960000">memberOf</font></b></font></font><font face="Arial" size="2"> $allocatedDays)</font></p>
<p align="left"><b><font color="#960000"><font face="Arial" size="2">then</font></font></b></p>
<p align="left"><font face="Arial" size="2">modify( $lesson) {</font></p><p align="left"><font face="Arial" size="2"> setHour($availableHour ),<br></font></p>
<p align="left"><font size="2"><font face="Arial"> setAllocated(</font><b><font color="#960000"><font face="Arial">true</font></font></b></font><font face="Arial" size="2">)</font></p><p align="left"><font face="Arial" size="2">}<br>
</font></p><p align="left"><font face="Arial" size="2">modify( $availableHour )</font></p><p align="left"><font face="Arial" size="2"> setSubject($lesson.getSubject()),<br></font></p>
<p align="left"><font size="2"><font face="Arial"> setAllocated(</font><b><font color="#960000"><font face="Arial">true</font></font></b></font><font face="Arial" size="2"> )</font></p><p align="left"><font face="Arial" size="2">}<br>
</font></p><font color="#960000"><font size="2"><font face="Arial"><b></b></font></font></font><font color="#960000"><p><font face="Arial" size="2"><b>end</b></font><br></p>
<div><span><span><br></span></span></div></font></span><div class="gmail_quote"> Hope it helps.<br><br> []s<br> Edson<br> <br>2008/4/14 Piccand, Regis <<a href="mailto:rpiccand@verisign.com">rpiccand@verisign.com</a>>:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div><span><font face="Arial" size="2">Hi
all,</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">I am evaluating
Drools and am stuck with a simple rule that selects elements which do not
correspond to the condition... Since I am updating objects in the RHD, I guess
it has to do with my wrong understanding (and the cache...?)</font></span></div>
<div><span><span><font color="#000000" face="Arial" size="2"></font></span></span> </div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">I am trying to
allocate lessons to periods (hour). My object model can be summarize is as
follows :</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">Lesson
</font></span></div>
<div><span> <font face="Arial" size="2">boolean : allocated // true if the lesson has been
allocated to an hour</font></span></div>
<div><span> <font face="Arial" size="2">int :
session
// a session is a bunch of lessons</font></span></div>
<div><span><font face="Arial" size="2">
Subject : subject // an allocated lesson is assigned a
subject</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">Subject</font></span></div>
<div><span> <font face="Arial" size="2">Set<Day> : allocatedDays // days in which this subject is taught -
checked before allocation, as a subject can only be taught once a
day</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">Hour</font></span></div>
<div><span> <font face="Arial" size="2">boolean : allocated // true is this hour has been allocated with a
lesson</font></span></div>
<div><span> D<font face="Arial" size="2">ay : day // the day this hour belongs to - required to check with
subject.allocatedDays</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">I put in the
workingMemory a bunch of Lesson objects, which have been set with Subject
and Session id. I also put a bunch of Hour object, set with a
Day.</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><font face="Arial" size="2">My rule is as
follows:</font></span></div>
<div><span><font face="Arial" size="2"></font></span> </div>
<div><span><b><font color="#960000">
<p align="left"><font face="Arial" size="2">rule</font></p></font></b><font face="Arial"><font size="2"> <font color="#008000">"allocate"</font></font></font>
<p align="left"><font face="Arial" size="2"></font></p>
<p align="left"><b><font color="#960000"><font face="Arial" size="2">when</font></font></b></p>
<p align="left"><font size="2"><font face="Arial">$lesson : Lesson(allocated ==
</font><b><font color="#960000"><font face="Arial">false</font></font></b></font><font face="Arial" size="2">, session.type
== Session.DISTINCT, $allocatedDays : subject.allocatedDays)</font></p>
<p align="left"><font size="2"><font face="Arial">$availableHour : Hour(allocated ==
</font><b><font color="#960000"><font face="Arial">false</font></font></b></font><font face="Arial"><font size="2">, day
<b><font color="#960000">not</font></b></font></font><font face="Arial"><font size="2"> <b><font color="#960000">memberOf</font></b></font></font><font face="Arial" size="2"> $allocatedDays)</font></p>
<p align="left"><font face="Arial" size="2"></font></p>
<p align="left"><b><font color="#960000"><font face="Arial" size="2">then</font></font></b></p>
<p align="left"><font face="Arial" size="2">$lesson.setHour($availableHour )
;</font></p>
<p align="left"><font size="2"><font face="Arial">$lesson.setAllocated(</font><b><font color="#960000"><font face="Arial">true</font></font></b></font><font face="Arial" size="2">) ;</font></p>
<p align="left"><b><font color="#960000"><font face="Arial" size="2">update</font></font></b><font face="Arial" size="2">($lesson);</font></p>
<p align="left"><font face="Arial" size="2"></font></p>
<p align="left"><font face="Arial" size="2">$availableHour.setSubject($lesson.getSubject()) ;</font></p>
<p align="left"><font size="2"><font face="Arial">$availableHour.setAllocated(</font><b><font color="#960000"><font face="Arial">true</font></font></b></font><font face="Arial" size="2"> );</font></p>
<p align="left"><b><font color="#960000"><font face="Arial" size="2">update</font></font></b><font face="Arial" size="2">($availableHour);</font></p>
<p align="left"><font face="Arial" size="2"></font></p><font color="#960000">
<p><font face="Arial" size="2"><b>end</b></font></p>
<div><span><span><font color="#000000" face="Arial" size="2">When I set a debug on the first line of the THEN
section, I can see that sometimes $availableHour.allocated == true ... sometimes
$lesson.allocated == true (although it's an implicit And statement
...)</font></span></span></div>
<div>
<p><font face="Arial"><font color="#000000"><font size="2"><span>Therefore, I can see that the update() works, but it
seems that the rule does not use the updated object (due to shallow copy
??)</span></font></font></font></p>
<p><font face="Arial"><font color="#000000"><font size="2"><span></span>A<span>ny help more
than welcome</span></font></font></font></p></div></font></span></div>
<p><span><font color="#000000" face="Arial" size="2">Regis</font></span></p>
<p><span><font color="#000000" face="Arial" size="2"></font></span> </p></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>