1
votes

I have this clips program that uses salience to get the message "Welcome to the advising system." to always appear first, but I was wondering how to do this using a control fact without the use of salience.

  1  (deffacts prerequisites
  2  (after COP1000 take COP2000)
  3  (after COP1001 take COP2001)
  4  (after MAC1000 take MAC2000)
  5  (after MAC1001 take MAC2001)
  6  (after ENG1000 and ENG1001 take ENG2000))
  7 
  8  (defrule welcome
  9  (declare (salience 10000))
 10   =>
 11   (printout t "Welcome to the advising system." crlf))
 12   
 13  (defrule rule2
 14   (after ?course1 take ?course2)
 15   (student ?name $? ?course1 $?)
 16   =>
 17   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf))
2

2 Answers

1
votes
CLIPS> 
(deffacts prerequisites
   (after COP1000 take COP2000)
   (after COP1001 take COP2001)
   (after MAC1000 take MAC2000)
   (after MAC1001 take MAC2001)
   (after ENG1000 and ENG1001 take ENG2000)
   (student Cindy COP1000 MAC1001)
   (phase welcome))
CLIPS>   
(defrule welcome
   ?f <- (phase welcome)
   =>
   (retract ?f)
   (assert (phase process))
   (printout t "Welcome to the advising system." crlf))
CLIPS>   
(defrule rule2
   (phase process)
   (after ?course1 take ?course2)
   (student ?name $? ?course1 $?)
   =>
   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf))
CLIPS> (reset)
CLIPS> (watch facts)
CLIPS> (watch activations)
CLIPS> (watch rules)
CLIPS> (run)
FIRE    1 welcome: f-7
<== f-7     (phase welcome)
==> f-8     (phase process)
==> Activation 0      rule2: f-8,f-1,f-6
==> Activation 0      rule2: f-8,f-4,f-6
Welcome to the advising system.
FIRE    2 rule2: f-8,f-4,f-6
Since Cindy has taken MAC1001 , I suggest taking MAC2001.
FIRE    3 rule2: f-8,f-1,f-6
Since Cindy has taken COP1000 , I suggest taking COP2000.
CLIPS>
1
votes

If you want multiple phases (say more than two) i would stick to the approach of Gary Riley. However if your desire is a simple prefiring rule i would suggest making the initial declaration of facts depending on a control flag.

(defrule prerequisites
  (preinit-done)
  =>
  (assert
    (after COP1000 take COP2000)
    (after COP1001 take COP2001)
    (after MAC1000 take MAC2000)
    (after MAC1001 take MAC2001)
    (after ENG1000 and ENG1001 take ENG2000))
)

(defrule welcome
  (not (preinit-done))
  =>
  (printout t "Welcome to the advising system." crlf)
  (assert (preinit-done))
)

(defrule rule2
   (after ?course1 take ?course2)
   (student ?name $? ?course1 $?)
   =>
   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf)
)

This way you dont have to add a phase fact to each rule, as far as they somehow depend on your initial facts.