
| (define-rule :name machine-swap               | (define-rule :name object-swap                  |
|-----------------------------------------------|-------------------------------------------------|
| :if (:operators ((?n1 (machine ?x) :resource) | :if (:operators ((?n1 (is-object ?x) :resource) |
| (?n2 (machine ?x) :resource))                 | (?n2 (is-object ?x) :resource))                 |
| :links ((?nl :threat ?n2))                    | :links ((?n1 :threat ?n2))                      |
| : c on s t r a i n t s                        | : c on s t r a i n t s                          |
| (adjacent-in-critical-path ?n1 ?n2))          | (adjacent-in-critical-path ?nl ?n2))            |
| :replace (:links (?nl ?n2))                   | :replace (:links (?nl ?n2))                     |
| :with (:links (?n2 ?n1)))                     | :with (:links (?n2 ?n1)))                       |

(define-rule :name IP-by-SP
:if (:operators (?n1 (immersion-paint ?x ?c))
:constraints ((regular-shapes ?s)
(in-critical-path ?nl)))
:replace (:operators (?n1))
(define-rule :name SP-by-IP
:if (:operators (?n1 (spray-paint ?x ?c ?s))
:constraints ((in-critical-path ?nl)))
:replace (:operators (?n1))
:with (:operators (?n2 (immersion-paint ?x ?c))))

| :with (:operators (?n2 (spray-paint ?x ?c ?s))))   |                                                 |
|----------------------------------------------------|-------------------------------------------------|
| (define-rule :name PU-by-DP                        | (define-rule :name DP-by-PU                     |
| :if (:operators (?n1 (punch ?x ?w ?o))             | :if (:operators ((?n1 (drill-press ?x ?w ?o)))  |
| :constraints ((in-critical-path ?nl)))             | :constraints ((in-critical-path ?nl)))          |
| :replace (:operators (?n1))                        | :replace (:operators (?n1))                     |
| :with (:operators (?n2 (drill-press ?x ?w ?o))))   | :with (:operators (?n2 (punch ?x ?w ?o))))      |
| (define-rule :name roll-by-lathe                   | (define-rule :name lathe-by-roll                |
| :if (:operators ((?n1 (roll ?x)))                  | :if (:operators ((?n1 (lathe ?x)))              |
| :constraints ((in-critical-path ?nl)))             | :constraints ((in-critical-path ?nl)))          |
| :replace (:operators (?n1))                        | :replace (:operators (?n1))                     |
| :with (:operators (?n2 (lathe ?x))))               | :with (:operators (?n2 (roll ?x))))             |
| (define-rule :name lathe+SP-by-SP                  | (define-rule :name both-providers-diff-bolt     |
| : i f ( : operators                                | :if (:operators ((?n3 (bolt ?x ?y ?z ?o ?w1)))  |
| (?n1 (lathe ?x))                                   | :links ((?n1 (has-hole ?x ?w1 ?o) ?n3)          |
| (?n2 (spray-paint ?x ?color ?shape1)))             | (?n2 (has-hole ?y ?wl ?o) ?n3)                  |
| :constraints ((regular-shapes ?shape2)))           | (?n4 (has-hole ?x ?w2 ?o) ?n5)                  |
| :replace (:operators (?n1 ?n2))                    | (?n6 (has-hole ?y ?w2 ?o) ?n7))                 |
| :with (:operators                                  | :constraints ((:neq ?w1 ?w2)))                  |
| (?n3 (spray-paint ?x ?color ?shape2)))))           | :replace (:operators (?n1 ?n2 ?n3))             |
| :with (:operators ((?n8 (bolt ?x ?y ?z ?o ?w2)))   |                                                 |
| :links ((?n4 (has-hole ?x ?w2 ?o) ?n8)             |                                                 |
| (?n6 (has-hole ?y ?w2 ?o) ?n8))))                  |                                                 |
| (define-rule :name has-hole-r-diff-bolt-add-PU     | (define-rule :name has-hole-r-diff-bolt-add-DP  |
| :if (:operators ((?n3 (bolt ?x ?y ?z ?o ?w1)))     | :if (:operators ((?n3 (bolt ?x ?y ?z ?o ?w1)))  |
| :links ((?nl (has-hole ?x ?wl ?o) ?n3)             | :links ((?n1 (has-hole ?x ?w1 ?o) ?n3)          |
| (?n2 (has-hole ?y ?wl ?o) ?n3)                     | (?n2 (has-hole ?y ?wl ?o) ?n3)                  |
| (?n4 (has-hole ?x ?w2 ?o) ?n5))                    | (?n4 (has-hole ?x ?w2 ?o) ?n5))                 |
| :constraints ((:neq ?w1 ?w2)))                     | :constraints ((:neq ?w1 ?w2)))                  |
| :replace (:operators (?n1 ?n2 ?n3))                | :replace (:operators (?n1 ?n2 ?n3))             |
| :with (:operators ((?n8 (bolt ?x ?y ?z ?o ?w2))    | :with (:operators ((?n8 (bolt ?x ?y ?z ?o ?w2)) |
| (?n6 (punch ?y ?w2 ?o)))                           | (?n6 (drill-press ?y ?w2 ?o)))                  |
| :links ((?n4 (has-hole ?x ?w2 ?o) ?n8)             | :links ((?n4 (has-hole ?x ?w2 ?o) ?n8)          |
| (?n6 (has-hole ?y ?w2 ?o) ?n8))))                  | (?n6 (has-hole ?y ?w2 ?o) ?n8))))               |
| (define-rule :name has-hole-y-diff-bolt-add-PU     | (define-rule :name has-hole-y-diff-bolt-add-DP  |
| :if (:operators ((?n3 (bolt ?x ?y ?z ?o ?w1)))     | :if (:operators ((?n3 (bolt ?x ?y ?z ?o ?w1)))  |
| :links ((?nl (has-hole ?x ?wl ?o) ?n3)             | :links ((?n1 (has-hole ?x ?w1 ?o) ?n3)          |
| (?n2 (has-hole ?y ?wl ?o) ?n3)                     | (?n2 (has-hole ?y ?wl ?o) ?n3)                  |
| (?n6 (has-hole ?y ?w2 ?o) ?n7))                    |                                                 |
| (?n6 (has-hole ?y ?w2 ?o) ?n7))                    |                                                 |
| :constraints ((:neq ?w1 ?w2)))                     | :constraints ((:neq ?w1 ?w2)))                  |
| :replace (:operators (?n1 ?n2 ?n3))                | :replace (:operators (?n1 ?n2 ?n3))             |
| :with (:operators ((?n8 (bolt ?x ?y ?z ?o ?w2))    | :with (:operators ((?n8 (bolt ?x ?y ?z ?o ?w2)) |
| (?n4 (punch ?x ?w2 ?o)))                           | (?n4 (drill-press ?x ?w2 ?o)))                  |
| :links ((?n4 (has-hole ?x ?w2 ?o) ?n8)             | :links ((?n4 (has-hole ?x ?w2 ?o) ?n8)          |
| (?n6 (has-hole ?y ?w2 ?o) ?n8))))                  | (?n6 (has-hole ?y ?w2 ?o) ?n8))))               |

Figure 20: Rewriting Rules for Manufacturing Process Planning