Backtracking & Brute Force Optimization Intro2CS – weeks 12-13 1.

Slides:



Advertisements
Similar presentations
Local Search Algorithms Chapter 4. Outline Hill-climbing search Simulated annealing search Local beam search Genetic algorithms Ant Colony Optimization.
Advertisements

1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
Computers playing games. One-player games Puzzle: Place 8 queens on a chess board so that no two queens attack each other (i.e. on the same row, same.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
CompSci 100e Program Design and Analysis II March 3, 2011 Prof. Rodger CompSci 100e, Spring
Eight queens puzzle. The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them are able to capture.
SIGCSE Nifty assignments: Brute force and backtracking Steve Weiss Department of Computer Science University of North Carolina at Chapel Hill
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Local search algorithms
1 Chapter 5 Advanced Search. 2 Chapter 5 Contents l Constraint satisfaction problems l Heuristic repair l The eight queens problem l Combinatorial optimization.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
Artificial Intelligence Constraint satisfaction Chapter 5, AIMA.
Ch 13 – Backtracking + Branch-and-Bound
Backtracking.
SOLVING SUDOKU WITH MATLAB VERIFICATION FUNCTION correctness verification of the puzzle: checks if the current element appears twice in the same line,
Constraint Satisfaction Problems
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Vlad Furash & Steven Wine.  Problem surfaced in 1848 by chess player Max Bezzel as 8 queens (regulation board size)  Premise is to place N queens on.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Back Tracking Project Due August 11, 1999 N-queens: –A classic puzzle for chess buffs is the N- Queens problem. Simply stated: is it possible to place.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Design and Analysis of Algorithms - Chapter 111 How to tackle those difficult problems... There are two principal approaches to tackling NP-hard problems.
1 Chapter 5 Advanced Search. 2 Chapter 5 Contents l Constraint satisfaction problems l Heuristic repair l The eight queens problem l Combinatorial optimization.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Announcements This Wednesday, Class and Labs are cancelled! The last lab is due this Wednesday … how many people are planning on doing it? Finally posted.
Data Structures Using C++ 2E1 Recursion and Backtracking: DFS Depth first search (a way to traverse a tree or graph) Backtracking can be regarded as a.
Sudoku Solver Comparison A comparative analysis of algorithms for solving Sudoku.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Sudoku Jordi Cortadella Department of Computer Science.
Searching by Constraint CMSC Artificial Intelligence January 24, 2008.
Hande ÇAKIN IES 503 TERM PROJECT CONSTRAINT SATISFACTION PROBLEMS.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
CPS Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze  Certain mazes can be solved using the “right-hand”
CompSci 100e 6.1 Plan for the week l More recursion examples l Backtracking  Exhaustive incremental search  When we a potential solution is invalid,
CompSci Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze ä Certain mazes can be solved using the.
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
The n queens problem Many solutions to a classic problem: On an n x n chess board, place n queens so no queen threatens another.
Analysis & Design of Algorithms (CSCE 321)
CSCE350 Algorithms and Data Structure Lecture 21 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
Satisfiability and SAT Solvers CS 270 Math Foundations of CS Jeremy Johnson.
Constraint Propagation Artificial Intelligence CMSC January 22, 2002.
CPS Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze ä Certain mazes can be solved using the “right-hand”
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
CompSci Problem Solving: Sudoku  Rules of the Game Sudoku is played with a 9 by 9 "board" consisting of nine 3 by 3 sub-boards. The symbols 1 -
CPS 100, Spring Search, Backtracking,Heuristics l How do you find a needle in a haystack?  How does a computer play chess?  Why would you write.
1 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 CSC384: Intro to Artificial Intelligence Backtracking Search I ● Announcements.
CSE 143 read: 12.5 Lecture 18: recursive backtracking.
Unit – 5: Backtracking For detail discussion, students are advised to refer the class discussion.
Constraints Satisfaction Edmondo Trentin, DIISM. Constraint Satisfaction Problems: Local Search In many optimization problems, the path to the goal is.
Cse 150, Fall 2012Gary Cottrell: Many slides borrowed from David Kriegman! Constraint Satisfaction Problems Introduction to Artificial Intelligence CSE.
Various Problem Solving Approaches. Problem solving by analogy Very often problems can be solved by looking at similar problems. For example, consider.
Backtracking, Search, Heuristics
BackTracking CS255.
Intro to Computer Science II
CSCI 104 Backtracking Search
Data Structures and Algorithms
Constraint Satisfaction Problem
Back Tracking.
Analysis and design of algorithm
Jordi Cortadella Department of Computer Science
Brute Force Approaches
adapted from Recursive Backtracking by Mike Scott, UT Austin
The N-queens problem Team: 404 brain not found
A General Backtracking Algorithm
Sudoku.
The N-Queens Problem Search The N-Queens Problem Most slides from Milos Hauskrecht.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Backtracking, Search, Heuristics
Presentation transcript:

Backtracking & Brute Force Optimization Intro2CS – weeks

Backtracking A general way (using recursion) to find a solution to a problem. Given a partial solution, we have several options in extending it. Try one option, and if that doesn’t work, backtrack (undo the change) and try another Often used for “constraint satisfaction problems” 2

Sudoku 3

Sudoku Solving 4

5

6 Check the column Check the row Check the quadrant

7

8

Questions Can you estimate the number of boards we need to explore? Provide a bound? How many of these will yield legal Sudoku puzzles? 9

Number of valid Sudoku boards 10

The 8 Queen Problem Find a way to place all 8 queens on a chess board so that: No two queens are on the same row No two queens are on the same column No two queens are on the same diagonal Again, how can we estimate how many board configurations there are (incl. illegal ones)? 11

12

From Wikipedia… 13 (Fundamental solutions can be rotated / reflected to obtain other solutions)

We use an 8x8 Boolean list as a board. A cell is True if a queen is placed there. 14

15

16

17

Optimization 18

19

Example 20

Knapsack 21

Another variant: each item has a weight, a size, and a value. The thief is limited both in weight and size. In python… 22

23

24

25

Idea for the algorithm Use recursion (backtracking). Given a partially filled bag, and a set of items Try with the first item (& make recursive call) – If the first item doesn’t fit, skip it. Try without the first item (& make recursive call) 26

27

28

Back to N-Queens We can phrase the N-Queen problem as an optimization problem: Find the board setting that has the fewest violated constraints. If we find the minimal number of violated constraints, and it happens to be 0, we have a legal solution. 29

Are there alternatives to brute force search? Yes! We can try guessing: start with random assignments until we find a good solution. We can try to have a solution with conflicts and try to move only conflicted pieces. Unfortunately, they are not much more efficient. 30

31

32

33