Backtracking and Branch-and-Bound

Similar documents
Backtracking. Chapter 5

UNIT 4 Branch and Bound

Branch and Bound. Live-node: A node that has not been expanded. It is similar to backtracking technique but uses BFS-like search.

Chapter-6 Backtracking

Coping with the Limitations of Algorithm Power Exact Solution Strategies Backtracking Backtracking : A Scenario

The problem: given N, find all solutions of queen sets and return either the number of solutions and/or the patterned boards.

Chapter 6 Backtracking Algorithms. Backtracking algorithms Branch-and-bound algorithms

BackTracking Introduction

Data Structures (CS 1520) Lecture 28 Name:

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

IV/IV B.Tech (Regular) DEGREE EXAMINATION. Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation

CS 440 Theory of Algorithms /

Algorithm Design And Analysis Asst. Prof. Ali Kadhum Idrees The Sum-of-Subsets Problem Department of Computer Science College of Science for Women

Data Structures (CS 1520) Lecture 28 Name:

Search means finding a path or traversal between a start node and one of a set of goal nodes. Search is a study of states and their transitions.

Algorithm Design Techniques (III)

Chapter 5 Backtracking 1

Algorithm classification

mywbut.com Informed Search Strategies-II

Search and Optimization

Backtracking. Examples: Maze problem. The bicycle lock problem: Consider a lock with N switches, each of which can be either 0 or 1.

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

Set 2: State-spaces and Uninformed Search. ICS 271 Fall 2015 Kalev Kask

Graphs & Digraphs Tuesday, November 06, 2007

CS 231: Algorithmic Problem Solving

CSE 417 Branch & Bound (pt 4) Branch & Bound

Lecture 3. Brute Force

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

DARSHAN INST. OF ENGG. & TECH.

CSC 8301 Design and Analysis of Algorithms: Exhaustive Search

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

15.083J Integer Programming and Combinatorial Optimization Fall Enumerative Methods

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Brute-Force Algorithms

Assignment No 2 (Group B)

Brute Force: Selection Sort

SEARCH ALGORITHMS NOTES FOR THE ADVANCED ALGORITHM CLASS

Methods and Models for Combinatorial Optimization Exact methods for the Traveling Salesman Problem

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

State Space Search. Many problems can be represented as a set of states and a set of rules of how one state is transformed to another.

CMSC Introduction to Algorithms Spring 2012 Lecture 16

Chapter 11: Graphs and Trees. March 23, 2008

Seach algorithms The travelling salesman problem The Towers of Hanoi Playing games. Comp24412: Symbolic AI. Lecture 4: Search. Ian Pratt-Hartmann

Data Structures, Algorithms & Data Science Platforms

Chapter 9 Graph Algorithms

Lecture 14: General Problem-Solving Methods

1. Meshes. D7013E Lecture 14

Dynamic Programming Homework Problems

Chapter 3: Solving Problems by Searching

Chapter 9 Graph Algorithms

Chapter S:II. II. Search Space Representation

Princess Nora University Faculty of Computer & Information Systems ARTIFICIAL INTELLIGENCE (CS 370D) Computer Science Department

Assignment 5: Solutions

3 INTEGER LINEAR PROGRAMMING

Search Algorithms. IE 496 Lecture 17

Dynamic Programming Homework Problems

Graph and Digraph Glossary

(Refer Slide Time: 01:00)

Approximation Algorithms

Chapter 4. Uninformed Search Strategies

5105 BHARATHIDASAN ENGINEERING COLLEGE

Downloaded from ioenotes.edu.np

More NP-complete Problems. CS255 Chris Pollett May 3, 2006.

Search Algorithms for Discrete Optimization Problems

Binary Decision Diagrams

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

Practice Problems for the Final

Backtracking is a refinement of the brute force approach, which systematically searches for a

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

Chapter 11 Search Algorithms for Discrete Optimization Problems

Ar#ficial)Intelligence!!

Uninformed Search Methods

Artificial Intelligence (Heuristic Search)

Partha Sarathi Mandal

March 20/2003 Jayakanth Srinivasan,

Efficient memory-bounded search methods

Module 6 NP-Complete Problems and Heuristics

CSE 203A: Randomized Algorithms

Lecture 8: The Traveling Salesman Problem

Introduction to Optimization

D.K.M.COLLEGE FOR WOMEN (AUTONOMOUS), VELLORE-1.

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

Branch & Bound (B&B) and Constraint Satisfaction Problems (CSPs)

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Chapter S:I. I. Introduction. Examples for Search Problems Search Problem Abstraction

56:272 Integer Programming & Network Flows Final Examination -- December 14, 1998

Practice Final Exam 1

Scientific Programming. Backtracking

UNIT 5 BACKTRACKING. BACKTRACKING (General Method)

CS 161 Fall 2015 Final Exam

Algorithms: Lecture 10. Chalmers University of Technology

COMP 355 Advanced Algorithms Approximation Algorithms: VC and TSP Chapter 11 (KT) Section (CLRS)

Module 6 P, NP, NP-Complete Problems and Approximation Algorithms

Lecture 3: Graphs and flows

P and NP CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

Algorithm Design and Analysis

Examples of P vs NP: More Problems

Treewidth and graph minors

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

DESIGN AND ANALYSIS OF ALGORITHMS

Transcription:

