home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / PMCLIPS.ZIP / AUTO.CLP next >
Text File  |  1988-05-03  |  8KB  |  283 lines

  1.  
  2. ;;;****************************
  3. ;;;* AUTOMOTIVE EXPERT SYSTEM *
  4. ;;;****************************
  5.  
  6. ;;;**********************
  7. ;;;* ENGINE STATE RULES *
  8. ;;;**********************
  9.  
  10. (defrule normal-engine-state-conclusions ""
  11.    (working-state engine normal)
  12.    =>
  13.    (assert (spark-state engine normal))
  14.    (assert (fuel-level gas-tank sufficient))
  15.    (assert (charge-state battery charged))
  16.    (assert (rotation-state engine rotates)))
  17.  
  18. (defrule unsatisfactory-engine-state-conclusions ""
  19.    (working-state engine unsatisfactory)
  20.    =>
  21.    (assert (fuel-level gas-tank sufficient))
  22.    (assert (charge-state battery charged))
  23.    (assert (rotation-state engine rotates)))
  24.  
  25. ;;;***************
  26. ;;;* QUERY RULES *
  27. ;;;***************
  28.  
  29. (defrule determine-engine-state ""
  30.    ?rem <- (query phase)
  31.    (not (working-state engine ?))
  32.    =>
  33.    (retract ?rem)
  34.    (printout t "What is the working state of the engine:" t)
  35.    (printout t " (normal/unsatisfactory/does-not-start)? ")
  36.    (bind ?response (read))
  37.    (assert (working-state engine ?response)))
  38.  
  39. (defrule determine-rotation-state ""
  40.    ?rem <- (query phase)
  41.    (working-state engine does-not-start)
  42.    (not (rotation-state engine ?))
  43.    =>
  44.    (retract ?rem)
  45.    (printout t "Does the engine rotate (yes/no)? ")
  46.    (bind ?response (read))
  47.    (if (eq ?response yes)
  48.        then
  49.        (assert (rotation-state engine rotates))
  50.        (assert (spark-state engine irregular-spark))
  51.        else
  52.        (assert (rotation-state engine does-not-rotate))       
  53.        (assert (spark-state engine does-not-spark))))
  54.  
  55. (defrule determine-sluggishness ""
  56.    ?rem <- (query phase)
  57.    (working-state engine unsatisfactory)
  58.    (not (symptom engine sluggishness | not-sluggishness))
  59.    =>
  60.    (retract ?rem)
  61.    (printout t "Is the engine sluggish (yes/no)? ")
  62.    (bind ?response (read))
  63.    (if (eq ?response yes)
  64.        then
  65.        (assert (symptom engine sluggishness))
  66.        else
  67.        (assert (symptom engine not-sluggishness))))
  68.  
  69. (defrule determine-misfiring ""
  70.    ?rem <- (query phase)
  71.    (working-state engine unsatisfactory)
  72.    (not (symptom engine misfiring | not-misfiring))
  73.    =>
  74.    (retract ?rem)
  75.    (printout t "Does the engine misfire (yes/no)? ")
  76.    (bind ?response (read))
  77.    (if (eq ?response yes)
  78.        then
  79.        (assert (symptom engine misfiring))       
  80.        (assert (spark-state engine irregular-spark))
  81.        else
  82.        (assert (symptom engine not-misfiring))))
  83.  
  84. (defrule determine-knocking ""
  85.    ?rem <- (query phase)
  86.    (working-state engine unsatisfactory)
  87.    (not (symptom engine knocking | not-knocking))
  88.    =>
  89.    (retract ?rem)
  90.    (printout t "Does the engine knock (yes/no)? ")
  91.    (bind ?response (read))
  92.    (if (eq ?response yes)
  93.        then
  94.        (assert (symptom engine knocking))
  95.        else
  96.        (assert (symptom engine not-knocking))))
  97.  
  98. (defrule determine-low-output ""
  99.    ?rem <- (query phase)
  100.    (working-state engine unsatisfactory)
  101.    (not (symptom engine low-output | not-low-output))
  102.    =>
  103.    (retract ?rem)
  104.    (printout t "Is the output of the engine low (yes/no)? ")
  105.    (bind ?response (read))
  106.    (if (eq ?response yes)
  107.        then
  108.        (assert (symptom engine low-output))
  109.        else
  110.        (assert (symptom engine not-low-output))))
  111.  
  112. (defrule determine-gas-level ""
  113.    ?rem <- (query phase)
  114.    (working-state engine does-not-start)
  115.    (rotation-state engine rotates)
  116.    (not (fuel-level gas-tank ?))
  117.    =>
  118.    (retract ?rem)
  119.    (printout t "Does the tank have any gas in it (yes/no)? ")
  120.    (bind ?response (read))
  121.    (if (eq ?response yes)
  122.        then
  123.        (assert (fuel-level gas-tank sufficient))
  124.        else
  125.        (assert (fuel-level gas-tank empty))))
  126.  
  127. (defrule determine-battery-state ""
  128.    ?rem <- (query phase)
  129.    (rotation-state engine does-not-rotate)
  130.    (not (charge-state battery ?))
  131.    =>
  132.    (retract ?rem)
  133.    (printout t "What is the state of the battery (charged/dead)? ")
  134.    (bind ?response (read))
  135.    (assert (charge-state battery ?response)))   
  136.  
  137. (defrule determine-point-surface-state ""
  138.    ?rem <- (query phase)
  139.    (or (and (working-state engine does-not-start)      
  140.             (spark-state engine irregular-spark))
  141.        (symptom engine low-output))
  142.    (not (point-surface-state points ?))       
  143.    =>
  144.    (retract ?rem)
  145.    (printout t "What is the surface state of the points " t)
  146.    (printout t " (normal/burned/contaminated)? ")
  147.    (bind ?response (read))
  148.    (assert (point-surface-state points ?response)))
  149.  
  150. (defrule determine-conductivity-test ""
  151.    ?rem <- (query phase)
  152.    (working-state engine does-not-start)      
  153.    (spark-state engine does-not-spark)
  154.    (not (charge-state battery dead))
  155.    (not (conductivity-test ignition-coil ?))       
  156.    =>
  157.    (retract ?rem)
  158.    (printout t "What is conductivity test for the ignition coil" t)
  159.    (printout t " (positive/negative)? ")
  160.    (bind ?response (read))
  161.    (assert (conductivity-test ignition-coil ?response)))
  162.  
  163. ;;;***************************
  164. ;;;* REPAIR SUGGESTION RULES *
  165. ;;;***************************
  166.  
  167. (defrule no-repair-needed ""
  168.    (working-state engine normal)    
  169.    =>
  170.    (assert (repair "No repair needed.")))
  171.  
  172. (defrule charge-battery-repair ""
  173.    (rotation-state engine does-not-rotate) 
  174.    (charge-state battery dead)             
  175.    =>
  176.    (assert (repair "Charge the battery.")))
  177.  
  178. (defrule timing-adjustment-repair ""
  179.    (working-state engine unsatisfactory)  
  180.    (symptom engine knocking)             
  181.    =>
  182.    (assert (repair "Timing adjustment.")))
  183.  
  184. (defrule replace-ignition-coil-repair ""
  185.    (working-state engine does-not-start)      
  186.    (spark-state engine does-not-spark)       
  187.    (conductivity-test ignition-coil negative) 
  188.    =>
  189.    (assert (repair "Replace the ignition coil.")))
  190.  
  191. (defrule distributor-lead-wire-repair ""
  192.    (working-state engine does-not-start)      
  193.    (spark-state engine does-not-spark)       
  194.    (conductivity-test ignition-coil positive) 
  195.    =>
  196.    (assert (repair "Repair the distributor lead wire.")))
  197.  
  198. (defrule point-gap-adjustment-repair ""
  199.   (working-state engine unsatisfactory)   
  200.   (symptom engine misfiring)             
  201.   =>
  202.   (assert (repair "Point gap adjustment.")))
  203.  
  204. (defrule replace-points-repair ""
  205.    (working-state engine does-not-start)  
  206.    (spark-state engine irregular-spark)   
  207.    (point-surface-state points burned)
  208.    =>
  209.    (assert (repair "Replace the points.")))
  210.  
  211. (defrule clean-points-repair-1 ""
  212.    (working-state engine does-not-start)  
  213.    (spark-state engine irregular-spark)    
  214.    (point-surface-state points contaminated)
  215.    =>
  216.    (assert (repair "Clean the points.")))
  217.  
  218. (defrule clean-points-repair-2 ""
  219.    (working-state engine unsatisfactory)  
  220.    (symptom engine low-output)           
  221.    (point-surface-state points contaminated)
  222.    =>
  223.    (assert (repair "Clean the points.")))
  224.  
  225. (defrule clean-fuel-line-repair ""
  226.    (symptom engine sluggishness) 
  227.    =>
  228.    (assert (repair "Clean the fuel line.")))
  229.  
  230. (defrule add-gas-repair ""
  231.    (rotation-state engine rotates)  
  232.    (fuel-level gas-tank empty)   
  233.    =>
  234.    (assert (repair "Add gas.")))
  235.  
  236. ;;;************************
  237. ;;;* REPAIR LISTING RULES *
  238. ;;;************************
  239.  
  240. (defrule no-repairs ""
  241.   (list-repairs)
  242.   (not (repair ?))
  243.   =>
  244.   (assert (repair "Take your car to a mechanic.")))
  245.  
  246. (defrule print-repair ""
  247.   (list-repairs)
  248.   (repair ?item)
  249.   =>
  250.   (format t " %s%n" ?item))
  251.  
  252. (defrule spaces-at-end ""
  253.   (declare (salience -10))
  254.   (list-repairs)
  255.   =>
  256.   (printout t t t))
  257.  
  258. ;;;***********************
  259. ;;;* PHASE CONTROL RULES *
  260. ;;;***********************
  261.  
  262. (defrule system-banner ""
  263.   =>
  264.   (printout t t t)
  265.   (printout t "The Engine Diagnosis Expert System")
  266.   (printout t t t))
  267.  
  268. (defrule initiate-query ""
  269.   (declare (salience -10))
  270.   (not (query phase))
  271.   =>
  272.   (assert (query phase)))
  273.  
  274. (defrule initiate-repair ""
  275.   (declare (salience -10))
  276.   (query phase)
  277.   =>
  278.   (printout t t t)
  279.   (printout t "Suggested Repairs:")
  280.   (printout t t t)
  281.   (assert (list-repairs)))
  282.  
  283.