Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Operator definitions
- :- op(800, fx, if).
- :- op(700, yfx, then).
- :- op(200, yfx, and).
- :- dynamic forecastDB/2.
- % Rule 1
- if today(rain) then tomorrow(rain) : 0.5.
- if today(dry) then tomorrow(dry) : 0.5.
- if today(rain) and rainfall(low) then tomorrow(dry) : 0.6.
- if today(rain) and rainfall(low) and temperature(cold) then tomorrow(dry) : 0.7.
- if today(dry) and temperature(warm) then tomorrow(rain) : 0.65.
- if today(dry) and temperature(warm) and sky(overcast) then tomorrow(rain) : 0.55.
- %fact(today(rain), 1.0).
- %fact(rainfall(low), 0.8).
- %fact(temperature(cold), 0.9).
- %fact(sky(overcast), 0.8).
- is_true(Prämise, CF) :- fact(Prämise, CF).
- min(Number1, Number2, Smaler) :-
- Number1 < Number2,
- Smaler is Number1.
- min(Number1, Number2, Smaler) :-
- Number1 > Number2,
- Smaler is Number2.
- min(Number1, Number2, Smaler) :-
- Number1 = Number2,
- Smaler is Number1.
- composed_fact(Prämise, CF) :-
- is_true(Prämise, CF).
- composed_fact(Prämise1 and Prämise2, CF) :-
- composed_fact(Prämise1, CFe1),
- composed_fact(Prämise2, CFe2),
- %is_true(Prämise1, CFe1),
- %is_true(Prämise2, CFe2).
- min(CFe1, CFe2, CF).
- calculateTotalCF(CF1, CF2, CFt) :-
- CFt is CF1 + CF2*(1 - CF1).
- new_forecast :-
- if X then Forecast : CFr,
- composed_fact(X, CFe),
- CF is CFe * CFr,
- lookup_forecast(Forecast, CF, N),
- assert(forecastDB(Forecast, N)).
- lookup_forecast(Forecast, N, NewN) :-
- forecastDB(Forecast, OtherN),
- calculateTotalCF(N, OtherN, NewN),
- retract(forecastDB(Forecast, OtherN)).
- lookup_forecast(Forecast, N, NewN) :-
- not(forecastDB(Forecast, _)),
- NewN is N.
- % Main clause to process all rules and all cf-values
- process:-
- writeln('... processing rules ...'),
- retractall(forecastDB(_, _)),
- %new_forecast(X,Y),
- new_forecast,
- fail;true,
- print_DB.
- print_DB :-
- forecastDB(X, Y),
- write(X),write('\t: '),
- format('~4f',Y),
- writeln(''),fail;true.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement