Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Midterm 330 Summer 2023 Prolog Portion (65 points)

1. For the following KB, what are the queries for a and b.

%model( model , num_seats ).

model(elantra,5).

model(acadia,7).

model(civic,4).

%...

%vehicle(ID,model,location).

vehicle(1253,acadia,lugoff).

vehicle(4164,wrangler,charlestonA).

vehicle(5312,civic,columbia).

%...

%state(ID,rented).

state(4164,y).

state(5312,n).

%...

%location(loc_name).

location(columbia).

location(lugoff).

location(charlestonA).

%...

a. (5) Query for a vehicle available, i.e. not rented, at Columbia location with 6 or more seats. This should show the ID and the model (by setting appropriately named variables).

b. (10) Query for a location with a Civic available (duplicates acceptable).

c. (10) Query for a location with no vehicles available.

2. Matryoshka Dolls, also known as “Russian Nesting Dolls”: Write the knowledgebase (KB) to represent the following rules. See picture to the right from Wikipedia if you don’t know what these are.

Assume the (8) dolls are defined in your file as follows:

doll(d1).

doll(d2).

%...

doll(d8).

· (10 for representation, 10 for larger rule)

· Represent the relative sizes with some sort of rule(s), one called larger, probably combined with facts that d1 is the smallest, d2 the second smallest,… d8 the largest.

· Make sure that you can compare ones that aren’t one size different, e.g. larger(d2,d6) should fail while larger(d6,d2) should succeed.

· You may not enumerate all possible pairs.

· No ellipses (“…”)

 

3. (20) Solve the map coloring problem to color the corners c1,c2,..c8 of the following wireframe cube with no two corners of adjacent colors. Use the given three colors. Your solutions must use at most two colors. Your solution rule should be of the form “solution(C1,C2,C3,C4,C5,C6,C7,C8):- […]” , where each corner is assigned a color from the color domain. You can, as always, define helper rules if you like.

 

color(red).     color(green).      color(blue).

solution(C1,C2,C3,C4,C5,C6,C7,C8):-

4. (5 points, extra credit) Define a rule that takes a list and holds (is true) if list is of successive pairs of items: e.g. [a,a,b,b,c,c] or perhaps [a,a,b,b,a,a] but not [a,a,b,b,b,a,a] or [a,a,a,b,b,c,c].