Homework? Lectures... + Could also split up topics some so rotate between some of the students being responsible for some part each day, count that towards your presentation grade...?? NP problems and NP-completeness + Note that sudoku in general form is NP-complete (reduce from latin squares). + So solving it exactly in general is probably exponential time. + But may be able to solve most boards. + May be able to approximately solve (though for sudoku this is not what we want). + Other NP-complete problems: SAT, TSP, bin packing, subset sum, clique, ... + Another name for NP problems is "search problems" - easy to check whether we have reached a goal. So can use these search algorithms for any NP problem. + Will see more about these types of problems in part on CSPs - Thursday. A* search + g(n) - cost to node n already + h(n) - estimated cost to solution starting from n + f(n) - estimated cost from start to goal through n + admissibility (never overestimate h - h(n) <= true cost) + consistency (triangle inequality for h) + consistency implies admissibility + optimal for tree search if h is admissible + optimal for graph search if h is consistent * assume state n with successor n', use definition of f and definition of consistent to show that f(n') >= f(n) (that is, estimated costs are non-decreasing on any path) * next, when choose node for expansion, have found optimal path to that node. + if not, some other node on path to current node, and by first thing we showed, f on that node would be lower - and would have been chosen first (by definition of A*) * so A* considers nodes in non-decreasing order by their f cost, and for goal node, f cost is the real cost, so first goal will be optimal (if not,...) A* search, thoughts + still doing a version of BFS, so space is the main problem just like BFS + can try using with slightly non-admissible heuristic - might get a solution faster, just a slightly non-optimal one. + one solution - use iterative-deepening A*, do iterated-deepening DFS with cutoff being f-cost. * but what if f cost goes up just slightly from one node to another, could end up taking a long-long time. * so choose how you do the cutoff carefully, may be good depending on the problem. Heuristic functions + for 8-puzzle, could use: * number of tiles that are wrong * manhattan distance (better) * total cost for a sub-problem (e.g., solve a 2x2 region and whatever that cost is can be used as a heuristic - and do not need to even solve it if you keep the solutions of all 2x2 states in a lookup table) * take the maximum of a collection of heuristics + TSP * minumum spanning tree for heuristic + SAT * count number of variables have to set to get True, could use as heuristic the number of free variables remaining in the formula. + Shortest path on roads * shortest point-to-point distance (as the bird flies) Local search * pick a state at random (or some other way), and keep going to states that are "better". + e.g., 8 queens, 8-puzzle, optimization problems. + that is called hill climbing. + problem: may end up in local optimal (but globally bad) * deal with that by: try many times (random restart hill climbing), other ways... * simulated annealing + another way to deal with local optimums - with some probability, go to states that are worse than current state + keeping track of k many states rather than one - called local beam search. * genetic algorithms - another approach, mimics evoluation/natural selection. * main advantage of these over previous search algorithms - very small memory space, can be applied naturally to optimization problems. * when local search is good - when optimal (or near-optimal) solutions are common. E.g., 8 queens. Probably not good for sudoku (since there is only one way to complete the puzzle on puzzles that are normally used). + another view - sometimes A* or one of the other complete searches is overkill, the problem might be much easier to solve than that. What is the best algorithm to use - A*, UCS, local search, or others? * Depends on the problem... * Can try them all - run them in parallel. Once you have a feel for which is best, use that one.