/*
Title: : Tourism Adviser Expert System
Author : Ferad Zyulkyarov
Date : 23.01.2006
University : Dokuz Eylul University
Department : Computer Engineering
Course : CSE423 Logic Programming and Expert Systems
Lecturer : Prof. Dr. Tatyana Yakhno
This is a very simple Expert System implemented in prolog (Visual Prolog).
It captures the knowledge of a hotel adviser. The knowledge base consists
of the "hotel" type facts that each fact specifies a single hotel.
The expert system begins running by unifying (staring) from the first
occurrence of the "run" predicate. It asks the user for a general
question. Depending on the given answer, the execution flow (unification)
branches on the corresponding "suitable_for" rule. The backtracking
continues until all rules have been exhausted (all solutions are found),
not until finding the first matching (solution).
The solution consists of two general types of rules:
1) derivation rules that are defined by "suitable_for" predicate;
2) and utility rules:
- price;
- ask_attribute;
- clear_facts;
- location_to_distance;
- clear_facts.
The entry point of the program is the first "run" rule.
References:
(1) PDC, Visual Prolog Language Tutorial, "Building a Small
Expert System", p.439-p.444, 2001
(2) Simple tourism adviser Expert System, avalable online at:
http://www.generation5.org/content/2002/prg01.asp,
last accessed on 08.12.2005
*/
facts
/*
hotel(Name, Distance, Stars, Season, Animation, Suit, Catering, BuildingType)
Specifies a hotel.
Name - the name of the hotel
Distance - the distance to the nearest city in kilometers.
Stars - the number of stars assigned to the hotel (1-5)
Season - the seasons that the hotel is open
summer - only summer
winter - only winter
all - all seasons
Animation - whether the hotel has animation (yes/no)
Suit - whether the hotel has a suit room (yes/no)
Catering - specifies the type of catering the hotel provides
all - all inclusive
breakfast - only breakfast
self - nothing
BuildingType - is the type of the rooms the hotel has
0 - only rooms
1 - only apartments
2 - only bungalow
3 - all the above
*/
hotel(string, integer, integer, symbol, integer, integer, symbol, integer)
/*
attribute(AttributeName, AttributeValue)
A pair of attribute name and value in the memory database.
AttributeName - is the name of the attribute.
AttributeValue - is the value of the attribute.
*/
attribute(symbol, symbol)
predicates
/*
The entri point of the program.
*/
nondeterm run
/*
Clears collected facts.
*/
clear_facts - determ ()
/*
ask_attribute(AttributeName, Message, AttributeValue)
Asks the user for the value of the attribute. The question
is accompanied with the message.
Inputs:
AttributeName - the name of the attribute
Message - the message associated with the question; can be
the possible values.
Outputs:
AttributeValue - the value of the attribute entered by the user.
*/
ask_attribute(symbol, symbol, symbol) - nondeterm (i, i, o)
/*
suitable_for(Criteria, Hotel)
Checks whether the specified hotel satisifes (is suitable for)
the specified criteria.
Input:
Criteria - the criteria
Hotel - the hotel
*/
nondeterm suitable_for(symbol, symbol)
/*
location_to_distance(Location, MinLimit, MaxLimit)
Obtains the range for the distance of the hotel.
Input:
Location - is the location (city or resort)
Output:
MinLimit - the minimum distance allowed
MaxLimit - the maximum distance allowed
*/
location_to_distance(symbol, integer, integer) - nondeterm (i, o, o)
/*
price(Hotel, Price)
Checks the price of the hotel. The test is done based onthe
stars of the hotel.
Inputs:
Hotel - the hotel to be checked
Output:
Price - the price category (expensive, moderate or cheap).
*/
nondeterm price(symbol, symbol)
clauses
% declaration of the facts
hotel("Hilton", 0, 5, all, 0, 1, breakfast, 0).
hotel("Efes", 1, 4, all, 0, 1, breakfast, 0).
hotel("Titanik", 550, 5, summer, 1, 1, all, 3).
hotel("Cesme Sheraton", 110, 5, summer, 1, 0, all, 0).
hotel("Lara", 110, 3, summer, 1, 0, all, 2).
hotel("Babadan", 1, 3, all, 0, 0, self, 0).
hotel("Bornova Yurt", 8, 1, all, 0, 0, self, 0).
hotel("Uludagi", 450, 5, winter, 1, 0, all, 2).
hotel("Kars", 900, 3, winter, 0, 0, all, 3).
hotel("Abant", 600, 3, winter, 0, 0, all, 1).
hotel("Bolu", 420, 3, winter, 0, 0, breakfast, 0).
hotel("Sari Kamis", 880, 4, winter, 0, 0, all, 3).
% The entry point
run:-
ask_attribute(location, "{resort, city}", Location),
hotel(Hotel, _, _, _, _, _, _, _),
suitable_for(Location, Hotel),
write("Suitable Hotel: ", Hotel),
nl, fail.
run:-
write("\nUnable to advise a hotel.\n"),
clear_facts,
readchar(_).
/* Utility Rules */
clear_facts:-
write("Please press the space button to exit.\n"),
retractall(_, dbasedom),
readchar(_).
ask_attribute(Attr, PossibleValues, AttrValue):-
attribute(Attr, AttrValue), !;
write("Enter ", Attr, " ", PossibleValues, " : "),
readln(AttrValue),
assertz(attribute(Attr, AttrValue)).
location_to_distance(Location, MinLimit, MaxLimit):-
Location = resort, MinLimit = 50, MaxLimit = 1000;
Location = city, MinLimit = -1, MaxLimit = 10;
Location = airport, MinLimit = 10, MaxLimit = 50.
price(Hotel, Cost):-
hotel(Hotel, _, Stars, _, _, _, _, _),
Stars >3, Stars < 6, Cost = expensive;
hotel(Hotel, _, Stars, _, _, _, _, _),
Stars > 1, Stars < 4, Cost = moderate;
hotel(Hotel, _, Stars, _, _, _, _, _),
Stars = 1, Cost = cheap.
/* Derivation rules */
suitable_for(city, Hotel):-
location_to_distance(city, MinLimit, MaxLimit),
hotel(Hotel, Distance, _, _, _, _, _, _),
Distance > MinLimit,
Distance < MaxLimit,
ask_attribute(trip_type, "{business, city visitation}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for(resort, Hotel):-
location_to_distance(resort, MinLimit, MaxLimit),
hotel(Hotel, Distance, _, _, _, _, _, _),
Distance > MinLimit,
Distance < MaxLimit,
ask_attribute(season, "{summer, winter}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for(business, Hotel):-
price(Hotel, Cost),
Cost = expensive.
suitable_for("city visitation", Hotel):-
price(Hotel, Cost),
Cost = moderate;
price(Hotel, Cost),
Cost = cheap.
suitable_for(summer, Hotel):-
hotel(Hotel, _, _, summer, _, _, _, _),
ask_attribute(guest_typem, "{honey month, friends, family, alone}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for(winter, Hotel):-
hotel(Hotel, _, _, winter, _, _, _, _),
ask_attribute(guest_type, "{honey month, friends, family, alone}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for("honey month", Hotel):-
hotel(Hotel, _, 5, _, _, 1, all, _).
suitable_for(friends, Hotel):-
hotel(Hotel, _, _, _, _, _, _, RoomType),
RoomType > 0,
price(Hotel, Price),
not(Price = expensive).
suitable_for(family, Hotel):-
hotel(Hotel, _, _, _, 1, _, all, RoomType),
RoomType > 0,
Price(Hotel, Price),
not(Price = expensive).
suitable_for(alone, Hotel):-
hotel(Hotel, _, _, _, _, _, _, 0),
price(Hotel, Price),
not(Price = cheap).
goal
run.
Monday, January 23, 2006
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment