Visual Prolog

29.11.2013
1
0
#1
В экспертной системе Finansovyy Sovetnik, создать цель, при реализации которой будут собраны данные о финансовых возможностях двух семьей и, попутно, будет решен вопрос у какой из них накопленния достаточны а у какой нет. Вводимые данные, в закоментированном виде, разместите в разделе goal, при проверке они будут использованы для ввода.


domains
s=string
i=integer
r=real

facts
semya(s,i)
nakopleno(s,r)
dohody(s,r)
pitanie_raskh_chel_den(s,r)
odezhda_raskh_chel_god(s,r)
obuv_raskh_chel_god(s,r)
transport_raskh_chel_den(s,r)
medicina_raskh_chel_god(s,r)
otpusk_raskh_chel_god(s,r)
drugie_raskh_chel_mesyac(s,r)

predicates
sovet(s,s)
ocenka_nakopleniy(s,s)
ocenka_dohodov(s,s)
raskh_chel_mesyac(s,r)
run
dialog(s,s)
p

clauses

run:-

p,
write("Esly zhelaete ppsovetovatsya, nazhmite klavishu <y>, esli net - <Enter>"),nl,
p,readln(Z),
dialog(Z,Klient),
sovet(Klient,Sovet),
nl,p,write("Sovet: ",Sovet,"."),nl,p,write("Do svidaniya"),nl.

dialog(Z,_):-
Z<>"y",write("Do svidaniya"),!,fail.

dialog(_,K):-
nl,p,write("Vvedite Imya"),nl,
readln(K),

nl,p,write("Vvedite chislo chenov v semye"),nl,
readint(I),
assertz(semya(K,I)), %semya(K,I)

%dobavlenie novyh factov
nl,p,write("Vvedite nakoplennuyu summu"),nl,
readreal(Zh),
assertz(nakopleno(K,Zh)),

nl,p,write("Vvedite summu dohodov"),nl,
readreal(AP),
assertz(dohody(K,AP)),

nl,p,write("Vvedite summu raskhodov na pitanie, na 1 cheloveka v den"),nl,
readreal(TK),
assertz(pitanie_raskh_chel_den(K,TK)),

nl,p,write("Vvedite summu raskhodov na odezhdu, na 1 cheloveka v god"),nl,
readreal(KiiZh),
assertz(odezhda_raskh_chel_god(K,KiiZh)),

nl,p,write("Vvedite summu raskhodov na obuv, na 1 cheloveka v god"),nl,
readreal(AyqZh),
assertz(obuv_raskh_chel_god(K,AyqZh)),

nl,p,write("Vvedite summu raskhodov na transport, na 1 cheloveka v den"),nl,
readreal(TrKu),
assertz(transport_raskh_chel_den(K,TrKu)),

nl,p,write("Vvedite summu raskhodov na medicinu, na 1 cheloveka v god"),nl,
readreal(MeZh),
assertz(medicina_raskh_chel_god(K,MeZh)),

nl,p,write("Vvedite summu raskhodov v otpuske, na 1 cheloveka v god"),nl,
readreal(DeZh),
assertz(otpusk_raskh_chel_god(K,DeZh)),

nl,p,write("Vvedite summu drugih raskhodov , na 1 cheloveka v mesyac"),nl,
readreal(TurmAy),
assertz(drugie_raskh_chel_mesyac(K,TurmAy)).


p:-write("**********************************************************************"),nl.


%sovet(Klient,Sovet)
%Ecli nakoplennogo nedostatochno, to nuzhno kopit

sovet(K,"kopit"):-
ocenka_nakopleniy(K,"nedostatochno").

sovet(K,"ispolsovat v biznese"):-
ocenka_nakopleniy(K,"dostatochno"),
ocenka_dohodov(K,"dostatochno").

sovet(K,"dopolnitelnyy sovet"):-
ocenka_nakopleniy(K,"dostatochno"),
ocenka_dohodov(K,"nedostatochno").

%ocenka_nakopleniy(Klient,Ocenka)
ocenka_nakopleniy(K,"dostatochno"):-
raskh_chel_mesyac(K,A),
semya(K,I),
A6I=A*6*I,
nakopleno(K,Zh),
Zh>=A6I.

ocenka_nakopleniy(K,"nedostatochno"):-
raskh_chel_mesyac(K,A),
semya(K,I),
A6I=A*6*I,
nakopleno(K,Zh),
Zh<A6I.

%ocenka_dohodov(Klient,Ocenka)
ocenka_dohodov(K,"dostatochno"):-
raskh_chel_mesyac(K,A),
semya(K,I),
AI=A*I,
dohody(K,P),
R=P-AI,
T=1500000/12,
R>=T.

ocenka_dohodov(K,"nedostatochno"):-
raskh_chel_mesyac(K,A),
semya(K,I),
AI=A*I,
dohody(K,P),
R=P-AI,
T=1500000/12,
R<T.

%raskh_chel_mesyac(Klient,raskhod)
raskh_chel_mesyac(K,A):-
pitanie_raskh_chel_den(K,TaKu),TaA=TaKu*30,
odezhda_raskh_chel_god(K,KiiZh),KiiA=KiiZh/12,
obuv_raskh_chel_god(K,AyqZh),AyqA=AyqZh/12,
transport_raskh_chel_den(K,TrKu),TrA=TrKu*30,
medicina_raskh_chel_god(K,MedZh),MedA=MedZh/12,
otpusk_raskh_chel_god(K,DemZh),DemA=DemZh/12,
drugie_raskh_chel_mesyac(K,TutmA),
A=TaA+KiiA+AyqA+TrA+MedA+DemA+TutmA.

semya("X",3).
semya("Y",3).
semya("Z",3).

nakopleno("X",4000000).
nakopleno("Y",4000000).
nakopleno("Z",1500000).

dohody("X",450000).
dohody("Y",400000).
dohody("Z",200000).

pitanie_raskh_chel_den("X",1500).
pitanie_raskh_chel_den("Y",1500).
pitanie_raskh_chel_den("Z",1500).

odezhda_raskh_chel_god("X",70000).
odezhda_raskh_chel_god("Y",70000).
odezhda_raskh_chel_god("Z",70000).

obuv_raskh_chel_god("X",40000).
obuv_raskh_chel_god("Y",40000).
obuv_raskh_chel_god("Z",40000).

transport_raskh_chel_den("X",240).
transport_raskh_chel_den("Y",240).
transport_raskh_chel_den("Z",240).

medicina_raskh_chel_god("X",50000).
medicina_raskh_chel_god("Y",50000).
medicina_raskh_chel_god("Z",50000).

otpusk_raskh_chel_god("X",100000).
otpusk_raskh_chel_god("Y",100000).
otpusk_raskh_chel_god("Z",100000).

drugie_raskh_chel_mesyac("X",20000).
drugie_raskh_chel_mesyac("Y",20000).
drugie_raskh_chel_mesyac("Z",20000).

%Sovety:
%"X" - ispolsovat v biznese
%"Y" - dopolnitelnyy sovet
%"Z" - kopit

goal
Что необходимо написать в Goal?