Programming Rule Based Expert Systems by QZ5R8I9

VIEWS: 16 PAGES: 3

									IS53024A: Artificial Intelligence


                 Programming Rule-Based Expert Systems
Example: An expert system for bagging shop items:
(RULE 1 (IF   (step is check-order)& (potato-chips ? ? ? ))
        (THEN (ADD (item0 Pepsi Bottle Large No))
              (SAYING ("Add a bottle of Pepsi to the order."))))

(RULE 2 (IF   (step is check-order)&(?bag is current-bag))
        (THEN (DELETE (step is check-order)& (ADD (step is bag-large-items))
              (SAYING ("Bagging large items."))))

(RULE 3 (IF   (step is bag-large-items)&(?bag is current-bag)&(?item ?c ? large ? )&(?item ? bottle ? ? )
        (THEN (DELETE (?item ? ? ? ? ))&(ADD (?bag contains ?item large))
                 (SAYING ("Put ~a, ~a, in ~a." ?item ?c ?bag ))))

(RULE 4 (IF   (step is bag-large-items)&(?bag is current-bag)&(?item ?c ? large ? ))
        (THEN (DELETE (?item ? ? ? ? ))&(ADD (?bag contains ?item large))
                 (SAYING ("Put ~a, ~a, in ~a." ?item ?c ?bag ))))

(RULE 5 (IF   (step is bag-large-items)&(?bag is current-bag))
        (THEN (DELETE (step is bag-large-items))&(ADD (step is bag-medium-items))
                 (SAYING ("Bagging medium items."))))

(RULE 6 (IF  (step is bag-medium-items)&( ?item ?name ? medium yes))
         (THEN (ADD (?item in freezer-bag))
               (SAYING ("Put ~a, ~a, in a freezer bag." ?item ?name))))

(RULE 7 (IF  (step is bag-medium-items)&(?bag is current-bag)&(?item ?c ? medium ?))
         (THEN (DELETE (?item ? ? ? ?))&(ADD (?bag contains ?item medium))
             (SAYING ("Put ~a, ~a, in ~a." ?item ?c ?bag))))

(RULE 8 (IF  (step is bag-medium-items)&(?bag is current-bag)&
             (?item ? ? medium ?)&(?new-bag is available-bag))
       (THEN (DELETE(?bag is current-bag))&(DELETE(?new-bag is available-bag))&(ADD(?new-bag is current-bag)
             (SAYING ("Start a fresh bag."))))

(RULE 9 (IF   (step is bag-medium-items)&(?bag is current-bag))
        (THEN (DELETE (step is bag-medium-items))&(ADD (step is bag-small-items))
              (SAYING ("Bagging small items."))))

(RULE 10(IF   (step is bag-small-items)&(?bag is current-bag)&(?item ?c ? small ?))
        (THEN (DELETE (?item ? ? ? ?))&(ADD (?bag contains ?item small))
              (SAYING ("Put ~a, ~a, in ~a." ?item ?c ?bag))))

(RULE 11(IF  (step is bag-small-items)&(?bag is current-bag)&
                (?item ? ? small ?)&(?new-bag is available-bag))
       (THEN (DELETE (?bag is current-bag))&(DELETE (?new-bag is available-bag))&
              (ADD (?new-bag is current-bag))
              (SAYING ("Start a fresh bag."))))
Consider the following working memory:
WM = ((step  is check-order)(bag1 is current-bag)(bag2 is available-bag)
 (bag3 is available-bag)(bag4 is available-bag)(item1 Bread Plastic-bag Medium No)
 (item2 Glop Jar Small No)(item3 Granola Cardboard-box Large No)
 (item4 Ice-cream Cardboard-carton Medium Yes)(item5 Potato-chips Plastic-bag Medium No))

Running the forward chaining algorithm produces the steps:
Fires R1: Add a bottle of Pepsi to the order.
             adds new assertion: (item0 Pepsi Bottle Large No)
Fires R2: Bagging large items. with binding ?bag=bag1,
             adds new assertion: (step is bag-large-items)
Fires R3: Put item0, Pepsi, in bag1. with bindings ?bag=bag1, ?item=item0,
             adds new assertion: (bag1 contains item0 large)
Fires R4: Put item3, Granola, in bag1. with bindings ?bag=bag1, ?item=item3,
             adds new assertion: (bag1 contains item3 large)
Fires R5: Bagging medium items.
             adds new assertion: (step is bag-medium-items)
Fires R6: Put item4, Ice-cream, in a freezer bag. with binding ?item=item4,
             adds new assertion: (?item in freezer-bag)
Fires R8: Start a fresh bag. with bindings ?bag=bag1, ?new-bag=bag2,
             adds new assertion: (bag2 is current-bag)
Fires R7: Put item1, Bread, in bag2. with bindings ?bag=bag2, ?item=item1,
             adds new assertion: (bag2 contains item1 medium)
Fires R7: Put item5, Potato-cips, in bag2. with bindings ?bag=bag2, ?item=item5,
             adds new assertion: (bag2 contains item5 medium)
Fires R9: Bagging small items. with binding ?bag=bag2,
             adds new assertion: (step is bag-small-items)
Fires R11: Start a fresh bag. with bindings ?bag=bag2, ?new-bag=bag3,
             adds new assertion: (bag3 is current-bag)
Fires R10: Put item2, Glop, in bag3. with binding ?bag=bag3, ?item=item2,
             adds new assertion: (bag3 contains item2 small)

								
To top