Backtracking and Branch-and-Bound Usually for problems with high complexity Exhaustive Search is too time consuming Cut down on some search using special methods Idea: Construct partial solutions and extend Smart method to extend partial solutions can lead to faster solutions If the current partial solution cannot lead to a full solution, prune If the current solution is worse than some earlier known solution, prune This approach makes it possible to sometimes solve large problems in reasonable time Worst case is still too much time p. 1/18

Backtracking: Applies to non-optimization problems Branch and Bound: only for optimization problems. Backtracking: usually DFS Branch and Bound: usually BFS p. 2/18

Search Tree Root represents initial state, Each child of a node represents how the current partial solution maybe extended towards full solution Leaves: possible solutions partial solutions may be promising (can lead to a (good) solution) or non-promising (cannot lead to a solution or solution will be poor in quality) Prune non-promising nodes p. 3/18

n-ueens Problem Place n queens on an n-by-n chess board so that no two of them attack each other, that is, no two of them are in the same row, same column or same diagonal. Can consider Chess Board as n n matrix. So, if two queens are at (i,j) and (i,j ), then we want i i, j j and i i j j. Ex.: n = 4: p. 4/18

Search Space/State Space 0 1 5 2 3 6 1 2 1 2 3 X X X X X 4 7 1 2 3 4 1 3 4 X X X X X X X 8 1 2 3 4 1 2 X X X X X X Solution p. 5/18

Travelling Salesman Problem To find a circuit going through all the vertices exactly once, with least weight or weight X. Assume complete graph (where edge weights can be large ( ) to denote missing edges. Root can denote just the starting vertex. For any node, each child denotes adding one more vertex to the path. Depth of the tree is n. Root has n branches, and each intermediate node has n l branches based on its distance l from the root. Cost upto a node is the sum of weights on the path so constructed upto that point. Each leaf represents a possible solution, and we need to find least cost leaf (or a leaf of cost X). p. 6/18

Subset Sum problem Problem: Given a set S = {s 1,s 2,...,s n } of n positive integers. Find a subset of S whose sum is d. Example: S = {1,5,7,4,3}, d = 12, then answer could be {5,7} or {4,3,5}. Root can be empty subset. Nodes at the l-th level decide whether to add/not add s i to the sum. If current sum > d, then the sum is too high, and any further search in this branch can be pruned. If current sum plus sum of remaining numbers is < d, then sum is too small, and any further search in this branch can be pruned. If sum = d, then done. p. 7/18

Subset-Sum Problem Example: S = {3,5,6,7}, d = 15. p. 8/18

Backtracking Algorithm Backtrack(node: v) If v represents a solution, Print v If no descendant of v can be a solution, then Halt (* Pruning in above case *) Else For each child X of node do Backtrack(X) (* Here may need to calculate some information regarding X *) EndFor p. 9/18

Can stop the algorithm after first solution is found In worst case the whole search space is searched Even then there is a systematic way of doing it Order of exploring the children can often speed up the search Here heuristics come into picture: which child is more promising? Usually in such cases we have a way to give value to partial solutions. For example in chess, summing up the values of pieces can give a way to compare the different partial solutions. p. 10/18

Branch and Bound For optimization Problems More similar to BFS than to DFS (though can be done DFS way) At any point, expand the most promising partial solution Prune if the nodes value is no better than the best solution already found Partial solutions can be kept in heap/queue p. 11/18

Knapsack Problem Recall that in Knapsack problem, there are n objects o 1,o 2,...,o n, with weights w 1,w 2,...,w n and values v 1,v 2,...,v n. There is knapsack capacity K Choose a subset of objects which maximises the value subject to the constraint that total weight ie K. That, is find, S {1,2,...,n} such that Σ i S v i is maximised subject to the constraint that Σ i S w i K. p. 12/18

Ex.: Knapsack Problem The knapsack s capacity W is 10. item weight value value weight 1 4 $40 10 2 7 $42 6 3 5 $25 5 4 3 $12 4 p. 13/18

Ex.: Knapsack Problem p. 14/18

Branch-and-Bound P romisingset = {root} currentbestvalue= or based on problem type While P romisingset Do Pick a promising member v of the PromisingSet If v is a solution, then update currentbest value/solution Otherwise, expand v: For each child w of v If w cannot lead to a solution, then prune (i.e. do not add w to the PromisingSet) Else If solutions by w and its descendants is worse than currentbestvalue, then prune Else add w to the PromisingSet EndFor EndWhile Print the bestvalue solution p. 15/18

P romisingset = {root} Done false While PromisingSet and not Done Do Pick the most promising member v of the PromisingSet If v is a solution, then Done true and print the best solution as given by v Otherwise, expand v: For each child w of v If w cannot lead to a solution, then prune (i.e. do not add w to the PromisingSet) Else add w to the PromisingSet EndFor EndWhile p. 16/18

How to give value to a partial solution? Heuristics Should be "upper bound" for maximization problems, and lower bound for "minimization problems" p. 17/18

Travelling Salesman Problem Sum of edges used in the partial tour constructed at a node. Sum of edges used in the partial tour constructed at a node plus minimum value of the edges going out from the remaining vertices Sum of edges used in the partial tour constructed at a node plus minimum value of the edges going out from the remaining vertices to one of the remaining vertices (plus the starting vertex) Take both incoming and outgoing different edges for the remaining vertices, except we need only entry to starting vertex and exit from the last vertex in the path constructed so far: take half of these costs as we need to avoid counting twice. p. 18/18