Exercise 1: Download and execute Arm.java.
We will now look at three planning problems as motivation for our study of planning:
Exercise 2: Download and unpack planning.jar, then execute PlanningGUI. Familiarize yourself with the three planning problems, and experiment with different goal configurations: generate "easy" and "hard" configurations to reach from the initial configuration. How can you tell what's easy or hard?
About planning problems in general:
Sometimes we use state instead of configuration:
Exercise 3: Find a goal state for the arm problem. How does one specify a complete description of this state?
Exercise 4: How many possible states are there for each of the three problems?
A neighborhood:
Exercise 5: What is the size of the neighborhood for each of the three problems?
Exercise 6: Consider the starting state in the 8-puzzle demo. Draw this state on paper, draw all its neighbors and all neighbors of its neighbors.
The underlying graph:
What we know about the shortest-path problem in graphs:
Unfortunately ...
The approach taken by planning algorithms:
Before looking at planning algorithms, let's examine the output of a planning algorithm.
Exercise 7: Compile and load MazeHandPlanner into PlanningGUI for the maze problem.
First, we'll explain how BFS and DFS work
⇒
It'll become clear why they are "non-cost"
Note: BFS = Breadth-First-Search, DFS = Depth-First-Search
Key ideas:
Algorithm: BFS (start, goal) Input: the start and goal nodes (states) 1. Initialize frontier and visited 2. frontier.add (start) 3. while frontier not empty 4. currentState = frontier.removeFirst () 5. if currentState = goalState 6. path = makeSolution () 7. return path 8. endif 9. visited.add (currentState) 10. for each neighbor s of currentState 11. if s not in visited or frontier 12. frontier.add (s) 13. endif 14. endfor 15. endwhile 16. return null // No solution
Exercise 8: Compile and load BFSPlanner into PlanningGUI for the maze problem. Verify that it finds the solution by clicking on the "next" button once the plan has been generated. Likewise, apply BFS to an instance of the puzzle problem and verify the correctness of the plan generated.
Exercise 9: Implement DFS by modifying the BFS code.
Exercise 10: Compare the memory requirements of BFS and DFS. In general, which one will require more memory? Can you analyze (on paper) the memory requirements for each?
Exercise 11: Examine the use of the two data structures in BFS and DFS. Identify the operations performed on each of these. How much time is taken for each operation performed on these data structures? Are there data stuctures which take less time?
The problem with BFS/DFS:
Cost-based methods:
The Cost-Based-Planner (CBP) Algorithm:
Algorithm: CostBased (start, goal) Input: the start and goal nodes (states) 1. Initialize frontier and visited 2. frontier.add (start) 3. while frontier not empty 4. currentState = remove from frontier the state with least cost 5. if currentState = goalState 6. path = makeSolution () 7. return path 8. endif 9. visited.add (currentState) 10. for each neighbor s of currentState 11. if s not in visited and not in frontier 12. frontier.add (s) 13. else if s in frontier 14. c' = cost to s via currentState 15. if c' < current cost of s 16. current cost of s = c' 17. endif 18. endif 19. endfor 20. endwhile 21. return null // No solution
Exercise 12: Implement the CBP by adding code to the method removeBest() in CBPlanner.java that is included in planning.jar. Most of the code has been written: you only need to extract the best node from the frontier using the costFromStart value in each state (which has already been computed for you).
Exercise 13: Compare BFS with Cost-Based for the puzzle problem.
Exercise 14: Examine the operations on data structures in CBP. Estimate the time needed for these operations. Suggest alternative data structures.
An improvement:
Exercise 15: What is a reasonable estimate of the cost-to-goal for the maze and puzzle problems? That is, from given a state and the goal, what is an estimate of how many moves it would take to get from the state to the goal? Show by example how the estimate can fail in each case.
Exercise 16: In a new file called CBPlannerAStar.java, copy over your code from CBPlanner and implement the A* algorithm. Again, you do not need to perform the estimation. Simply use the estimatedCostToGoal value in each state (which has already been computed for you).
Exercise 17: Compare the time-taken (number of moves) and the quality of solution produced by each of A* and CBP for the maze and puzzle problems. Generate at least 5 instances of each problem and write down both measures (number of moves, quality) for each algorithm.
Exercise 18: Examine the code that produces the estimatedCostToGoal for the maze and puzzle problems. Can you suggest an alternative for the puzzle problem?
What these terms mean:
Completness:
Optimality:
Exercise 19: Create an example of the maze problem and show that DFS can be arbitrarily worse than optimal. What "arbitrarily worse" means: for any number x, you can find a maze problem example where DFS performs x% worse than than optimal.
Efficiency:
A challenge with discretizing:
Let's first take a naive approach and fully discretize the space:
Exercise 20: Compare BFS, CBP and A* on the arm problem. Initially, use a simple target (a short distance up the y-axis). Gradually make the target harder.
Exercise 21: Identify the part of the code that computes the neighbors of a state in ArmProblem.java. Change the 8-neighborhood to a 4-neighborhood (N,S,E,W) and compare. In the CBP code, you can un-comment the "draw" line to see what the screen looks like when the algorithm is in action.
Exercise 22: How do we know we have visited a state before? How and where is equality-testing performed in the code? What makes this equality-test different from the test used in the maze and puzzle problems?
Next, let's consider discretizing another way:
Inverse kinematics:
That is, what should θ′0 and θ′1 be?
Exercise 23: Why is this true?
Now let's look at a slighly more complex task that combines high-level discrete states with low-level small changes to angles:
where:
Exercise 24: Within each of the above phases, identify the signs (positive or negative) of Δθ0,Δθ1. For example, when straightening, what are the signs of each likely to be?
// Initially, state=0 while not over if state = 0 if (straightened) state = 1 // Go to state 1 else apply Δθ0,Δθ1 to straighten endif else if state = 1 if y = 10 state = 2 // Go to state 1 else apply Δθ0,Δθ1 to bring 2nd link down endif else if state = 2 if x = 30 stop else apply Δθ0,Δθ1 to move horizontally endif endif endwhile
Exercise 25: Download and unpack twolinkexample.zip.
In practice:
Greedy:
Exercise 26: Create an example of the maze problem in which Greedy performs badly.
Reducing memory requirements:
Other ideas in search:
About planning: