| | Prolog Exercise 4 | |
| | Author | Message |
---|
PAPoUCH Super Elite Lv2: Jr. Vet
Number of posts : 1860 Age : 37 Mood : Points : 298 Registration date : 2007-10-12
Character sheet Weapon: Crowbar Class: Thief HP: (50/50)
| Subject: Prolog Exercise 4 Tue Oct 12, 2010 7:33 pm | |
| % Author: Kevin Stewart 0700410 % Date: 10/12/2010
atom_length(Arg1, Arg2). %returns length of Arg1 into Arg2
integer(Arg). %tests if Arg is integer returns true or false
Arg1 mod Arg2 %mod returns the remainder of deviding Arg1 by Arg2
Last edited by PAPoUCH on Tue Oct 19, 2010 7:36 pm; edited 1 time in total | |
| | | PAPoUCH Super Elite Lv2: Jr. Vet
Number of posts : 1860 Age : 37 Mood : Points : 298 Registration date : 2007-10-12
Character sheet Weapon: Crowbar Class: Thief HP: (50/50)
| Subject: Exercise 4 Tue Oct 19, 2010 7:29 pm | |
| QUESTION (Problem So1ving)
Formalize the following problem by implementing the necessary Prolog facts and rules.
People shop online everyday from different retailers for various things. Amazon and Ectow are cheap retailers, Ebay is expensive. Amazon’s origin is in Baltimore, Ebay is in Vancouver and Ectow is in Beijing. Amazon ships to Toronto and Beijing as well as all the cities in the country of its origin. Ebay ships to Beijing and Kingston only and Ectow ships to Kingston and Baltimore. Ectow and Amazon sells blackberrys and n95, Ebay sells camera.
A buyer making a purchase may have a preference regarding the cost, location of retailer that (s)he does transaction with, or it may be unimportant. Meya wants to buy a cheap blackberry or a N95 from a retailer who will ship to Jamaica. Rami wants a camera but doesn’t care about the cost, as long as the retailer will ship to Jamaica. Lisa wants to buy a cheap blackberry or a N95 from a retailer that is not originated in China, as long as they will ship the goods to Jamaica or USA.
Write a knowledge-base in PROLOG which encodes the above knowledge in as general a form as possible, and a predicate, which, when executed, generates a sequence of statements of the form:
can purchase from
All possibilities should be generated.
[For those whose Geography is a bit rusty, Toronto and Vancouver are in Canada, Beijing is in China, Baltimore in USA, and Kingston is in Jamaica].
Use the following vocabulary to assist you. • person(X) means that the object denoted by x is a person. • retailer (X,Y) X has cost Y. • ships(X,Y) X can ship to Y • origin(X,Y) X originates in Y • located (X,Y) means that X is located in Y.
Assume other predicates as you see fit to generate all possibilities for Lisa, Meya and Rami, goods to purchase and the relevant retailers to use.
Solution (You may copy and paste solution into a prolog editor)
retailer(amazon,cheap). retailer(ectow,cheap). retailer(ebay,expensive). origin(amazon,baltimore). origin(ebay,vancouver). origin(ectow,beijing). ships(amazon,toronto). ships(amazon,beijing). ships(amazon,baltimore). ships(ebay,beijing). ships(ebay,kingston). ships(ectow,beijing). ships(ectow,kingston). sells(ectow,blackberry). sells(ectow,n95). sells(amazon,blackberry). sells(amazon,n95). sells(ebay,camera). located(toronto,canada). located(vancouver,canada). located(beijing,china). located(baltimore,usa). located(kingston,jamaica). person(lisa). person(meya). person(rami).
%This function returns the retailer and product if the retailer sells blackberry or n95.
sells_either(Retailer,Prod):-sells(Retailer,Prod),Prod==n95; sells(Retailer,Prod),Prod==blackberry.
meya :- person(Buyer),Buyer==meya,retailer(Retailer,cheap), sells_either(Retailer,Prod), ships(Retailer,Region),located(Region,jamaica),nl, write(Buyer),write(' can purchase '), write(Prod),write(' from '),write(Retailer).
rami :- person(Buyer),Buyer==rami,sells(Retailer,camera), ships(Retailer,Region),located(Region,jamaica),nl, write(Buyer),write(' can purchase camera from '),write(Retailer).
%This function returns the retailer if the retailer ships to a region that is located in jamaica or usa
ships_either(Retailer):-ships(Retailer,Region),located(Region,jamaica); ships(Retailer,Region),located(Region,usa).
%This function checks if a retailer is located in a region found in china (retailer located in china). % Note - not(locat_china(Retailer)) - will check for a retailer not located in china
locat_china(Retailer):-origin(Retailer,Region),located(Region,china).
lisa:-person(Buyer),Buyer==lisa,retailer(Retailer,cheap), sells_either(Retailer,Prod), not(locat_china(Retailer)), ships_either(Retailer),nl, write(Buyer),write(' can purchase '), write(Prod),write(' from '),write(Retailer).
%this function will call functions meya,rami and lisa to print results.
purchase:- meya,rami,lisa,fail.
| |
| | | PAPoUCH Super Elite Lv2: Jr. Vet
Number of posts : 1860 Age : 37 Mood : Points : 298 Registration date : 2007-10-12
Character sheet Weapon: Crowbar Class: Thief HP: (50/50)
| Subject: Re: Prolog Exercise 4 Tue Oct 19, 2010 7:33 pm | |
| % Author: Kevin Stewart % Date: 9/28/2010
cheap_retailer('Amazon'). cheap_retailer('Ectow'). expensive_retailer('Ebay').
origin('Amazon', 'Baltimore'). origin('Ebay', 'Vancouver'). origin('Ectow', 'Beijing').
ship_to('Amazon', 'Toronto'). ship_to('Amazon', 'Beijing'). ship_to('Amazon', 'Baltimore'). ship_to('Ebay', 'Beijing'). ship_to('Ebay', 'Kingston'). ship_to('Ectow', 'Kingston'). ship_to('Ectow', 'Baltimore').
sells('Amazon', 'blackberry'). sells('Amazon', 'n95'). sells('Ectow', 'blackberry'). sells('Ectow', 'n95'). sells('Ebay', 'camera').
goods('blackberry'). goods('n95'). goods('camera').
purchase(X):- X==meya, cheap_retailer(Y), sells(Y, Z), (Z==n95; Z==blackberry), ship_to(Y, 'Kingston'), nl, write(X), write(' can purchase '), write(Z), write(' from '), write(Y), fail. purchase(X):- X==rami, sells(Y, Z), Z==camera, ship_to(Y, 'Kingston'), nl, write(X), write(' can purchase '), write(Z), write(' from '), write(Y), fail. purchase(X):- X==lisa, cheap_retailer(Y), sells(Y, Z), (Z==blackberry; Z==n95), not(origin(Y,'Beijing')), (ship_to(Y, 'Kingston'); ship_to(Y, 'Baltimore')), nl, write(X), write(' can purchase '), write(Z), write(' from '), write(Y), fail. | |
| | | Sponsored content
| Subject: Re: Prolog Exercise 4 | |
| |
| | | | Prolog Exercise 4 | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Latest topics | » Echo...Sun Jan 29, 2012 6:41 pm by ahmeer » Versace For H&M Party.Sun Nov 13, 2011 11:41 pm by snowlin42 » Trend Simply click Seem with the Evening: Claudia Programs '90s Grunge StonSun Nov 13, 2011 11:39 pm by snowlin42 » Vogue Press Glimpse on the Time: Claudia Programmes '90s Grunge SteelSun Nov 13, 2011 11:38 pm by snowlin42 » Way Push Appearance within the Daytime: Claudia Avenues '90s Grunge PebblesSun Nov 13, 2011 11:25 pm by snowlin42 » Vogue shops ’should seek the advice of consumers’ with manufacturers.Sat Nov 12, 2011 3:30 am by snowlin42 » Woods: Williams apologized over racial slurMon Nov 07, 2011 11:42 pm by yidiandiana » Galaxy fights through to knock off Red BullsFri Nov 04, 2011 2:54 am by youxieshi » Avery clears waivers, set to rejoin RangersWed Nov 02, 2011 3:39 am by kuaiguonianlo » iPhone 4S battery life problems: bug in location services suspectedSun Oct 30, 2011 11:06 pm by youshiyinianla » Euro zone rescue fund will have firepower of 1 trillion eurosThu Oct 27, 2011 2:59 am by zhendeainia » Plaxico Burress' 3 TDs help Jets top ChargersMon Oct 24, 2011 5:20 am by weishinia » Leafs' Kessel gears up for biggest test of seasonThu Oct 20, 2011 11:08 am by qiheitiann » fish oil benefits dosageThu Aug 04, 2011 4:57 am by Guest » APP Elite Content SoftwareTue Aug 02, 2011 6:22 pm by Guest |
Poll | | Which Power Ranger was your favorite?? | The Red Ranger (Jason) | | 7% | [ 1 ] | The Blue Ranger (Billy) | | 0% | [ 0 ] | The Pink Ranger (Kimberly) | | 13% | [ 2 ] | The Black Ranger (Zack) | | 27% | [ 4 ] | The Yellow Ranger (Trini) | | 7% | [ 1 ] | The Green Ranger (Tommy) | | 47% | [ 7 ] |
| Total Votes : 15 |
|
Download The Jubecron Toolbar! | |
Social bookmarking |
Bookmark and share the address of Jubecron Forum on your social bookmarking website |
|
Who is online? | In total there are 3 users online :: 0 Registered, 0 Hidden and 3 Guests None Most users ever online was 479 on Fri Oct 22, 2021 3:08 am |
Statistics | We have 191 registered users The newest registered user is lathdarx
Our users have posted a total of 17260 messages in 1324 subjects
|
|