Brute Force Approaches

Slides:



Advertisements
Similar presentations
Knapsack Problem: Greedy vs. Brute Force pp (Section 7.6)
Advertisements

Algorithms + L. Grewe.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
5-1 Chapter 5 Tree Searching Strategies. 5-2 Satisfiability problem Tree representation of 8 assignments. If there are n variables x 1, x 2, …,x n, then.
Branch & Bound Algorithms
Greedy vs Dynamic Programming Approach
Branch and Bound Searching Strategies
24-Jun-15 Pruning. 2 Exponential growth How many leaves are there in a complete binary tree of depth N? This is easy to demonstrate: Count “going left”
Problem Solving and Search in AI Heuristic Search
1 Branch and Bound Searching Strategies 2 Branch-and-bound strategy 2 mechanisms: A mechanism to generate branches A mechanism to generate a bound so.
Ch 13 – Backtracking + Branch-and-Bound
Backtracking.
The Knapsack Problem Input –Capacity K –n items with weights w i and values v i Goal –Output a set of items S such that the sum of weights of items in.
Dave Risch. Project Specifications There is a “knapsack” that you want to fill with the most valuable items that are available to you. Each item has a.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding ILPs with Branch & Bound ILP References: ‘Integer Programming’
Decision Procedures An Algorithmic Point of View
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
1 Branch and Bound Searching Strategies Updated: 12/27/2010.
Algorithm Design Methods (II) Fall 2003 CSE, POSTECH.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
Backtracking & Brute Force Optimization Intro2CS – weeks
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
Chapter 13 Backtracking Introduction The 3-coloring problem
Branch and Bound Searching Strategies
Introduction to Algorithms: Brute-Force Algorithms.
Various Problem Solving Approaches. Problem solving by analogy Very often problems can be solved by looking at similar problems. For example, consider.
Problem Solving: Brute Force Approaches
Integer Programming An integer linear program (ILP) is defined exactly as a linear program except that values of variables in a feasible solution have.
BackTracking CS255.
Depth-First Search N-Queens Problem Hamiltonian Circuits
Dynamic Programming Sequence of decisions. Problem state.
Lecture on Design and Analysis of Computer Algorithm
Greedy Method 6/22/2018 6:57 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
Design and Analysis of Algorithm
Problem Solving by Searching
Informed Search and Exploration
Introduction to Operations Research
Artificial Intelligence Problem solving by searching CSC 361
Analysis and design of algorithm
Problem Solving: Brute Force Approaches
CS 3343: Analysis of Algorithms
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
The Greedy Method Spring 2007 The Greedy Method Merge Sort
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Greedy Algorithms Many optimization problems can be solved more quickly using a greedy approach The basic principle is that local optimal decisions may.
Analysis & Design of Algorithms (CSCE 321)
Advanced Algorithms Analysis and Design
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Dynamic Programming Merge Sort 1/18/ :45 AM Spring 2007
Haskell Tips You can turn any function that takes two inputs into an infix operator: mod 7 3 is the same as 7 `mod` 3 takeWhile returns all initial.
Dynamic Programming 23-Feb-19.
Branch and Bound Searching Strategies
Pruning 24-Feb-19.
Lecture 3: Environs and Algorithms
Algorithm Design Methods
Backtracking and Branch-and-Bound
Dynamic Programming.
Merge Sort 4/28/ :13 AM Dynamic Programming Dynamic Programming.
Constraint Satisfaction
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Lecture 2: Greedy Algorithms
0-1 Knapsack problem.
Major Design Strategies
Dynamic Programming Merge Sort 5/23/2019 6:18 PM Spring 2008
Major Design Strategies
Lecture 4: Tree Search Strategies
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

Brute Force Approaches Techniques for finding optimal solutions to hard problems “relatively” quickly Backtracking Branch and Bound Combining efficient solutions with brute force approaches Other issues

The Knapsack Problem Input Goal Capacity K n items with weights wi and values vi Goal Output a set of items S such that the sum of weights of items in S is at most K and the sum of values of items in S is maximized

Greedy Does Not Work What are possible greedy strategies? Highest Density First Highest Value First Lowest Weight First Prove these are not optimal for the 0-1 knapsack problem.

Multi-constraint Knapsack Input Capacity K1 and K2 n items with integer weights wi, size si, and values vi Goal Output a set of items S such that the sum of weights of items in S is at most K1 the sum of sizes of items in S is at most K2 and the sum of values of items in S is maximized Can we use dynamic programming?

Situation where dynamic programming does not work What if our problem can’t be described with integers? wA = 2 vA = $40 wB =  vB = $50 wC = 1.98 vC = $100 wD = 5 vD = $95 wE = 3 vE = $30 We have to resort to brute force….

Brute Force Generate all possible solutions With n items, there are 2n solutions to be generated Check each to see if they satisfy the constraint Save maximum solution that satisfies constraint Can be represented as a tree

Brute Force: Branching Out B C D E B C D E There are 2n solutions for us to consider. We scan through them for the most valuable legal one. As a matter of fact, the first one was already out before we even considered E. So we could have stopped searching right there! Weight = 15.12 Value = $315 Weight = 8.98 Value = $235 Weight = 9.98 Value = $225

