This half of the assignment is pencil-and-paper, rather than a programming problem. It provides an example of a circuit-design application in which Karnaugh maps can be used.
In order to make it easy to print out these problems, they are included on a separate webpage:
Problem 1 (Karnaugh Maps and circuits)
You should submit your solutions to Problem 1 under the door of Olin 1245 (formerly 245) by 6:00 pm on Saturday evening, April 1 (that is, given the built-in extension).
This problem entails coding queries into predicate logic using Prolog. Your file should be a program which will load and run in Prolog named restaurants.pl.
In prolog the names of constants and predicates are in lower-case. Variables are alphabetic strings beginning with an uppercase letter (or the underscore). The following predicates about local restaurants have been pre-coded in Prolog. Your program should access this code by including the following line in your restaurants.pl source:
:- ensure_loaded('/cs/cs60/as/a9/foodkb.pl').
Code the following queries in Prolog. You will likely find it helpful to define auxiliary predicates to assist you.
Important: Name the final query (the one that
returns the answers to each question in a list) ans1,
ans2, ..., ans12. If you don't do this, the testing
program will not give you credit for your solutions. See the example that appears
after these queries for the expected format -- the predicates ans1,
ans2, etc. are a good place to use setof, so that
the whole set is returned.
Each answer should be encoded as a predicate, ans1, ans2, ..., which gives the whole set of entities as a list. The following is an example of how this would be done for the first query:
/* 1. Which restaurants are in claremont? */ /* inClaremont(Restaurant) is true iff Restaurant is in claremont */ inClaremont(R) :- restaurant(R, _, claremont). /* ans1(Set) gives the set of restaurants in claremont */ ans1(Set) :- setof(R, inClaremont(R), Set).
ans1(S). ans2(S). ...return the same answers that are in the file /cs/cs60/as/a9/Test1.out. /cs/cs60/as/a9/Test1.in exists, but you're better off typing the queries in by hand to the prolog prompt. (There's no way that I know of to load a file into prolog from the unix command line.)
Predicate Logic and prolog is covered in Chapter 10 of the text.
Hand in your Karnaugh Maps under the door of Olin 1245 (by 6:00 pm Sat., April 1). Submit the prolog file restaurants.pl in the usual way, i.e., by running
% cs60submit restaurants.pl
You will be asked to input the assignment number (9).
The following is a summary of the restaurants knowledge base:
There are four predicates that hold all of the information in the database:
The following summarizes the entries in the database:
serves predicate:
american restaurants serve salad, steak, sandwiches, burgers, and fried chicken. burger_place restaurants serve burgers, fries, and salad. cajun restaurants serve rice, beans, gumbo, and sausage. chinese restaurants serve eggrolls, rice, shrimp, soup, and noodles. indian restaurants serve papadam, bagan_bharta, rice, tandoori, and naan. italian restaurants serve salad, pasta, cioppino, snapper, and bread. japanese restaurants serve sashimi, rice, tempura, and noodles. mediterranean restaurants serve gyros, humus, pita, and falafel. mexican restaurants serve tacos, beans, rice, enchiladas, and snapper. pizza_place restaurants serve pizza, salad, garlic_bread seafood_place restaurants serve salad, shrimp, snapper, bouillabaisse, and clams. thai restaurants serve eggrolls, rice, noodles, and pad_thai.
Note: There are two ways in which you can define a predicate such as serves: One on hand, you can enumerate each relationship:
serves(american, salad).
serves(american, steak).
serves(american, sandwiches).
etc.
A more concise way is to use lists in an auxiliary predicate, in conjunction with the built-in member predicate that enumerates the relationships.
servesAll(american, [salad, steak, sandwiches, burgers, fried_chicken]). serves(Kind, Dish) :- servesAll(Kind, Dishes), member(Dish, Dishes).
This is the technique used in foodkb.pl.
(end of note)
dish predicate:
vegetarian dishes: beans, bagan_bharta, enchiladas, falafel, humus, pizza, salad, soup, tempura, and all starch dishes meat dishes: burgers, enchiladas, gyros, pad_thai, pizza, steak, sandwiches, fried_chicken, tacos, tandoori seafood dishes: eggrolls, snapper, cioppino, sashimi, shrimp, bouillabaisse, tempura starch dishes: naan, papadam, bread, rice, noodles, pita, garlic_bread, pasta, fries
cuisine and location predicates:
arrufos is an italian restaurant in claremont. bamboo_yuan is a chinese restaurant in claremont. bombay is an indian restaurant in ontario. chilis is an american restaurant in laverne. don_salsa is a mexican restaurant in claremont. el_gato is a mexican restaurant in upland. full_house is a chinese restaurant in upland. islands is a burger place in montclair. kishi is a japanese restaurant in upland. nirvana is an indian restaurant in montclair. nogi is a japanese restaurant in claremont. orchid_garden is a thai restaurant in laverne. pizza_n_such is a pizza_place restaurant in claremont. rosas is an italian restaurant in ontario. sacas is a mediterranean restaurant in claremont. sanamluang_cafe is a thai restaurant in pomona. shrimp_house is a seafood_place restaurant in claremont. tutti_mangia is an italian restaurant in claremont. warehouse is a pizza_place restaurant in laverne. yiannis is a mediterranean restaurant in claremont.
county predicate:
claremont is in los_angeles_county. laverne is in los_angeles_county. montclair is in san_bernardino_county. ontario is in san_bernardino_county. pomona is in los_angeles_county. upland is in san_bernardino_county.