# AI

```Module Bank-1-SEC-B
1. Consider a water jug problem. You are given 3 jugs: a 10-gallon 5-gallon and a 6-gallon
jugs. Neither has any measuring mark in it. There is a pump that can be used to fill the jugs
with water. How can you get exactly 8-gallon of water into a 10-gallon jug? State the
production rules for the water jug problem.
Formulate this problem as state space search problem and answer the following questions
a. How do you represent a state?
b. What is your representation of the start state?
c. Give your representation of the set of goal states.
d. Draw the state space graph of this problem
e. Show any one solution to the problem by specifying the sequence of operations.
2. Consider the problem of finding the shortest path between two points on a plane that has
convex polygonal obstacles as shown in. This is an idealization of the problem that a
robot has to solve to navigate in a crowded environment.
a. Suppose the state space consists of all positions (x,y)(x,y) in the plane. How many
states are there? How many paths are there to the goal?
b. Explain briefly why the shortest path from one polygon vertex to any other in the
scene must consist of straight-line segments joining some of the vertices of the
polygons. Define a good state space now. How large is this state space?
c. Define the necessary functions to implement the search problem, including a
function that takes a vertex as input and returns a set of vectors, each of which maps
the current vertex to one of the vertices that can be reached in a straight line. (Do
not forget the neighbors on the same polygon.) Use the straight- line distance for the
heuristic function.
d. Apply one or more of the algorithms in this chapter to solve a range of problems in
the domain, and comment on their performance.
3. Consider the Z-to-A example below (a reversed mangle of the class example). Trace the
sequence of transformations for the &quot;expanding all ways from a chosen state&quot; approach, to
get from Z to A, for a
a. Consecutively bounded DFS to find any solution, depth increment 1.
b. BFS, using the indicated estimated costs to the goal.
4. Consider the problem of finding the optimal route between two cities on a map, represented
as a graph. The objective is to minimize the distance traveled.
a. Explain the hill climbing algorithm's application to this problem, considering
each city as a state and the edges between cities as possible moves.
b. Describe the evaluation function that assigns a value (distance) to each state
(city).
c. Perform a step-by-step illustration of the hill climbing algorithm on a small
example, starting from an initial city and selecting the neighbor with the lowest
distance at each step.
d. Identify the challenges faced by the hill climbing algorithm in finding the
optimal route and potential issues related to local optima.
e. Discuss how the hill climbing algorithm could be enhanced by incorporating
random restarts or simulated annealing to overcome local optima and improve
the quality of the solution.
5. The following question pertains to adversarial search. Consider the game tree in Figure
in which static scores are all from the first players point of view. (Triangle is
maximizer. Upside-down triangle is minimizer.)
MAX
MIN
3 12
82
4
6 2
5
14
Figure: A Min- max Game Tree
6. The missionaries and cannibals problem is usually stated as follows. Three missionaries
and three cannibals are on one side of a river, along with a boat that can hold one or two
people. Find a way to get everyone to the other side without ever leaving a group of
missionaries in one place outnumbered by the cannibals in that place. This problem is
famous in AI because it was the subject of the first paper that approached problem
formulation from an analytical viewpoint (Amarel, 1968).
A. Formulate the problem precisely, making only those distinctions necessary to
ensure a valid solution. Draw a diagram of the complete state space.
B. Implement and solve the problem optimally using an appropriate search algorithm.
Is it a good idea to check for repeated states?
C. Why do you think people have a hard time solving this puzzle, given that the state
space is so simple?
7. You are tasked with creating a restaurant ordering agent that can assist customers in placing
their orders based on their preferences. The agent will use various search algorit hms to
navigate through the menu and find suitable recommendations for the customers.
To simplify the problem, assume that the restaurant has a fixed menu and specific rules for
recommending dishes to customers. The agent will gather information from customers,
search through the menu using different searching algorithms, and provide appropriate
suggestions for their orders.
Your task is to implement a searching algorithm in Python that can assist the agent in
finding suitable recommendations based on predefined rules and customer preferences.
Here are the details of the scenario:
1. Menu: The restaurant has a fixed menu of dishes, each identified by a unique name and
possibly accompanied by additional information such as ingredients or dietary restrictio ns.
2. Customer Preferences: Customers will provide their preferences, such as dietary
restrictions (e.g., vegetarian, gluten- free), preferred cuisine types, and any specific
ingredients they dislike.
3. Rules and Recommendations: Define a set of rules that map customer preferences to
appropriate recommendations. Each rule consists of a condition (e.g., vegetarian and Italian
cuisine) and a corresponding recommendation (e.g., &quot;We recommend the Margherita pizza
or the Vegetable pasta&quot;).
To complete this task, you will need to implement the following components:
1. Menu Representation: Define the restaurant's menu as a data structure in Python, such
as a list or a dictionary, where each item represents a dish with its relevant details.
2. Searching Algorithm: Implement a searching algorithm, such as linear search, binary
search, or even a more complex algorithm like A* search, to search through the menu and
find suitable recommendations based on customer preferences.
3. Recommendation Generation: Based on the search results, generate appropriate
recommendations for the customer by applying the predefined rules and matching them with
the customer's preferences.
Once you have implemented the searching algorithm in Python, you can test it by
simulating customer interactions, providing their preferences, and evaluating the agent's
ability to find suitable recommendations based on the predefined rules and the menu.
8. Imagine you are planning a road trip across the United States, starting from New York City and ending in
San Francisco. You want to find the optimal route to reach your destination, considering the shortest
distance traveled. To find the optimal route, you decide to use a state space search algorithm. The state
space search involves exploring different states (cities) and the possible transitions (roads) between them.
1. Start State: New York City
2. Goal State: San Francisco
State Space:
- New York City
- Boston
- Washington D.C.
- Pittsburgh
- Chicago
- Denver
- Las Vegas
- Los Angeles
- San Francisco
1. New York City to Boston: 225 miles
2. New York City to Philadelphia: 95 miles
3. New York City to Washington D.C.: 225 miles
4. Boston to Pittsburgh: 520 miles
5. Boston to Chicago: 1,000 miles
6. Philadelphia to Pittsburgh: 305 miles
7. Philadelphia to Washington D.C.: 140 miles
8. Pittsburgh to Chicago: 470 miles
9. Pittsburgh to Denver: 1,460 miles
10. Chicago to Denver: 1,020 miles
11. Chicago to Las Vegas: 1,730 miles
12. Denver to Las Vegas: 750 miles
13. Denver to Los Angeles: 1,020 miles
14. Las Vegas to Los Angeles: 270 miles
15. Los Angeles to San Francisco: 380 miles
Using a state space search algorithm, such as breadth-first search or A*, you can explore the different
cities and the distances between them to find the optimal route from New York City to San Francisco.
The algorithm will expand nodes (cities) based on the available transitions (roads) and the distance
from the start state to the current state.
Note: The distances mentioned here are for illustrative purposes only and do not represent actual
distances between cities.
Draw a State space diagram for each move.
9. Consider the game tree below, which contains maximizer nodes and chance nodes.
A. Assume that for the chance nodes the probability of each outcome is equally likely. Is
pruning possible if the nodes are evaluated in left-to-right order? If NO, provide a brief
justification. if YES, cross out the branches that can be pruned.
B. What is the propagated value at the root node under the condition as in (A)?
C. What is the minimum value of the root node assuming a fully rational opponent but
considering the worst-case outcome at the chance nodes?
10. Consider the following game: there are three piles of sticks, with 1,1 and 2 sticks in each pile,
respectively. There are THREE players A, B, C who play in turn in that order. Each player can
take one or more sticks from one and only one pile. The player who takes last stick wins one
treat from each of the other two players (i.e., two treats total).
i. How would you represent the game value of the leaf nodes in the game tree
now that there are three players?
ii. Draw the complete game tree (hint: the piles (1,2,1) are equivalent to
(1,1,2). You may want to always sort the numbers from small to large).
iii. What should A’s initial move be?
```