Backtracking In the tree representation, we can think of the previous algorithm doing a DFS in the tree If we reach a point where a solution no longer is feasible, there is no need to continue exploring We can “backtrack” from this point and potentially cut off much of the tree and many of the solutions In the given example, backtracking would be much more effective if we had even more items or a smaller knapsack capacity

Backtracking In Out A B B C C C C D D D E D E D D E D E D E E E E E E 2, $40 , $50 1.98, $100 5, $95 3, $30 Backtracking A In Out B B C C C C D D D E D E D D E D E D E As soon as we choose the D in the first branch, we’re already over-weight, so we can stop there. If there were a F, G, H, I, etc… you can imagine that this would be very useful -- it would cut off an entire sub-tree from needing to be checked. Can we do better? E E E E E E Weight = 8.98 Value = $235 Weight = 9.98 Value = $225

Branch and Bound We can backtrack if we know the best possible solution in current subtree is worse than current best solution obtained so far. Estimates for improvement given current ordering A down can give $315 B down -> $275 C down -> $225 D down -> $125 E down -> $30

Branch and Bound In Out A B B C C C C D D D D D D E E E E E E E E 2, $40 , $50 1.98, $100 5, $95 3, $30 Branch and Bound A In Out B B C C C C D D D D D D If choosing ALL of the remaining values won’t give us as good an answer as we have, we should stop here! A down can give $315 B down -> $275 C down -> $225 D down -> $125 E down -> $30 E E E E E E E E Weight = 7.12 Value = $190 Weight = 8.98 Value = $235

Generating a good bound The key to branch and bound is having a good initial bound. How might we generate a good initial bound?

2, $40 , $50 1.98, $100 5, $95 3, $30 Order of items Since there is no fixed ordering of items, is there a better way to order the input items? Highest weight first Generate infeasible solutions quickly Highest density first Generate good solution quickly Which is better depends on input

Heaviest on Top In Out D B B E E A A A C A C C C C D: 5, $95 B: , $50 (Max remaining = $220) E E A A A C A Weight comes into play first! This would be more dramatic if total weight was much larger than allowed weight. This worked well in this case because the heaviest was worth a lot. But what if it isn’t? C C C C Weight = 8.14 Value = $145 Weight = 10.0 Value = $165 Weight = 9.98 Value = $225 Weight = 8.98 Value = $235

Best Density on Top In Out C A A D D B B B B E E E E Here we put the most likely to be included on the top. Next Problem: Polygon Triangulation E E E E Weight = 8.98 Value = $235

Greedy and Brute Force Suppose half the inputs to our knapsack problem all have the same weight. If all inputs had the same weight, we could implement a greedy solution However, since half do not, we cannot use greedy alone to find optimal solution Combine brute-force approach with greedy to find optimal solution more quickly.

The Breakdown... In Out Greedy on half! F1 F2 F2 F3 F3 F3 F3 F4 F4 F4

Algorithm Backtrack on half the inputs At leafs, apply greedy strategy on the other half of the inputs Comparison Pure brute force: O(2n) Combination: O(n2n/2)

How much better? Assumptions 250 would take over 35 years Suppose n=50 We can test 1,000,000 solutions/second. 250 would take over 35 years 225 can be generated in half an hour Plus marginal time to generate greedy solution for each of the 225 solutions

Another combination Suppose half the inputs to our knapsack problem have small integral weights/values while the other half have real weights/values. How can we combine approaches to solve this efficiently?

The n-Queens Problem Input Task Positive integer n Task Place n queens on an n by n chessboard so that no two queens attack each other (on same row, column, diagonal), or report that this is impossible Solve the n-queens problem for n = 1, 2, 3

n=4 Pure brute force search Improvements 16 squares on a 4 by 4 chessboard Leads to 16 * 15 * 14 * 13 = 43,680 possible solutions Improvements At most one queen per row: 44 = 256 possible solutions Backtracking: If two queens already attack before final queen placed, backtrack

Larger values of n n=8 n=12 At most one queen per row: 88 = 16,777,216 Early backtracking: 2057 nodes total Time to find first solution: 114 nodes n=12 At most one queen per row: 1212 Early backtracking: 856,189 nodes total Time to find first solution: 262 nodes

The Problem In the U.S. navy, the SEALS are each specially trained in a wide variety of skills so that small teams can handle a multitude of missions. If there are k different skills needed for a mission, and n SEAL members that can be assigned to the team, find the smallest team that will cover all of the required skills. Andersen knows hand-to-hand, first aid, and camouflage Butler knows hand-to-hand and snares Cunningham knows hand-to-hand Douglas knows hand-to-hand, sniping, diplomacy, and snares Eckers knows first-aid, sniping, and diplomacy This is also known as the “Set Cover” problem. Its described in detail in your textbook.

Greedy Algorithm What is the obvious greedy algorithm for this problem? Find a counter-example to the optimality of greedy for this problem.

Brute Force Approach What is the brute-force approach? How can we simplify the problem as far as possible in polynomial time? How can we set bounds on the solutions? When will we need to do backtracking? What order should we test the potential members in when branching? * This first one should be easy * Some simplifications are obvious if we look at our example… * Bounds are easy… if we’ve already included more people than we did in our best solution, we can stop. * Will we ever need to? Not with good simplification! * Can we make both sub-problems much easier? Another question: What data structures to use?