KnowledgeWorks and Prolog User Guide > 6 Advanced Topics > 6.1 Control Flow > 6.1.2 User-definable Conflict Resolution

NextPrevUpTopContentsIndex

6.1.2.1 Examples

The following tactic prefers instantiations with truck objects to ones without

(deftactic prefer-trucks :static (inst1 inst2)
   (flet ((truck-p (obj) (typep obj 'truck)))
        (and (some #'truck-p (inst-token inst1))
             (notany #'truck-p (inst-token inst2)))))

Note that this tactic would be incorrect if we did not check that the second instantiation does not refer to any trucks (otherwise it would always return t if both instantiations contain trucks). It can safely be declared as static as it does not look into the slots of the objects which make up the instantiation.

This tactic implements alphabetical ordering on rule names:

(deftactic alphabetical-rulename :static (inst1 inst2)
   (string< (symbol-name (inst-rulename inst1))
            (symbol-name (inst-rulename inst2))))

This tactic prefers instantiations which bind the variable ?x to zero:

(deftactic prefer-?x=0 :dynamic (inst1 inst2)
   (flet ((fetch-?x (inst)
            (cdr (assoc '?x (inst-bindings inst)))))
         (and (eql 0 (fetch-?x inst1))
              (not (eql 0 (fetch-?x inst2))))))

Note that again we must not forget to check that ?x is not zero in the second instantiation. This tactic must be declared dynamic as ?x must have been instantiated from the slots of one of the matched objects.

The final tactic is for the example of uncertain reasoning and implements a method of preferring "more certain" instantiations:

(deftactic certainty :dynamic (inst1 inst2)
   (> (inst-c-factor inst1) (inst-c-factor inst2)))

This tactic must be dynamic if the certainty factors of objects can be modified after creation. If this is forbidden the tactic could be defined as static. Then the context defined by

(defcontext my-context :strategy (priority certainty))

will prefer instantiations of rules with higher priority or, if this does not discriminate sufficiently, instantiations which are "more certain".


KnowledgeWorks and Prolog User Guide (Unix version) - 22 Dec 2009

NextPrevUpTopContentsIndex