CS计算机代考程序代写 prolog %%% Prolog program for the plumbing example with relations….

%%% Prolog program for the plumbing example with relations….
% Copyright Poole and Mackworth 2021. Do not distribute.

:- dynamic on/1, plugged/1, unplugged/1.

pressurized(p1).
pressurized(X) :- connected(X,Y), pressurized(Y).

% connected(X,Y) is true if X is connected to Y so water will flow to X from Y.

connected(p2,p1) :- on(t1).
connected(p3,p2).
connected(hws,p2) :- on(t4).
connected(p4,hws).
connected(p5,hws).

% flow(X) is true if there is water flowing into X
flow(X) :- flows_into(Y,X), flow(Y).

flow(shower) :- on(t2), pressurized(p2).
flow(shower) :- on(t5), pressurized(p5).
flow(cold_spout) :- on(t3), pressurized(p3).
flow(hot_spout) :- on(t5), pressurized(p4).

% flows_into(X,Y) means X flows into Y
flows_into(shower,bath).
flows_into(d2,d1).
flows_into(d3,d1).
flows_into(bath,floor) :- plugged(bath).
flows_into(bath,d2) :- unplugged(bath).
flows_into(sink,floor) :- plugged(sink).
flows_into(sink,d3) :- unplugged(sink).
flows_into(cold_spout, sink).
flows_into(hot_spout, sink).

wet(X) :- flow(X).

% Try some subset of:
on(t1).
on(t2).
%on(t3).
% t4 is the tap that connects the HWS to p2
%on(t4).
% t5 is the tap from the hot water system to the shower
%on(t5).
% t6 is the hot tap at the sink
on(t6).

% You should axiomatize what is plugged as well as what is unplugged.

% To changed whether the bath is plugged, you can change:
unplugged(bath).
plugged(sink).

% Try:
%?- flow(d1).
%?- wet(floor).
%?- try changing the bath to be plugged and see what happens.