Question: Python implementation for (b) is provided below. 2. A mopping robot maps the rooms of the house using a graph model, where the rooms are
Python implementation for (b) is provided below.


2. A mopping robot maps the rooms of the house using a graph model, where the rooms are nodes and edges indicate that the rooms are connected. The robot will mop one room at a time, leaving the floor clean but slightly wet. For this reason, the robot must not revisit a room that has already been mopped. The algorithm must ensure that the robot mops the rooms in an order such that each one of the rooms is mopped on the way back to the base station. Any such order will be called a valid order. (a) Which one of the two graph search algorithms could be adapted to solve this problem? (b) Take the Python implementation of the algorithm chosen in (a) from the lecture slides. Modify it by adding a call to a function mop (node) so that the robot mops all the rooms in a valid order. Note that the function must be called on the way back (c) Output a valid order for mopping the rooms in the following graph. Whenever we have the choice between two or more nodes, we will choose nodes in alpha- betical order. edef BreadthFisrtSearch(G, u): Q = Queue () visited = [] Q.enqueue (u) visited.add(u) while not Q.empty(): V = Q.dequeue) for w in v.neighbors(): if w not in visited: visited.add(w) Q.enqueue (w) def DepthFirstSeachRecursive(Gu, visited): visited.add(u) for v in u.neighbors(): if v not in visited: DepthFirstSeachRecursive(G, v, visited) def DFS ( u): S = Stack() visited = [] $.push(u) visited.add(u) while not S.empty(): V = S.pop() if v not in visited: visited.add(v) for w in v.neighbors(): S.push(w) 2. A mopping robot maps the rooms of the house using a graph model, where the rooms are nodes and edges indicate that the rooms are connected. The robot will mop one room at a time, leaving the floor clean but slightly wet. For this reason, the robot must not revisit a room that has already been mopped. The algorithm must ensure that the robot mops the rooms in an order such that each one of the rooms is mopped on the way back to the base station. Any such order will be called a valid order. (a) Which one of the two graph search algorithms could be adapted to solve this problem? (b) Take the Python implementation of the algorithm chosen in (a) from the lecture slides. Modify it by adding a call to a function mop (node) so that the robot mops all the rooms in a valid order. Note that the function must be called on the way back (c) Output a valid order for mopping the rooms in the following graph. Whenever we have the choice between two or more nodes, we will choose nodes in alpha- betical order. edef BreadthFisrtSearch(G, u): Q = Queue () visited = [] Q.enqueue (u) visited.add(u) while not Q.empty(): V = Q.dequeue) for w in v.neighbors(): if w not in visited: visited.add(w) Q.enqueue (w) def DepthFirstSeachRecursive(Gu, visited): visited.add(u) for v in u.neighbors(): if v not in visited: DepthFirstSeachRecursive(G, v, visited) def DFS ( u): S = Stack() visited = [] $.push(u) visited.add(u) while not S.empty(): V = S.pop() if v not in visited: visited.add(v) for w in v.neighbors(): S.push(w)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
