Randomized Algorithm. NP-Complete Problem  A problem that, right now, we need exhaustive search  Example:  SAT  TSP  Vertex Cover  Etc.

Slides:



Advertisements
Similar presentations
NP-Hard Nattee Niparnan.
Advertisements

Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Reducibility Class of problems A can be reduced to the class of problems B Take any instance of problem A Show how you can construct an instance of problem.
1 The TSP : Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell ( )
NP-Complete Problems Polynomial time vs exponential time
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Combinatorial Algorithms
Great Theoretical Ideas in Computer Science.
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Introduction to Approximation Algorithms Lecture 12: Mar 1.
Approximation Algorithms
Approximation Algorithms: Combinatorial Approaches Lecture 13: March 2.
Dealing with NP-Complete Problems
1 Vertex Cover Problem Given a graph G=(V, E), find V' ⊆ V such that for each edge (u, v) ∈ E at least one of u and v belongs to V’ and |V’| is minimized.
The Theory of NP-Completeness
Analysis of Algorithms CS 477/677
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
1 NP-Complete Problems Polynomial time vs exponential time –Polynomial O(n k ), where n is the input size (e.g., number of nodes in a graph, the length.
Chapter 11: Limitations of Algorithmic Power
1 Combinatorial Dominance Analysis Keywords: Combinatorial Optimization (CO) Approximation Algorithms (AA) Approximation Ratio (a.r) Combinatorial Dominance.
9-1 Chapter 9 Approximation Algorithms. 9-2 Approximation algorithm Up to now, the best algorithm for solving an NP-complete problem requires exponential.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
1 NP-Complete Problems (Fun part) Polynomial time vs exponential time –Polynomial O(n k ), where n is the input size (e.g., number of nodes in a graph,
Approximation Algorithms
1.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Programming & Data Structures
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
The Traveling Salesperson Problem Algorithms and Networks.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Approximation Algorithms These lecture slides are adapted from CLRS.
Thursday, May 9 Heuristic Search: methods for solving difficult optimization problems Handouts: Lecture Notes See the introduction to the paper.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Unit 9: Coping with NP-Completeness
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
Optimization Problems
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
1 Approximation algorithms Algorithms and Networks 2015/2016 Hans L. Bodlaender Johan M. M. van Rooij TexPoint fonts used in EMF. Read the TexPoint manual.
Algorithms for hard problems Introduction Juris Viksna, 2015.
NP Completeness Piyush Kumar. Today Reductions Proving Lower Bounds revisited Decision and Optimization Problems SAT and 3-SAT P Vs NP Dealing with NP-Complete.
CSC 413/513: Intro to Algorithms
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
Approximation Algorithms by bounding the OPT Instructor Neelima Gupta
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
Approximation algorithms
TU/e Algorithms (2IL15) – Lecture 11 1 Approximation Algorithms.
Optimization Problems
The Theory of NP-Completeness
The NP class. NP-completeness
Hard Problems Some problems are hard to solve.
Approximating the MST Weight in Sublinear Time
Approximation algorithms
Algorithms for hard problems
Optimization Problems
Approximation Algorithms
Chapter 11 Limitations of Algorithm Power
Presentation transcript:

Randomized Algorithm

NP-Complete Problem  A problem that, right now, we need exhaustive search  Example:  SAT  TSP  Vertex Cover  Etc.

Travelling Salesman Problem (TSP)  Find a sequence of city to visit  Minimize the cost of travel

Example RouteCost A B C D A B D C A C B D A C D B A D B C A D C B

Example RouteCost A B C D A B D C A C B D A C D B A D B C A D C B

General Search Algorithm while has_unexplored_solution() { Solution sol = gen_another_solution() int cost = evaluate(sol) if (cost < min_cost) { min_cost = cost; min_sol = sol; } Time = number of solutions * evaluation

TSP Solution Space  N cities  (N-1)! / 2  assume symmetric graph

What to do if N is too large?

Relaxation  In practice, we don’t really need the “best” solution  But we need it now  Something close to now (1 min, 1 hour, etc.. But not 100 years)  Just something being “near” the best solution

One who try to optimize everything is bounded to be unhappy Approximation Algorithm

Bounded solution  If solving for “optimum” solution requires exponential time  What polynomial time could give us?  What can we say about the solution from polynomial time?

Approximation Ratio The “best” solution for I Our algorithm Problem Instance Approximation ratio, upper bound of our sub-optimal

Approximation Algorithm  Algorithm that run fast (polynomial time) that give good approximation ratio  Reasonable choice when dealing with NP complete problem

Clustering  Input:  Set of points X  Integer k  Output:  Partition of points into k set  Such that the diameter of each set is minimized

Metric Property  A function d(x,y) such that 1. d(x,y) >= 0 2. d(x,y) = 0 if and only if x = y 3. d(x,y) = d(y,x) 4. d(x,y) < d(x,z) + d(z,y) Triangular Inequality

Example

Approximated Version

Guarantee  Ratio = 2  i.e., the resulting diameter is not more than twice of original

Why ?  Let p be the point in X that is farthest from μ 1, μ 2, μ 3,…, μ k  Let r be the distance from p to it’s closest center  Then… by triangular inequality, every cluster has diameter at most 2r

So what?  How r relate to the optimal solution?  There are k + 1 points  μ 1, μ 2, μ 3,…, μ k, p  Such that they are all at least r from the others  So, any partition into k set must have some set that contains at least two of tem  That set must has diameter at least r

Approximated Euclidian TSP  TSP such that distance between two cities is a Metric  What is closely relate to TSP and can be easily compute?

MST and TSP  Given an answer for TSP  It is a cycle  Remove one edge from the answer  The result is path that is also a spanning tree (not minimal)  Let p be that path

From MST to TSP  Given an MST  Do DFS, the result of visiting is simply a cycle that visit every vertex  Also visit some vertex multiple times

From MST to TSP  Length of that path is at most twice of the best TSP path  Fix the path into TSP  Simply skip the vertex that is about to re-visit and move to the next vertex in the list

Fixing the Path By triangular inequality, the new path is shorter

Approximated 01-Knapsack  Input  A number W, the capacity of the sack  n pairs of weight and price ((w 1,p 1 ),(w 2,p 2 ),…,(w n,p n ))  w i = weight of the i th items  p i = price of the i th item  Output  A subset S of {1,2,3,…,n} such that  is maximum 

Guarantee  Pick any ε > 0  Result value is at least (1 – ε) of the maximum value

Approximated 01-Knapsack  Knapsack can be solved using dynamic programming  Using O(nW)  W = sum of weight  We can derive similar algorithm using O(nV) where V = sum of values

O(nV) knapsack  Let K(v) be the “minimal weight” when sum of selected value is v  If the i th item is in the best solution  K(v) = K(v – p i ) + w i  But, we don’t really know that the i th item is in the optimal solution  So, we try everything  K(v) = min 1≤i ≤ n (K(v – p i ) + w i )

Approximation  Since it is O(nV)  Can we reduce V?  To improve running time

Value scaling  Scale the price by a constant  Resulting price is at most n/ε  Thus, the running time is (n 3 / ε)

The optimal solution  Let S be the selected subset of the optimal  Let K * be the maximum value  Find the result of the rescaled input

Approximation Ratio  Rewrite in terms of K *  Let Ŝ be the set of selected rescaled item

Search with bounded resource RANDOM SEARCH

General Search Algorithm while time_not_exceed() { Solution sol = random_a_solution() int cost = evaluate(sol) if (cost < min_cost) { min_cost = cost; min_sol = sol; } Time is bounded Best solution is not guaranteed

Does it work?  If we have “enough” time…  Eventually, we will hit the “right” answer

It’s ok to be greed Hill Climbing

Can we improve Random Search?  Anything better than randomly generate a new answer?

0-1 Knapsack Problem  Pick a combination of items  Solution Space  (0)  (1)  (2)  (3)  (4) .  (31) 32 solutions in total

Evaluation Function Solution eval (1) (2) (3) (4)(5) (6) …

Neighbor of Solution  In solution space  (4) is close to  (3) and  (5)

Hill Climbing Search  Generate only the neighbor solution  Move to the best neighbor solution Solution sol = random_a_solution() while time_not_exceed() { Solution nb[] = gen_all_neighbors(sol) Solution nb_sol; int nb_min; For all x in nb { int cost = evaluate(x) if (cost < nb_min) { nb_min = cost; nb_sol = x; } if (nb_min < min_cost) { min_cost = nb_min; sol = nb_sol; } If cost does not improve, we might stop

Several definition of neighbor

Best Problem for Hill Climbing  Unimodal

Bad problem for hill climbing  Multimodal

Local Minima  Hill climbing is a local search  (solver can define their own “local”)  It could stuck at local minima  Need something to fix it  If stuck  Randomly generate another solution and start from that solution

O’ mother nature, I worship thou Simulated Annealing

Annealing  A material (metal) is heated and then slowly cooled down  Rearrangement of atom  Because, if not heated, atom is stuck at irregular position from inertia  That’s like the “Local Minima”

Simulated Annealing  Just like hill climbing  But solution is allowed to move to lower position  With some probability  With inverse proportional to the elapsed time  Help escape from local minima

Simulated Annealing Solution sol = random_a_solution() while time_not_exceed() { Solution nb = gen_one_neighbors(sol) int cost = evaluate(nb); if (cost < min_cost) { sol = nb; min_cost = cost; } else { if (random() < chance_at_time(t)) { sol = nb; min_cost = cost; }

Fitness Function Randomized for Decision Problem

Decision Problem  We look for “the solution”  Not the best  Answer is either yes/no

SAT Problem  Find assignment to x,y,z that make this expression true  evaluate (sol) is either “true” or “false”

Fitness of SAT  Use other function for hill climbing  A function that is maximal when evaluate (sol) is true  Should return something near maximum when sol is near the “correct” answer

Example for SAT  Fitness = number of clause that is true

GA? SA? Random? Hill Climbing? Lot’s more…. What to use?

No Free Lunch Theorem  algo A outperform algo B on average  For example Hill Climbing >>> Random?  Here’s come the “No Free Lunch” theorem  No such A,B exist

Definition: Black Box algorithm  Oracle-based model Does not ask same question twice X1X1 X2X2 F(X 1 ) F(X 2 )

Definition: algorithm  Sample   D m = all sample of size m  D = all sample = D 1 U D 2 U …  Optimization Algorithm is a mapping  From D to   a : d  D  { x | x  d x }

 Given  Algorithm a  m number of oracle call  Cost function f  Performance = P(d y m | f, m, a )  Performance measure in d y m : Φ(d y m )  e.g., minimization Definition: performance Desired output Problem at hand Resource Algorithm

The NFL theorem  For any two algorithms a 1, a 2  The chance of getting any particular d y m  P(d y m |f,m,a)  Is equal when sum over all possible function

Why?

  = finite search space   = finite cost value space  Opt. problem f :      =   = all possible function  Size = |  | |  |  Large, but finite

Implication of NFL  NFL says  There are no universally good algo  if A do better than B on some problem  B must do better than A on other problem  E.g. If A beat random search on some set…  A must performs worse than random  for the rest of problems

Implication of NFL  If someone write a paper saying  “We design A for one particular Problem F”  “We compare it with B on test problems f 1,f 2,f 3 ”  “Result show that A is better than B”  “My algo should be better than B on all F”  It might be wrong…

Another view of NFL  Better indicator for performance  NFL is proven when P(f) is flat  Flat P(f) is sufficient... But not necessary  In real life, P(f) is not flat  However  Some knowledge must put into A  structure of problem does not justify the choice

Conclusion  Randomized algorithm works well in practice  But you need to at least put some knowledge it in  Given a problem, if you really has no idea, try them first…