<div dir="ltr">ups, i created a nice endless loop with my proposed solution. :-)<br><br>the correct (still ugly) solution is:<br><br>rule 
  &quot;fact1 should be smaller then 1&quot;<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  $f : UserFact($fact1 : fact1 &gt;= 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not IntConstraintOccurence(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ruleId == &quot;fact1 should be smaller then 1&quot;,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; constraintType == ConstraintType.NEGATIVE_SOFT,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; causes contains $f,<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; weight != $fact1)&nbsp; // the weight has to be different, else the rule should not fire<br><br>
&nbsp;&nbsp;&nbsp; then 
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // use the value of fact1 to determine the error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new IntConstraintOccurence(&quot;fact1 should be smaller then 1&quot;, $fact1, $f )); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  <br>
end<br><br>
rule 
  &quot;fact1 should be smaller then 1, old constraint exists&quot;<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  $f : UserFact($fact1 : fact1 &gt;= 1);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // see if there is already a fact in the <br>
&nbsp; &nbsp; &nbsp; &nbsp; $oldConstraint : IntConstraintOccurence(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ruleId == &quot;fact1 should be smaller then 1&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; constraintType == ConstraintType.NEGATIVE_SOFT,<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; causes contains $f,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; weight != $fact1)&nbsp; // the weight has to be different, else the rule should not fire&nbsp;&nbsp; <br>then 
  <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retract($oldConstraint); // manually retract the obsolete fact<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // use the value of fact1 to determine the error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new IntConstraintOccurence(&quot;fact1 should be smaller then 1&quot;,ConstraintType.NEGATIVE_<div dir="ltr">SOFT,&nbsp; $fact1, $f )); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  <br>
end</div><br><br><br><br><br><div class="gmail_quote">On Tue, Oct 7, 2008 at 6:59 PM, tim tim <span dir="ltr">&lt;<a href="mailto:timbaermannextra@googlemail.com">timbaermannextra@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr">thanks, you are right, that is kind of a solution. but not really what i am<br>
looking for.<br>i am using drools-solver, and the &quot;CreatedFact&quot; is an IntConstraintOccurrence, which i do not want to change.<br>
&nbsp;<br>maybe i should make the example more specific for my problem.<br><br>i have a rule, used for the solver:<br><br>rule 
  &quot;fact1 should be smaller then 1&quot;<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  $f : UserFact(fact1 &gt;= 1);<br>&nbsp;&nbsp;&nbsp; then 
  <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // use the value of fact1 to determine the error<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new IntConstraintOccurence(&quot;fact1 should be smaller then 1&quot;, $f.getFact1(), $f )); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  <br>end<br><br><br>i have a Move that decrements fact1, so that after the move the error should be 1 smaller.<br>but the move is almost never triggered, because the old constraintOccurence is not retracted from memory and the new one added anyway, <br>

hence the error is nearly double after the move, as now two constraintOccurences represent the same error.<br><br><br>what i could think of is something like this:<br><br>one rule for the first test:<br><br>
rule 
  &quot;fact1 should be smaller then 1&quot;<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  $f : UserFact(fact1 &gt;= 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not IntConstraintOccurence(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ruleId == &quot;fact1 should be smaller then 1&quot;,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; constraintType == ConstraintType.NEGATIVE_SOFT,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; causes contains $f)<br>
&nbsp;&nbsp;&nbsp; then 
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // use the value of fact1 to determine the error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new IntConstraintOccurence(&quot;fact1 should be smaller then 1&quot;, $f.getFact1(), $f )); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  <br>
end<br><br>and a second rule, when the first rule has already fired before:<br><br>
rule 
  &quot;fact1 should be smaller then 1, old constraint exists&quot;<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  $f : UserFact(fact1 &gt;= 1);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // see if there is already a fact in the <br>
&nbsp; &nbsp; &nbsp; &nbsp; $oldConstraint : IntConstraintOccurence(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ruleId == &quot;fact1 should be smaller then 1&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; constraintType == ConstraintType.NEGATIVE_SOFT,<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; causes contains $f)&nbsp;&nbsp; <br>then 
  <br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retract($oldConstraint); // manually retract the obsolete fact<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // use the value of fact1 to determine the error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new IntConstraintOccurence(&quot;fact1 should be smaller then 1&quot;,ConstraintType.NEGATIVE_SOFT,&nbsp; $f.getFact1(), $f )); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  <br>
end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>this solution seems very verbose for such a common task. and again, i do not understand, why an obsolete fact is not<br>retracted automatically?<br><br>best, tim<br><br><div class="gmail_quote">

On Tue, Oct 7, 2008 at 5:57 PM, Gras, Patrick <span dir="ltr">&lt;Patrick.Gras@generali.ch&gt;</span> wrote:<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 size="2" color="#0000ff" face="Arial">Hello,</font></span></div>
<div><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" color="#0000ff" face="Arial">If you 
can change the code for CreatedFact and let it have a reference to UserFact and 
change the rule to:</font></span></div>
<div><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" color="#0000ff" face="Arial"><font size="3" color="#000000" face="Times New Roman"><div>rule &quot;fact = 
1&quot;<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $f : 
UserFact(fact1 == 1);<br>&nbsp;&nbsp;&nbsp; then 
<br></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new 
CreatedFact($f)); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
<br>end</font><br></font></span></div>
<div><span><font size="2" color="#0000ff" face="Arial">you 
will also have to overide equals and hashcode for CreatedFact so that several 
CreatedFacts referencing the same UserFact are considered 
equal...</font></span></div>
<div><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" color="#0000ff" face="Arial">But 
with this solution CreatedFact will always be up to date with the value of 
UserFact even without firing the rules and maybe it&#39;s not what you 
want...</font></span></div>
<div><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" color="#0000ff" face="Arial">-Patrick</font></span></div>
<blockquote dir="ltr" style="margin-right: 0px;">
  <div dir="ltr" align="left"><font size="2" face="Tahoma">-----Message d&#39;origine-----<br><b>De&nbsp;:</b> 
  <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> 
  [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>]<b>De la part de</b> tim 
  tim<br><b>Envoyé&nbsp;:</b> mardi, 7. octobre 2008 16:53<br><b>À&nbsp;:</b> 
  <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><b>Objet&nbsp;:</b> [rules-users] insertLogical 
  and modifyRetract<br><br></font></div><div><div></div><div>
  <div dir="ltr">Hello,<br><br>I am a bit confused about how insertLogical() 
  supposed to work in drools 5.<br><br>when i have a rule such as:<br><br>rule 
  &quot;fact = 1&quot;<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  $f : UserFact(fact1 == 1);<br>&nbsp;&nbsp;&nbsp; then 
  <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insertLogical(new 
  CreatedFact($f.getFact2())); &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
  <br>end<br><br>now i change $f in such a way, that the rule will fire 
  again.<br>via <br><br>// build first version<br>UserFact f = new 
  UserFact();<br>f.setFact1(1);<br>f.setFact2(1);<br><br>memory.insert(f);<br>memory.fireAllRules(); 
  // &lt;- Rule fires once<br><br>// now i change the memory and fire the rules 
  again<br><br>memory.modifyRetract(f) ;<br>f.setFact2(100); // &lt;- changing 
  $f, but leaving fact1 as it 
  is.<br>memory.modifyInsert(f);<br><br>memory.fireAllRules();&nbsp; // &lt;- 
  Rule fires again<br><br>now the rule should fire again, which it does.<br>but 
  i end up with two CreatedFact instances in the workingMemory..<br>one with the 
  old OtherFact value 1, and one with the new value, 100<br><br>but i want only 
  the second instance. the one created first is not valid any more.<br>i could 
  write an extra rule for retracting the first CreatedFact-fact, but then i 
  would have<br>a very tight coupling of the two rules.<br>&nbsp;<br>is there a 
  better way?<br>it seems odd to me, that a consequence of a rule stays in 
  memory, when there is<br>a more current version of the rule evocation with the 
  _same_ facts in the precondition<br>and a different consequence.<br><br>thanks 
  in advance, tim<br><br></div></div></div></blockquote></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div>
</blockquote></div><br></div>