Rule matching problem with exists and test

Help
lna
2012-01-05
2014-01-28
1 2 > >> (Page 1 of 2)
  • lna

    lna - 2012-01-05

    Hi Gary,

    As previously mentioned in the RUN-TIME crash in reteutil (GetLeftMemory) topic, I've encountered a problem with the exists CE. I've investigated a little further and here's what I come up with :
    When a test CE immediately follows an exists CE, the test is not executed. In the following example, the detect rule is put onto the agenda as it obviously shouldn't due to the test.

    (defrule TRAITEMENT::detect
      (an_augm ?an)
      (phase_traitement)
      (exists (object (is-a RENTE)
         (name ?rente)
         (mutable TRUE)))
      (test (eq 1 2))
    =>
      (printout t "********************************************" crlf))

    However, if I put the (phase_traitement) instruction between the exists and the test, everything works fine, the rule is not put onto the agenda.

    I believe there might be a problem with the reordering (due to the test being moved up when following a not instruction).
    Or is there a deliberate reason to this ?

    Thanks for any input.

    Cheers,

    Helena

     
  • Gary Riley

    Gary Riley - 2012-01-09

    It's a bug unrelated to reordering. Actually in version 6.3, reordering doesn't occur in this situation-I need to update the documentation. I'm working on a fix for this issue.

     
  • lna

    lna - 2012-01-23

    Thanks Gary… problem fixed ;)

     
  • lna

    lna - 2012-01-30

    I've updated reteutil.c and drive.c and I've unfortunately come up with another problem.
    The match on fact addresses does not seem to work anymore.
    The following rule illustrates de problem.

    (defrule presence_mandataire "vérifier l'existence et la validité du mandataire"
    ; dp2_4
    (etape (type ?te&:(eq ?te ?*ce_donnees_base*)) (status a_valider|a_reverifier) (inst ?etape))
    ?f_adr <- (adresse (nom ~""))
    (object (is-a ASSURE_INT)(adresse_mandataire ?f_adr))
    =>
    (send ?etape cree_instance_message INFO MSG00005))

    This rule does not trigger anymore. ?f_adr has the value f-3 and the object ASSURE_INT has the value <Fact-3> in its adresse_mandataire slot and this hasn't changed since modifying drive.c and reteutil.c

    Do you have any idea where this could come from ?

    Thanks,

    Helena

     
  • lna

    lna - 2012-01-30

    Forget my last comment… It seems as though I did not update my code correctly.
    Sorry…

     
  • Gary Riley

    Gary Riley - 2012-01-30

    No problem. There was a bug related with the fact/instance address use in the LHS of a rule, but it was fixed with the update to reteutil.c

     
  • vranoch

    vranoch - 2012-07-09

    Hello,
    I have a similar problem, the combination of (exist ) and (test ) does not work. I werified that I have the latest version of drive.c:

          // Bug Fix - Need to evaluate secondary network test for exists CE 0881
          if ((join->secondaryNetworkTest != NULL) && exprResult && join->patternIsExists)
            {
             EngineData(theEnv)->GlobalRHSBinds = rhsBinds;
             exprResult = EvaluateJoinExpression(theEnv,join->secondaryNetworkTest,join);
             if (EvaluationData(theEnv)->EvaluationError)
               { SetEvaluationError(theEnv,FALSE); }
            }
    

    In my program:

    (deffacts xy
    (SAD T 1 T07 "12345678")
    )
    (defrule x
        (exists (SAD T ?ix T07 ?str)
            (test (>= (str-length ?str) 0))
        ) 
        (test (=  1 1))
    =>
        (printout t "FIRED" crlf)
    )
    

    the "x" defrule does not fire as it should:

    (clear)
    (load D:/Projects/ARCD/clips/CLIPSShell/k)
    $*
    TRUE
    (reset)
    (run)
    

    Am I doing anything wrong or do I have to update any other source (I took the complete sources in may)?

    Thanks Vranoch

     
  • vranoch

    vranoch - 2012-10-12

    Hi Gary, could You please look at the last post? Thanks Vranoch

     
  • Gary Riley

    Gary Riley - 2012-10-13

    It's a bug. I haven't had the time to investigate the fix yet.

     
  • vranoch

    vranoch - 2012-10-18

    Thanks, do You have any idea about when You could fix it?
    Vranoch

     
  • Gary Riley

    Gary Riley - 2012-10-31

    I've got a fix. Just need to do a little more testing on it.

     
  • vranoch

    vranoch - 2012-11-01

    Great, thanks. Let me then know how to fix it, please .

    Vranoch

     
  • Gary Riley

    Gary Riley - 2012-11-07

    I've posted fixes to drive.c and rulebld.c

     
    • vranoch

      vranoch - 2013-02-06

      Thanks Gary, I have just implemented it in my solution and tested it and everything looks OK. Thanks again

      Vranoch

       
  • vranoch

    vranoch - 2013-12-10

    Hi Gary,

    it looks like Your last bugfix introduced another bug. At least for me (having the latest SVN checkout) on Win7, MSVS2010

    {{{
    (deffacts xy
    (SAD G 1 GX01 "XX")
    (SAD G 1 GCH 1 GCH03 "AA")
    (SAD G 2 GX01 "CN")
    (SAD G 2 GCH 1 GCH03 "AA")
    (SAD G 3 GX01 "XX")
    (SAD G 3 GCH 1 GCH03 "B00")
    (SAD G 4 GX01 "CN")
    (SAD G 4 GCH 1 GCH03 "B00")
    )

    (defrule if_exists ""
    (SAD G ?ix1 GX01 ?var1)
    (and
    (test (eq ?var1 "CN"))
    (exists (SAD G ?ix1 GCH ?ix2 GCH03 ?var2)
    (test (eq ?var2 "B00"))
    )
    )
    =>
    (printout t "Found item " ?ix1 crlf)
    )
    }}}

    It should display just:
    {{{
    Found item 4
    }}}

    but displays instead:
    {{{
    Found item 4
    Found item 2
    }}}

    (looks like the exists has no effect)

    Can You help, please?

    Thanks Vranoch

     
  • vranoch

    vranoch - 2013-12-12

    Hi Gary,

    I have another occurrence of (probably) this problem. The following rule crashes when loading. Can You please check it - I deadly need to solve it as it is in a production enterprise solution.

    Thanks Jan

    (defrule xx
    (SAD SD SD01 ?val0)
    (and
    (exists
    (SAD G ?ix G10 ?val1)
    (SAD G ?ix G10 ?val2)
    (or
    (test (eq ?val1 "IQ"))
    (test (eq ?val2 "IQ"))
    )
    )
    (test (eq ?val0 "ZAH"))
    )

    =>
    )

     
    • Gary Riley

      Gary Riley - 2013-12-14

      Checked in a fix for the crash issue: rulebld.c

       
      • vranoch

        vranoch - 2013-12-14

        Thanks a lot Gary, I will test it. I do not know the nature of this problem but did You also consider other similar constructions (e.g. nesting these constructions - (exists (exists )), etc.)? For example the following construction also does not work correctly without Your latest fix. With outermost (exists ) it does not fire at all whereas without it it fires two times. Consider also this, please.

        Thanks Vranoch

        (defrule if_exists ""
        (exists
        (SAD G ?ix1 GX01 ?var1)
        (test (eq ?var1 "CN"))
        (and
        (exists (SAD G ?ix1 GCH ?ix2 GCH03 ?var2)
        (test (eq ?var2 "B00"))
        )
        )
        )
        =>
        ; (printout t "Found item " ?ix1 crlf)
        (printout t "Found item " crlf)
        )

         
      • vranoch

        vranoch - 2013-12-15

        Hi Gary,

        I checked the fix and it looks OK. Could You also look at the other issue? I can't protect users from creating such constructions and it it currently a critical issue for them.

        Thanks Vranoch

         
        • Gary Riley

          Gary Riley - 2013-12-15

          I'm currently reviewing the logic.

           
          • vranoch

            vranoch - 2013-12-20

            Hi Gary, do You hav any estimation how long can such review take? I'm just asking because I have to provide some solution so I wonder whether I shall wait for a correct fix or temporarily return back before the first fix of this thread, because this issue was introduced newly in this thread. If so, is it sufficient to rewind just drive.c and rulebld.c?

            Thanks Vranoch

             
  • Gary Riley

    Gary Riley - 2013-12-12

    I'll take a look at it.

     
  • Gary Riley

    Gary Riley - 2013-12-21

    I need to reimplement the algorithm that handles a single pattern/pattern group paired with a test CE within a not/and or exists conditional element. That represents a special case and depending upon how you count there's around 10 to 20 different scenarios that need to be handled. I'm working a set of test cases that cover the logic paths I've identified and I've already uncovered a couple of additional cases that don't work properly.

    I can't say whether it's better for you to rewind or wait for a complete fix. If users are commonly using these types of constructions, then you could continue to have problems whether you unwind or not.

    Once this issue is fixed, it would still be prudent to advise users that this type of construction is not the most efficient way to write the rules (assuming that the rules you've posted are actual rules rather than extreme simplifications of the originals). This method for testing constants:

    (SAD ?var1)
    (test (eq ?var1 "CN"))

    Is handled quite differently than this method:

    (SAD "CN")

    In the latter case, if there are multiple constants specified for a position in a pattern, a hash table for the constants is created. If there are N constants for the position, this allows the matched constant to be determined with 1 computation. In the former case, there would be N computations regardless of whether a matched constant was found or not.

     
    • vranoch

      vranoch - 2013-12-31

      Thanks Gary,

      I know that this is quite a complex task with a lot of variants. Cross fingers to You to succeed in completing it successfully. I rewound back to a configuration in which the problem does not occur so I hope I addressed the most critical problem and will have some time to fix it properly.

      Thanks for a hint concerning constants. This situation is not exceptional - the code is generated so I may try to review the generator, however testing for a constant is not too frequent as far as I found - testing for various functions (substrings, uppercase, etc.) are more frequent, but any speedup will be usefull. Thanks again and looking forward to a final fix. Let me know if I can help You somehow.

      Thanks Vranoch

       
1 2 > >> (Page 1 of 2)

Log in to post a comment.