Lab 7 and 8
Lab 7 and 8
# Driver Code
print("Following is the Breadth-First Search")
bfs(visited, graph, '0') # function calling
initial_state = (0, 0)
queue.append((initial_state, []))
visited.add(initial_state)
while queue:
current_state, path = queue.popleft()
x, y = current_state
if x == target or y == target:
print("Path to reach the target:")
for state in path:
print(state)
return True
# Fill jug 1
if (a, y) not in visited:
new_state = (a, y)
new_path = path + [new_state]
queue.append((new_state, new_path))
visited.add(new_state)
# Fill jug 2
if (x, b) not in visited:
new_state = (x, b)
new_path = path + [new_state]
queue.append((new_state, new_path))
visited.add(new_state)
# Empty jug 2
if (x, 0) not in visited:
new_state = (x, 0)
new_path = path + [new_state]
queue.append((new_state, new_path))
visited.add(new_state)
return False
if __name__ == "__main__":
a=3
b=5
target = 4