Model bath tub
Description
A qualitative model of bath tub.
Source: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.
Download
Listing
% Figure 20.9 A qualitative model of bath tub.
:- op( 900, fy, not).
:- op( 220, xfy, ..).
% not Goal): negation as failure;
% Note: This is often available as a built-in predicate,
% often written as prefix operator "\+", e.g. \+ likes(mary,snakes)
not Goal :-
Goal, !, fail
;
true.
% A bath tub model
landmarks( amount, [ zero, full, inf]).
landmarks( level, [ zero, top, inf]).
landmarks( flow, [ minf, zero, inflow, inf]).
correspond( amount:zero, level:zero).
correspond( amount:full, level:top).
legalstate( [ Level, Amount, Outflow, Netflow]) :-
mplus( Amount, Level),
mplus( Level, Outflow),
Inflow = flow:inflow/std, % Constant in-flow
sum( Outflow, Netflow, Inflow), % Netflow = Inflow - Outflow
deriv( Amount, Netflow),
not overflowing( Level). % Water not over the top
overflowing( level:top..inf/_). % Over the top
initial( [ level: zero/inc,
amount: zero/inc,
flow: zero/inc,
flow: inflow/dec ] ).