Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# index constants for nodes in visited: CURRENT = 0 PREVIOUS = 1 #======================================== def index_in_visited(visited, amounts): i = 0 while i roblem 5 (20

image text in transcribed

# index constants for nodes in visited:

CURRENT = 0 PREVIOUS = 1 #======================================== def index_in_visited(visited, amounts): i = 0 while i   roblem 5 (20 pts) Complete the function bfs_jugs(caps, show) to solve the Jug Problem: The list caps is of the form [capacity of Jug A, capacity of Jug B, capacity of Jug C]. All capacities are integers, and the capacity of Jug A is even. Jug A starts off full with water, and the other two start off empty. At each step, you may pour water from a jug i into a jug j until either jug i is empty jug j is full-those are the only stopping conditions. The goal is to end with half the water in Jug A and half in Jug B. Use breadth-first search to find the minimum number of steps needed to achieve this goal. You will need frontier and visited lists. Nodes in the frontier will be lists of the form [a,b,c] where a,b, and c are the amounts in Jug A, Jug B, and Jug C, respectively. Nodes in the visited list will be of the form shown below, where the first list shows the amounts in the jugs for the current state, and the second list shows the amounts in the jug for the previous state: [[acurr,bcurr,ccurr],[aprev,bprev,cprev]] This is so you can find the path once you reach the goal state. The parameter show is a boolean. If it is true, display the frontier and visited lists, as well as the node that is popped off of the frontier. (See output file). If it is not possible to reach the goal state, the function returns the empty list. Otherwise, the function returns a list whose first element is a list containing the steps on the optimal path from the start state to the goal state, and the second is the list visited

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain two types of the supply chain and list their properties.

Answered: 1 week ago