Hi everyone

I've got some strange problem with Jess engine. A simple code below illustrates it. The code iteratevily forms a sorted list. It does this quite well when the number of entities is small enough (<=10). But as it increases Jess engine failes to find matches (I've tried 7.0b2).

(clear)

(deftemplate entity (slot id))

(deftemplate value (slot id) (slot val))

(deftemplate group (multislot ids))

(defrule form-sorted-group
  (entity (id ?id))
  (value (id ?id) (val ?val))

  ?fact <- (group (ids $?ids&:(not (member$ ?id $?ids))))

  (not
    (and
      (entity (id ?id2&~?id&:(not (member$ ?id2 $?ids))))
      (value
        (id ?id2)
        (val ?val2&:(< ?val2 ?val))
      )
    )
  )
 =>
  (modify ?fact (ids (create$ $?ids ?id)))
)

(reset)

(assert (group (ids (create$))))
(for (bind ?id 0) (< ?id 10) (++ ?id) ;this one works
;(for (bind ?id 0) (< ?id 11) (++ ?id) ;this one fails
  (assert
    (entity (id ?id))
    (value (id ?id) (val ?id))
  )
)

Using sematically equivalent "forall" instead of "not CE":
 
(forall
  (entity
    (id ?id2&~?id&:(not (member$ ?id2 $?ids)))
  )
  (value
    (id ?id2)
    (val ?val2&:(>= ?val2 ?val))
  )
)

gives the same result.

Yuri Gribov

 

Reply via email to