高级算法 (Fall 2016)/Greedy and Local Search
Contents
Set cover
Given subsets of a universe of size , a forms a set cover if , that is, is a sub-collection of sets whose union "covers" all elements in the universe.
Without loss of generality, we always assume that the universe is .
This defines an important optimization problem:
Set Cover Problem - Input: subsets of a universe of size ;
- Output: the smallest such that .
We can think of each instance as a bipartite graph with vertices on the right side, each corresponding to an element , vertices on the left side, each corresponding to one of the subsets , and there is a bipartite edge connecting with if and only if . By this translation the set cover problem is precisely the problem of given as input a bipartite graph , to find the smallest subset of vertices on the right side to "cover" all vertices on the left side, such that every vertex on the left side is incident to some vertex in .
By alternating the roles of sets and elements in the above interpretation of set cover instances as bipartite graphs, the set cover problem can be translated to the following equivalent hitting set problem:
Hitting Set Problem - Input: subsets of a universe of size ;
- Output: the smallest subset of elements such that intersects with every set for .
Frequency and Vertex Cover
Given an instance of set cover problem , for every element , its frequency, denoted as , is defined as the number of sets containing . Formally,
- .
In the hitting set version, the frequency should be defined for each set: for a set its frequency is just the size of the set .
The set cover problem restricted to the instances with frequency 2 becomes the vertex cover problem.
Given an undirected graph , a vertex cover is a subset of vertices such that every edge has at least one endpoint in .
Vertex Cover Problem - Input: an undirected graph
- Output: the smallest such that every edge is incident to at least one vertex in .
It is easy to compare with the hitting set problem:
- For graph , its edges are vertex-sets of size 2.
- A subset of vertices is a vertex cover if and only if it is a hitting sets for , i.e. every intersects with .
Therefore vertex cover is just set cover with frequency 2.
The vertex cover problem is NP-hard. Its decision version is among Karp's 21 NP-complete problems. Since vertex cover is a special case of set cover, the set cover problem is also NP-hard.
Greedy Algorithm
We present our algorithms in the original set cover setting (instead of the hitting set version).
A natural algorithm is the greedy algorithm: sequentially add such to the cover , where each covers the largest number of currently uncovered elements, until no element is left uncovered.
GreedyCover - Input: sets ;
- initially, , and ;
- while do
- find with the largest ;
- let and ;
- return ;
Obviously the algorithm runs in polynomial time and always returns a set cover. We will then show how good the set cover returned by the algorithm compared to the optimal solution by analyzing its approximation ratio.
We define the following notations:
- We enumerate all elements of the universe as , in the order in which they are covered in the algorithm.
- For , let denote the set of uncovered elements in the beginning of the -th iteration of the algorithm.
- For the -th element covered, supposed that it is covered by in the -th iteration, define
- to be the average "price" to cover element in the algorithm.
Observe that if is covered by in the -th iteration, then there are precisely elements, including , become covered in that iteration, and all these elements have price . Then it is easy to have the following lemma:
Lemma 1 - For the set cover returned by the algorithm, .
This lemma connect the size of the returned set cover to the prices of elements. The next lemme connects the price of each element to the optimal solution.
Lemma 2 - For each , , where is the size of the optimal set cover.
Proof. For an instance with a universe of size , let denote an optimal set cover. Then
- .
By averaging principle, there must be an of size
- .
By the greediness of the algorithm, in the first iteration the algorithm must choose a set of at least this size to add to the set cover , which means the price the element covered at first, , along with all elements covered in the first iteration, are priced as
- .
For the -th element covered by the algorithm, supposed that it is covered by in the -th iteration, and the current universe for the uncovered elements is , it holds that
- ,
since there are at most elements covered before .
The uncovered elements constitutes a set cover instance (some of which may be empty), with universe . Note that this smaller instance has an optimal set cover of size at most OPT (since the optimal solution for the original instance must also be an optimal solution for this smaller instance), and is among the elements covered in the first iteration of the algorithm running on this smaller instance. By the above argument, it holds for the (also note that this value is not changed no matter as in the -th integration of the algorithm running on the original instance or as in the first iteration of the algorithm on the smaller instance) that The lemma is proved.
Combining Lemma 1 and Lemma 2, we have
where is the -th Harmonic number.
This shows that the GreedyCover algorithm has approximation ratio .
Theorem - For any set cover instance with optimal set cover of size , the GreedyCover returns a set cover of size
- ,
- where is the size of the universe and represents the -th Harmonic number.
- For any set cover instance with optimal set cover of size , the GreedyCover returns a set cover of size
Ignoring lower order terms, is also the best approximation ratio achievable by polynomial time algorithms, assuming that NPP.
- Lund and Yannakakis (1994) showed that there is no poly-time algorithm with approximation ratio , unless all NP problems have quasi-polynomial time algorithms (which runs in time ).
- Feige (1998) showed that there is no poly-time algorithm with approximation ratio better than with the same complexity assumption.
- Ras and Safra (1997) showed that there is no poly-time algorithm with approximation ratio better than for a constant assuming that NPP.
- Dinur and Steurer (2014) showed that there is no poly-time algorithm with approximation ratio better than assuming that NPP.
Primal-Dual Algorithm
Given an instance for set cover, the set cover problem asks for minimizing the size of subject to the constraints that and , i.e. is a set cover. We can define a dual problem on the same instance. The original problem, the set cover problem is called the primal problem. Formally, the primal and dual problems are defined as follows:
- Primal:
- minimize
- subject to
- Dual:
- maximize
- subject to
- ,
The dual problem is a "maximum matching" problem, where the matching is defined for the set system instead of graph. Given an instance , an is called a matching for if for all .
It is easier to see these two optimization problems are dual to each other if we write them as mathematical programs.
For the primal problem (set cover), for each , let indicate whether . The set cover problem can be written as the following integer linear programming (ILP).
- Primal:
- minimize
- subject to ,
- ,
For the dual problem (maximum matching), for each , let indicate whether . Then the dual problem can be written as the following ILP.
- Dual:
- maximize
- subject to ,
- ,
It is fundamental fact that for a minimization problem, every feasible solution to the dual problem (which is a maximization problem) is a lower bound for the optimal solution to the primal problem. This is called the weak duality phenomenon. The easy direction (that every cut is a lower bound for every flow) of the famous "max-flow min-cut" is an instance of weak duality.
Theorem (Weak Duality) - For every matching and every vertex cover for , it holds that .
Proof. If is a matching for , then every intersects with on at most one element, which means no two elements in can be covered by one , and hence each element in will consume at least one distinct to cover. Therefore, for any set cover, in order to cover all elements in must cost at least sets.
More formally, for any matching and set cover , it holds that
where the first equality is because is a set cover and the last inequality is because is a matching.
As a corollary, every matching for is a lower bound for the optimal set cover :
Corollary - Let be an instance for set cover, and the size of the optimal set cover.
- For every matching for , it holds that .
Now we are ready to present our algorithm. It is a greedy algorithm in the dual world. And the maximal (local optimal) solution to the dual problem helps us to find a good enough solution to the primal problem.
DualCover - Input: sets ;
- construct a maximal matching such that for all
- by sequentially adding elements to until nothing can be added;
- return
The algorithm constructs the maximal matching by sequentially adding elements into until reaching the maximality. This obviously takes polynomial time.
It is not so obvious to see that the returned is always a set cover. This is due to the maximality of the matching :
- By contradiction, assuming that is not a set cover, which means there is an element such that for all , , which implies that and the is still a matching, contradicting the maximality of .
Therefore the constructed as in the DualCover algorithm must be a set cover.
For the maximal matching constructed by the DualCover algorithm, the output set cover is the collection of all sets which contain at least one element in . Recall that the frequency of an element is defined as the number of sets containing . Then each element may contribute at most many sets into the set cover . Then it holds that
where denotes the maximum frequency of all elements.
We proved the following -approximation bound for the DualCover algorithm on set cover instances with maximum frequency .
Theorem - For any set cover instance with optimal set cover of size , the DualCover returns a set cover of size
- ,
- where is the maximum frequency.
- For any set cover instance with optimal set cover of size , the DualCover returns a set cover of size
When the frequency , the set cover problem becomes the vertex cover problem. And the DualCover algorithm works simply as follows:
DualCover for vertex cover problem - Input: an undirected graph ;
- initially ;
- while
- pick an arbitrary edge and add both and to ;
- remove all edges in incident to or ;
- return ;
Since this algorithm is just an implementation of the DualCover algorithm on the vertex cover instances (set cover instances with frequency ), by the analysis of the DualCover algorithm, it is a 2-approximation algorithm for the vertex cover problem.
Ignoring lower order terms, is also the best approximation ratio achievable by polynomial time algorithms, assuming certain complexity assumption.
- Dinur and Safra (2005) showed that there is no poly-time algorithm with approximation ratio , assuming that NPP.
- Khot and Regev (2008) showed that there is no poly-time algorithm with approximation ratio for any constant assuming the unique games conjecture.
Scheduling
We consider the following scheduling problem:
- There are jobs to be processed.
- There are identical parallel machines. Each machine can start processing jobs at time 0 and can process at most one job at a time.
- Each job must be processed on one of these machines for time units without interruption. is called the processing time of job .
In a schedule each job is assigned to a machine to process starting at some time, respecting the above rules. The goal is to complete all jobs as soon as possible.
Suppose each job is completed at time , the objective is to minimize the makespan .
This problem is called minimum makespan on identical parallel machines. It can be described as the following simpler version as a load balancing problem:
Minimum Makespan on Identical Parallel Machines (load balancing version) - Input: positive integers and a positive integer ;
- Output: an assignment which minimizes .
With the notation for scheduling, this problem is the scheduling problem .
The notation was introduced by Ron Graham et al. to model scheduling problems. See this note for more details.
The problem is NP-hard. In particular, when , the problem can solve the partition problem, which is among Karp's 21 NP-complete problems.
Partition Problem - Input: a set of positive integers ;
- Determine whether there is a partition of into and such that .
Graham's List algorithm
In a technical report in the Bell labs in 1966, Graham described a natural greedy procedure for scheduling jobs on parallel identical machines and gave an elegant analysis of the performance of the procedure. It was probably the first approximation algorithm in modern dates with provable approximation ratio. Interestingly, it was even earlier than the discovery of the notion of NP-hardness.
Graham's List algorithm takes a list of jobs as input. The load of a machine is defined as the total processing time of the jobs currently assigned to the machine.
The List algorithm (Graham 1966) - Input: a list of jobs with processing times ;
- for
- assign job to the machine that currently has the smallest load;
In a scheduling language, the List algorithm can be more simply described as:
- Whenever a machine becomes idle, it starts processing the next job on the list.
It is well known that the List algorithm has approximation ratio .
Theorem - For every instance of scheduling jobs with processing times on parallel identical machines, the List algorithm finds a schedule with makespan , where is the makespan of optimal schedules.
Proof. Obviously for any schedule the makespan is at least the maximum processing time:
and by averaging principle, the makespan (maximum load) is at least the average load:
- .
Suppose that in the schedule given by the List algorithm, job finished at last, so the makespan where is the completion time of job .
By the greediness of the List algorithm, before job is scheduled, the machine to which job is going to be assigned has the smallest load. By averaging principle:
- .
On the other hand,
- .
Together, we have
The analysis is tight, you can try to construct a family of instances on which the List returns schedules with makespan at least .
Local Search
Another natural idea for solving optimization problems is the local search. Given an instance of optimization problem, the principle of local search is as follows:
- We start with a feasible solution.
- At each step, we try to improve the solution by modifying the locally (changing the assignment of a constant number of variables), until nothing can be further changed (thus a local optimum is reached).
For the scheduling problem, we have the following local search algorithm.
LocalSearch - start with an arbitrary schedule of jobs to machines;
- while (true)
- let denote the job finished at last in the current schedule;
- if there is machine such that job can finish earlier if transferred to machine
- job transfers to machine ;
- else break;
By a similar analysis to that of the List algorithm, we can give the same bound to the approximation ratio of the LocalSearch algorithm.
Suppose that when the algorithm stops and a local optimum is reached, job finishes at last. Then the makespan is achieved by job 's completion time .
In a local optimum, cannot transfer to any other machine to improve its completion time . Then by averaging principle, the starting time of job , , must be no greater than the average processing time of all jobs except :
- .
The rest is precisely the same as the analysis of the List algorithm. We have
- .
So the approximation ratio of the LocalSearch algorithm is .
For local search, a bigger issue is to bound its running time. In the LocalSearch algorithm for scheduling, we observe that the makespan never increases. Furthermore, in each iteration, either decreases or the number of jobs completes at time decreases. Therefore the algorithm must terminates within finite steps.
In order to improve the running time, we consider the following variant of the local search algorithm.
GreedyLocalSearch - start with an arbitrary schedule of jobs to machines;
- while (true)
- let denote the job finished at last in the current schedule;
- let denote the machine which completes all its jobs earliest;
- if job can finish earlier by transferring to the machine
- job transfers to machine ;
- else break;
The GreedyLocalSearch algorithm has the same approximation ratio as the LocalSearch algorithm since it is a special case of the LocalSearch algorithm.
We let to denote the completion time of the machine who finishes all its jobs earliest. It is easy to see that never decreases. More precisely, in each iteration either increases or the number of machines that complete all its jobs at time decreases. In each iteration, if the algorithm does not terminate, the job that finishes at last transfers to the machine that stops at time . Since a job will not be transferred to a machine which stops no earlier than its starting time and never decreases, a job will never be transferred twice. Therefore, the GreedyLocalSearch algorithm must terminate within iterations.
Theorem - For every instance of scheduling jobs with processing times on parallel identical machines, starting from an arbitrary schedule, the GreedyLocalSearch algorithm terminates in at most iterations and always reaches a schedule with makespan , where is the makespan of optimal schedules.
The local search algorithm can start with an arbitrary solution. If it starts with a schedule returned by the List algorithm, it will terminate without making any change to the schedule, yet the approximation ratio still holds. This provides another proof of that the List algorithm is -approximation.
In the analysis of the local search algorithm, we actually show that any local optimum has approximation ratio to the global optimum. And the List algorithm returns a local optimum.
Longest Processing Time (LPT)
In the List algorithm, the jobs are presented in an arbitrary order. Intuitively, the List algorithm seems to perform better if we process the heavier jobs easier. This gives us the following Longest Processing Time (LPT) algorithm.
LongestProcessingTime(LPT) - Input: a list of jobs with processing times in non-increasing order;
- for
- assign job to the machine that currently has the smallest load;
The analysis of approximation is similar as before, with an extra observation that the job that finishes at last is smaller since the jobs are scheduled in the non-increasing order in processing times.
Suppose that jobs finishes at last. And the makespan is job 's completion time . Due to the greediness of the algorithm, we still have that
- .
Therefore,
- .
We still have the lower bound . Next we find a better lower bound of in terms of .
Note that the first jobs are assigned to all machines, one job per each machine. Without loss of generality we can assume:
- the number of jobs is greater than the number of machines, ;
- the makespan is achieved by a job other than the first jobs, ;
since if otherwise, the LPT algorithm will return an optimal solution.
Therefore . And observe that even for the first jobs with processing times , the optimal makespan is at least by pigeon hole principle. We have the lower bound for the optimal makespan
- .
Altogether, we have
- .
We show that the LPT algorithm is -approximation.
Both the analysis of the LPT algorithm and approximability of the scheduling problem can be further improved:
- With a more careful analysis, one can show that the LPT algorithm is -approximation. The trick is to show by case analysis that or otherwise the LPT algorithm can find an optimal solution.
- By scaling and rounding a dynamic programming, one can obtain a PTAS (Polynomial Time Approximation Scheme) for minimum makespan scheduling on parallel identical machines.
Online Algorithms and Competitive Ratio
An advantage of the List algorithm is that it is an online algorithm. For an online algorithm, the input arrives one piece at a time, and the algorithm must make decision when a piece of the input arrives without seeing the future pieces. In contrast, the algorithm which can make decision after seeing the entire input is called an offline algorithm.
For the scheduling problem, the online setting is that the jobs arrive one-by-one in a series, and the online scheduling algorithm needs to assign each job to a machine to start processing right after it arrives (or having a buffer of bounded size to temporarily store the incoming jobs). The List algorithm is an online scheduling algorithm, while the LPT algorithm is not because it needs to sort all jobs according to the processing time.
For online algorithms, a notion similar to the approximation ratio, the competitive ratio was introduced to measure the performance. For a minimization problem, we say an online algorithm has competitive ratio , or is -competitive, if for any input sequence ,
where is the value of the solution returned by the online algorithm with the input and is the value of the solution returned by the optimal offline algorithm on the same input. The competitive ratio for maximization problem can be similarly defined.
For online scheduling, it is immediate to see that the List algorithm is -competitive.
- This competitive ratio is optimal for all deterministic online algorithms on or machines.
- For large number of machines, better competitive ratios (1.986, 1.945, 1.923, 1.9201, 1.916) were achieved.
- On the lower bound side, it is known that no deterministic online scheduling algorithm can achieve a competitive ratio better than 1.88 and no randomized online scheduling algorithm can achieve a competitive ratio better than .
See a survey of Albers for more details.