Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

thermostat settings with prolog

Status
Not open for further replies.

maha3986

Technical User
Jun 3, 2009
2
SA
Hi everybody
I write program with prolog programming language that represent the following rules :

Rule 1 : if the day is Monday or the day is Tuesday or the day isWednesday
or the day is Thursday or the day is Friday then today is a workday.
Rule 2 : if the day is Saturday or the day is Sunday then today is the
weekend.
Rule 3 : if today is workday and the time is ‘between 9 am and 5 pm’ then
operation is ‘during business hours’.
Rule 4 : if today is workday and the time is ‘before 9 am’ then operation
is ‘not during business hours’.
Rule 5 : if today is workday and the time is ‘after 5 pm’ then operation is
‘not during business hours’.
Rule 6 : if today is weekend then operation is ‘not during business hours’.
Rule 7 : if the month is January or the month is February or the month is
December then the season is summer.
Rule 8 : if the month is March or the month is April or the month is May
then the season is autumn.
Rule 9 : if the month is June or the month is July or the month is August
then the season is winter.
Rule 10 : if the month is September or the month is October or the month
is November then the season is spring.
Rule 11 : if the season is spring and operation is ‘during business hours’ then
thermostat setting is ’20 degrees’.

but I have an error (each time I get the same result '15 degrees' ) to solve this problem I add startagain rule but the problem still exists,could anyone help me please

this is the program
member(H,[H|T]).
member(X,[H|T]):-member(X,T).
testday(Y):-member(Y,[saturday,sunday]),assert(today(weekend)).
testday(Y):-member(Y,[monday,tuesday,wednesday,thursday,friday]),assert(today(workday)).
testtime(Z):-member(Z,['between 9 am and 5 pm']),today(workday),assert(operation('during business hours')).
testtime(Z):-member(Z,['after 5 pm','before 9 am']),today(workday),assert(operation('not during business hours')).
testtime(Z):-today(weekend),assert(operation('not during business hours')).
testmonth(X):-member(X,[january,febrauary,december]),assert(season(summer)).
testmonth(X):-member(X,[march,april,may]),assert(season(autumn)).
testmonth(X):-member(X,[june,july,august]),assert(season(winter)).
testmonth(X):-member(X,[septemeber,october,december]),assert(season(spring)).

thermostat_setting('15 degrees'):-
season(spring),
operation('not during business hours').

thermostat_setting('20 degrees'):-
season(spring),
operation('during business hours').

thermostat_setting('24 degrees'):-
season(summer),
operation('during business hours').
thermostat_setting('27 degrees'):-
season(summer),
operation('not during business hours').
thermostat_setting('20 degrees'):-
season(autumn),
operation('during business hours').
thermostat_setting('16 degrees'):-
season(autumn),
operation('not during business hours').
thermostat_setting('18 degrees'):-
season(winter),
operation('during business hours').
thermostat_setting('14 degrees'):-
season(winter),
operation('not during business hours').
go:-write('what month is it?'),nl,read(X),testmonth(X),nl,
write('what day is it?'),nl,read(Y),testday(Y),nl,
write('what time is it?'),nl,read(Z),testtime(Z),nl,
thermostat_setting(TH),write(TH).
startagain:-retract(today(X)),retract(operation(X)),retract(season(X)).


 
You should use the cut after member(H, [H| T]). no need to continue.
Code:
member(H,[H|_T]) :- 
  !.

member(X,[_H|T]):-
  member(X,T).

I think you should use retractall to clean the database.
Code:
startagain:-
  retractall(today(_)),
  retract(operation(_)),
  retract(season(_)).
 
Code:
testmonth(X):-
   member(X,[june,july,august]),
   assert(season(winter)).

testmonth(X):-
   my_member(X,[january,febrauary,december]),
   assert(season(summer)).

Are you sure ?

 
thank you joel76
now my program works well
but I didn't understand your question "Are you sure ?"
do you mean the months of each season !! or what?
if you mean that ,I can tell you this distribution of month according to Australia
thank you again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top