/* --- Copyright University of Sussex 1989. All rights reserved. ----------
 > File:            $poplocal/local/plog/lib/engine.pl
 > Purpose:         Exercise using checker.pl for fault diagnosis
 > Author:          Harry Barrow, Feb  3 1989 (see revisions)
 > Documentation:   TEACH * ENGINE
 > Related Files:   TEACH * CHECKER , SHOWLIB * CHECKER
 */



engine(N) :-
    initialise_prover,

    % axioms about inequality
    add_clause(neq_lo_mid,  [ -( lo  = mid ) ],     axiom),
    add_clause(neq_lo_hi,   [ -( lo  = hi  ) ],     axiom),
    add_clause(neq_mid_lo,  [ -( mid = lo  ) ],     axiom),
    add_clause(neq_mid_hi,  [ -( mid = hi  ) ],     axiom),
    add_clause(neq_hi_lo,   [ -( hi  = lo  ) ],     axiom),
    add_clause(neq_hi_mid,  [ -( hi  = mid ) ],     axiom),

    % axioms about engine
    add_clause(eng_revs,
        [-ok(engine),-revs(Rpm), Rpm = hi],                         rule),
    add_clause(eng_temp,
        [-ok(engine), -temperature(b,Tb), Tb = hi],                 rule),
    add_clause(pump_temp,
        [-ok(pump),-temperature(b,Tb),-temperature(c,Tc), Tb = Tc], rule),
    add_clause(pump_press,
        [-ok(pump),-pressure(c,Pc), Pc = hi],                       rule),
    add_clause(rad_temp,
        [-ok(radiator),-ok(pump),-temperature(a,Ta), Ta = lo],      rule),

    % rules about ok
    add_clause(ok(engine),  [ ok(engine) ],             assumption),
    add_clause(ok(pump),    [ ok(pump) ],               assumption),
    add_clause(ok(radiator),[ ok(radiator) ],           assumption),

% axioms about observations
    observations(N),
    print_clauses.


observations(0) :-
    % a normally working engine
    add_clause(obs_revs,    [ revs(hi) ],           observation),
    add_clause(obs_temp_a,  [ temperature(a,lo) ],  observation),
    add_clause(obs_temp_b,  [ temperature(b,hi) ],  observation),
    add_clause(obs_temp_c,  [ temperature(c,hi) ],  observation),
    add_clause(obs_press_c, [ pressure(c,hi) ],     observation),
    !.


observations(1) :-
    % a broken pump
    add_clause(obs_revs,    [ revs(hi) ],           observation),
    add_clause(obs_temp_a,  [ temperature(a,mid) ], observation),
    add_clause(obs_temp_b,  [ temperature(b,hi) ],  observation),
    add_clause(obs_temp_c,  [ temperature(c,lo) ],  observation),
    add_clause(obs_press_c, [ pressure(c,lo) ],     observation),
    !.


observations(2) :-
    % a dead engine
    add_clause(obs_revs,    [ revs(lo) ],           observation),
    add_clause(obs_temp_a,  [ temperature(a,lo) ],  observation),
    add_clause(obs_temp_b,  [ temperature(b,lo) ],  observation),
    add_clause(obs_temp_c,  [ temperature(c,lo) ],  observation),
    add_clause(obs_press_c, [ pressure(c,hi) ],     observation),
    !.



observations(3) :-
    % a useless radiator
    add_clause(obs_revs,    [ revs(hi) ],           observation),
    add_clause(obs_temp_a,  [ temperature(a,hi) ],  observation),
    add_clause(obs_temp_b,  [ temperature(b,hi) ],  observation),
    add_clause(obs_temp_c,  [ temperature(c,hi) ],  observation),
    add_clause(obs_press_c, [ pressure(c,hi) ],     observation),
    !.


observations(4) :-
    % a broken sensor
    add_clause(obs_revs,    [ revs(hi) ],           observation),
    add_clause(obs_temp_a,  [ temperature(a,lo) ],  observation),
    add_clause(obs_temp_b,  [ temperature(b,lo) ],  observation),
    add_clause(obs_temp_c,  [ temperature(c,hi) ],  observation),
    add_clause(obs_press_c, [ pressure(c,hi) ],     observation),
    !.

/* --- Revision History ---------------------------------------------------
--- Harry Barrow, Feb  3 1989
 */
